Marin1960 Postat Octombrie 27, 2022 Autor Partajează Postat Octombrie 27, 2022 Inca un hex modificat pentru compatibilitate cu schema ta. ceas-led-2313-3231-cc07-sinv-v20.hex Link spre comentariu
expert Postat Octombrie 31, 2022 Partajează Postat Octombrie 31, 2022 am trimis MP, mai sunt probleme! Link spre comentariu
CIBY2 Postat Iunie 12, 2023 Partajează Postat Iunie 12, 2023 La 15.03.2022 la 10:26, Marin1960 a spus: Raspund unei cereri a unui coleg de forum, care doreste afisarea cifrei 7 in stil asiatic: Softul este dezvoltat in Bascom, daca sunt colegi care lucreaza cu acest soft si sunt interesati de acest ceas, voi posta codul sursa, astfel incat sa-l poata personaliza dupa dorinta. In acest moment, codul poate fi compilat pentru 3 tipuri de RTC (DS1307, DS3231 si MCP7940), 2 tipuri de afisaj cu driver de tranzistoare (pnp pentru Anod Comun, npn pentru Catod Comun) sau direct, fara tranzistoare (Anod Comun_0, Catod Comun_0). ceas-led-at2313-nou-v17(7).hex 5 kB · 8 descărcări Te rog daca ai timp sa postezi si codul sursa. Am vreo trei ceasuri incepute si nu reusesc sa comunic pe I2C cu RTC-ul, nici cu DS1307 nici cu MCP7940. Link spre comentariu
Marin1960 Postat Iunie 12, 2023 Autor Partajează Postat Iunie 12, 2023 Sa inteleg ca ceasul nu afiseaza timpul? Explica mai pe larg, te rog, ce se intampla. Daca ai modificat schema (ca in cazul userului expert, e posibil sa nu ai o afisare corecta). Ce RTC (DS1307, DS3231 sau MCP7940) si display (anod comun, catod comun) ai utilizat, si cu ce firmware ai programat procesorul? Link spre comentariu
CIBY2 Postat Iunie 13, 2023 Partajează Postat Iunie 13, 2023 Nu este aceasta schema. Am incercat pe doua variante, prima cu Atmega88 si 4 cifre, iar a doua cu Atmega8535, inlocuit ulterior cu Atmega16, cu 6 cifre, folosind la ambele o rutina de afisaj accesata de intreruperea din Timer0, ulterior incercand si cu Timer2. Acum fac referire la cel cu 8535: La pornire, in program, am introdus un cod de scriere a registrului de control al RTC-ului si de setare a bitului de pornire a oscilatorului (bit 7 din prima linie, cea a secundelor din RTC). Am folosit prima data MCP7940 si pe urma am incercat cu DS1307. Stiu ca nu sunt echivalente 100%, dar am scris cod pentru amandoua, folosind aceleasi variabile. Pe liniile SCL si SDA am rezistente de pullup de 4,3 kiloohmi, iar pinii folositi sunt cei dedicati, PC0 si PC1 din Atmega. Dupa scrierea registrului si a bitului de pornire oscilator (1 in cazul MCP si 0 in cazul DS) urmeaza o bucla DO-LOOP, in care in functie de starea unui bit setat de iesirea SQWE din RTC, denumit de mine Set_read_flag, citeste memoria RTC-ului. SQWE este legat la INT0, in asa fel incat citirea sa se faca la fiecare secunda. Daca am vazut ca nu reusesc sa citesc RTC-ul, am introdus diferite valori pentru variabilele ce trebuiesc afisate, pentru a verifica functionarea rutinei de afisaj, si functioneaza, inclusiv cu un cod ce genereaza ceas (secunde, minute, ore) in functie de Timer1. Ma tot gandesc unde am gresit, ce nu am configurat bine. Ca idee, PortulD este folosit pentru comanda LED-urilor si se suprapune peste pinii RXT si TXD ai USART si a trebuit sa dezactivez aceasta functie, netrecand in cod setarea baudrate. Inca o chestie, a trebuit sa dezactivez din fusebits JTAG-ul, care imi bloca o cifra, tot din cauza suprapunerii cu iesirea, dar catre unul din tranzistoarele din anozii afisajelor. Am cerut codul tau in speranta ca imi pot da seama ce setari ai facut tu acolo. Din pacate nu am acum codul scris de mine sa pot posta ce am facut, dar cand ajung acasa o sa incerc sa postez din el. Nici cu DS18B20 nu am reusit sa comunic. Link spre comentariu
Marin1960 Postat Iunie 13, 2023 Autor Partajează Postat Iunie 13, 2023 Programul este scris in Bascom? Link spre comentariu
CIBY2 Postat Iunie 13, 2023 Partajează Postat Iunie 13, 2023 Bascom AVR. Este prima data cand incerc comunicarea I2C si 1Wire. In tinerete am mai cochetat cu BASIC-ul si in facultate am studiat Foxpro, care e tot un BASIC orientat pe baze de date. Chiar mi-am facut niste programe de contabilitate si gestiune cu el, functionale, dar asta acum 20 si ceva de ani. Si cum Bascom-ul este tot un Basic, am zis ca experienta din tinerete nu s-a irosit si ca ma descurc si cu el. Dar cred ca problema mea sunt microcontrolerele, chiar daca am idee de functiile logice, cochetand candva cu TTL si CMOS, astea sunt mult mai complexe, iar din datasheet, cu engleza mea, merg mai mult pe ghicite. Link spre comentariu
Marin1960 Postat Iunie 13, 2023 Autor Partajează Postat Iunie 13, 2023 O sa postez sursa, diseara cand ajung acasa. Link spre comentariu
Marin1960 Postat Iunie 13, 2023 Autor Partajează Postat Iunie 13, 2023 'Mi '************************************ 'proiect ;Ceas-AT2313-RTC-TH 'microcontroller ;attiny 2313 / attiny 4313 'autor ;Marinica Ionescu 'descriere ;display tip Anod Comun (A) sau Catod Comun (C) comandati 'prin tranzistoare sau direct (a) si (c). Afisajul are 4 digiti "Ore:Minute" 'Potrivire timp cu 2 butoane (Set/Mode, Up) 'La pornire apare "buna" timp 5 secunde, dupa care se afiseaza timpul. 'La prima pornire trebuie setat timpul si luminozitatea. 'Ceasul va afisa timpul alternant cu temperatura (8 secunde timp si 2 secunde 'temperatura). Apasarea pe butonul UP si SET va afisa versiunea ceasului. '26-12-2013 ;start proiect ' ;RTC DS1307, registru 0 bit 7(Clock Halted) trebuie sa fie 0 'ca oscilatorul sa funcioneze. 'In registrul 7 Control, bitul 4 SQWE=1 activeaza iesirea oscilatorului. 'Frecventa de iesire este data de bitii RS0 si RS1. RS1=0, RS0=0 => 1Hz 'Control (07h)=10h '04-02-2014 ;termometru cu DS75 '25-05-2014 ;RTC MCP7940, registrul 0 RTCSEC bit 7 ST=1 pentru functionare 'oscilatorului. 'Registrul 7 Control SQWE=1 activeaza iesirea oscilatorului. 'Frecventa de iesire din bitii SQWFS1=0 SQWFS0=0 pentru 1HZ 'Control(07h)=40h. '01-12-2019 ;am introdus bright night intre 22 si 6 '05-12-2019 ;am redus numarul de caractere afisabile '03-05-2020 ;am modificat rutina key, mici corectii '25-06-2020 ;Bright Night este 25% din Bright '30-07-2020 ;am introdus Option 0=timp, 1=timp+temp, 2=temp '23-01-2021 ;temperaturi pozitive si negative '24-01-2021 ;initializare osc RTC la pornire '18-02-2022 ;RTC DS3231 registrul de Control 14, bit 7 EOSC=0 activeaza 'oscilatorul, bitul 6 BBSQW=1 activeaza iesirea oscilatorului, bitii 4 si 3 'RS1=0 si RS0=0 => frecventa oscilator=1Hz, Control(0Eh)=40h. 'Registrul Status(0Fh)=0 inhiba iesirea 32khz (minimizare consum). 'La compilare se alege tipul RTC (DS1307, DS3231 sau MCP7940), tipul de 'display (Ac, Cc, Ac0, Cc0), tipul procesorului (2313 sau 4313) si tip cifra 7 '21-02-2022 ;ok, testat in toate versiunile (rtc si display) '11-04-2022 ;versiunea este afisata in felul urmator Ex: A319 'A - primul digit reprezinta tipul de display (A=anod comun, a=anod comun 'direct, C=catod comun, c=catod comun direct) '1 - al doilea digit reprezinta tipul RTC (1=DS1307, 3=DS3231, 7=MCP7940) '18 - digitii 3 si 4 reprezinta versiunea ceasului (versiunea este in 'intervalul 1-49 pentru procesorul ATtiny2313 si 50-99 pentru procesorul 4313) ' '8,000 mhz oscilator intern 'fusebits 'LOW = 0xE4 'HIGH = 0xDF 'EXTENDED = 0xFF ' $crystal = 8000000 $hwstack = 16 $swstack = 16 $framesize = 20 ' 'Cc(C)=Catod comun cu tranzistoare, Ac(A)=Anod comun cu tranzistoare 'Cc0(c)=Catod comun direct, Ac0(a)=Anod comun direct Const Cc = 0 : Const Ac = 1 Const Cc0 = 2 : Const Ac0 = 3 'Versiune Ceas = display(A,a,C,c)+rtc(1|3|7)+(proc(0|50) + Versiune) => A119 'Configurare CEAS '************ VERSIUNE ************** Const Versiune = 19 'versiune ceas Const Rtc = 1307 '1307, 3231, 7940 Const Tip_disp = Ac 'Ac, Cc, Ac0, Cc0 Const Tip_proc = 2313 '2313, 4313 Const Tip_7 = 0 '0=> 7 clasic, 1=> 7 asiatic '************ VERSIUNE ************** Const Vers = Versiune #if Tip_proc = 2313 'Attiny2313 $regfile = "attiny2313.dat" ' Const Vers = Versiune #elseif Tip_proc = 4313 'Attiny4313 $regfile = "attiny4313.dat" ' Const Vers = Versiune + 50 #else $regfile = "procesor not supported" 'eroare la compilare #endif ' $lib "i2cv2.lbx" 'dupa $regfile ' #if Tip_disp = Ac 'anod comun cu tranz. pnp Const Vdisp = 28 'A #elseif Tip_disp = Ac0 'anod comun direct Const Vdisp = 13 'a #elseif Tip_disp = Cc 'catod comun cu tranz. npn Const Vdisp = 15 'C #elseif Tip_disp = Cc0 'catod comun direct Const Vdisp = 29 'c #endif ' 'pentru tip rtc vezi initializare "Tip RTC" ' #if Tip_7 = 0 '7 clasic Const Cst7 = &HF8 #else '7 asiatic Const Cst7 = &HD8 #endif ' Const Vdec = Int(vers / 10) 'afis zeci versiune Const Vunit = Vers Mod 10 'afis unitati versiune ' '[Variabile] 'EEPROM, sar prima locatie din eeprom Dim Dummy As Eram Byte , Bright_e As Eram Byte , Option_e As Eram Byte Dim Tempo_e As Eram Byte 'afisare Dim Ndig As Byte , Leds As Byte Dim Cod_chr As Byte , Digit As Byte Dim Level As Byte , Ds_max As Byte Dim Brightt As Byte , Offset As Byte Dim Tim(25) As Byte 'temperatura Dim Tempds As Byte , Flag_temp As Byte Dim Valid_temp As Byte 'timp Dim Ds(5) As Byte , Enosc As Byte Dim Ds_addr As Byte , Ds_byte As Byte Dim Hsec As Byte , Disp_time As Byte 'key Dim F_key As Byte , Key_start As Byte Dim In_key As Byte , Key As Byte , Old_key As Byte 'SQW Dim Sqw As Byte , Sqw_old As Byte 'contoare timp Dim Tims As Byte , Tim_key As Byte 'temporare Dim I As Byte 'Overlay, nu utilizeaza RAM Dim T01 As Word At Tim(0) Overlay , T23 As Word At Tim(0) + 2 Overlay Dim Ds_ab As Word At Ds_addr Overlay Dim F_key_start As Word At F_key Overlay ' 'Descriere variabile 'Dummy - nefolosit 'Bright_e - valoarea Bright din eeprom 'Option_e - valoarea Option din eeprom 'Tempo_e - valoarea Tempo (offset temperatura) din eeprom (nefolosit) 'Ndig - numar digit(anod/catod) curent 'Leds - ledurile dintre ore si minute (0=on, 1=off) 'Cod_chr - codul 7 segmente al caracterului de afisat (in varianta anod comun) 'Digit - anodul/catodul care trebuie aprins 'Level - 0 afis timp, 1 set minute, 2 set ore, 3 set Bright, 4 set option 'Ds_max - valoarea maxima a variabilei Ds (secunda, minut, ora, bright, option) 'Brightt - valoarea Bright temporara din ram 'Tim() - contine timp, temp., lumin. (oz, ou, mz, mu,-, tempz, tempu, o, C) etc 'Tempds - temperatura senzor DS75 'Flag_temp - 'Ds() - timpul din RTC 'Enosc - continut original al Ds(0) 'Ds_addr - adresa registru RTC 'Ds_byte - continutul de la adresa RTC 'Hsec - jumatate secunda 'Disp_time - 'F_key - contor apasare tasta 'Key_start - tasta valida acceptata 'In_key - port taste 'Key - tasta curenta 'Old_key - ultima tasta apasata 'Sqw - secunda hardware RTC 'Sqw_old - stare veche a SQW 'Tims - timer soft de 0,5 seconds 'Tim_key - timer soft de 2,5 ms 'I - contor pentru FOR ' 'Ds_ab este de tip word (Ds_addr high byte, Ds_byte low byte) ' 'Bright - luminozitate afisaj in 20 de trepte (0=minim, 19=maxim) ' - - - - - - - - - - - - - - - - - - '[Constante] 'Ntim0 = 237 => f = 411 Hz Const Cst_ntim0 = 237 'f=fclk/prescaler/(256-ntim0)=411Hz 'f=8000000/1024/(256-237)=411 (T=2,4ms) ' Const Cst_led_on = 127 'aprinde leduri Const Cst_led_off = 255 'stinge leduri ' 'DS1307 si DS3231 au aceiasi adresa de scriere si citire: 'Const Rtc_w = &B1101000_0 'Const Rtc_r = &B1101000_1 'MCP7940 are adresa de scriere si citire: 'Const Rtc_w = &B1101111_0 'Const Rtc_r = &B1101111_1 'DS75r slave address read Const Ds75r = &B1001000_1 ' 'DS1307 SQWE = 1 => 1Hz Const Cst_sqwe_1307 = &H1007 'adresa &H07 = &H10 'DS3231 SQWE = 1 => 1Hz Const Cst_sqwe_3231 = &H400E 'adresa &H0E = &H40 'DS3231 iesire 32kHz inactiva pentru consum redus Const Cst_32khz_3231 = &H000F 'adresa &H0F = &H00 'MCP7940N SQWE = 1 => 1Hz Const Cst_sqwe_7940 = &H4007 'adresa &H07 = &H40 'MCP7940 pornesc oscilator Const Cst_osc_7940 = &H8000 'adresa &H00 = &H80 ' Const Cst_key_mask = &B0011_0000 'masca pentru Butoane Const Cst_sqw_mask = &B0100_0000 'masca pentru Secunda ' Const Cst_set = 30 '15 secunde Const Cst_buna = 10 '5 secunde ' 'scrie eeprom doar daca valoarea de scris este diferita de continutul eeprom Const Updateeprom = 0 ' - - - - - - - - - - - - - - - - - - 'alias, variabile pentru o mai buna claritate Secunda Alias Ds(0) Minut Alias Ds(1) Ora Alias Ds(2) Bright Alias Ds(3) Option Alias Ds(4) ' - - - - - - - - - - - - - - - - - - '[Configurare] 'index vector, pleaca de la 0 Config Base = 0 'index 0 Config Portb = Output 'activ Low sau High in functie de configuratie 'portb0=a 'portb1=b 'portb2=c 'portb3=d 'portb4=e 'portb5=f 'portb6=g 'portb7=leds Config Portd = &B0000_1111 'bitii 0...3 sunt iesiri 'portd0=digit zeci ore 'portd1=digit unitati ore 'portd2=digit zeci minute 'portd3=digit unitati minute 'portd4=key Key up intrare 'portd5=key Key mode intrare 'portd6=SQW secunda RTC intrare 'portd7=nu exista ' - - - - - - - - - - - - - - - - - - 'configurare I2C Config Scl = Porta.0 'pin 5 Config Sda = Porta.1 'pin 4 ' - - - - - - - - - - - - - - - - - - 'configurare timere Config Timer0 = Timer , Prescale = 1024 On Timer0 Timer_0_int , Nosave Enable Timer0 ' Config Timer1 = Timer , Prescale = 1024 On Timer1 Timer_1_int , Nosave Enable Timer1 Enable Interrupts ' - - - - - - - - - - - - - - - - - - 'Initializare 'DS1307 Control Reg = &H07 (val=&H10), DS1307 SQWE = 1Hz 'DS3231 Status register = &H0F (val=0), osc on 'DS3231 Control register = &H0E (val=&H40) BBSQW=1, RS1=RS2=0 =>1Hz '########### Tip RTC ############### #if Rtc = 1307 'rtc este DS1307 Const Vrtc = 1 Const Ds_rtc_w = &B1101000_0 Const Ds_rtc_r = &B1101000_1 Gosub Get_time If Enosc.7 = 1 Then 'testez oscilator Ds_ab = 0 'oscilator on Gosub Ds_send1 End If Ds_ab = Cst_sqwe_1307 'activez SQWE cu 1Hz Gosub Ds_send1 #elseif Rtc = 3231 'rtc este DS3231 Const Vrtc = 3 Const Ds_rtc_w = &B1101000_0 Const Ds_rtc_r = &B1101000_1 Ds_ab = Cst_sqwe_3231 'activez SQWE cu 1Hz Gosub Ds_send1 Ds_ab = Cst_32khz_3231 Gosub Ds_send1 #elseif Rtc = 7940 Const Vrtc = 7 Const Ds_rtc_w = &B1101111_0 Const Ds_rtc_r = &B1101111_1 Gosub Get_time If Enosc.7 = 0 Then 'testez oscilator Ds_ab = Cst_osc_7940 'oscilator on Gosub Ds_send1 End If Ds_ab = Cst_sqwe_7940 'activez SQWE cu 1Hz Gosub Ds_send1 #else "RTC not supported" 'eroare in timpul compilarii #endif '########### Tip RTC ############### Bright = Bright_e Option = Option_e Level = 5 : Tims = Cst_buna 'buna 5 sec Goto Main ' - - - - - - - - - - - - - - - - - - Init: Tims = 255 Level = 0 Bright_e = Bright Option_e = Option ' - - - - - - - - - - - - - - - - - - 'Main program Main: Do If Disp_time = 1 Then Disp_time = 0 Gosub Sincro Gosub Message Gosub Buffer_time Gosub Disp_level Gosub Display_digit Gosub Change_bright Gosub Read_key If Tims = 0 Then Goto Init End If Loop ' - - - - - - - - - - - - - - - - - - 'citeste SQW, pe fornt cazator citeste timp, seteaza Flag_temp, pe front 'crescator citeste temperatura Sincro: Sqw = Pind And Cst_sqw_mask If Sqw = Sqw_old Then Return 'sincronizare sec Sqw_old = Sqw If Tims <> 255 Then Tims = Tims - 1 'timer de 0.5 sec If Sqw = 0 Then Hsec = Cst_led_off Gosub Get_time Flag_temp = Secunda Mod 10 Else Hsec = Cst_led_on Gosub Get_temp End If Return ' - - - - - - - - - - - - - - - - - - 'completeaza vectorul Tim() cu mesajul de afisat Message: I = 5 Restore Msg Do Read Tim(i) I = I + 1 Loop Until I = 25 Return ' - - - - - - - - - - - - - - - - - - 'completeaza vectorul Tim() cu timp si temperatura Buffer_time: 'idx 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 etc 'Tim() oz ou mz mu - tz tu o C b r bz bu o P t opt Tim(0) = Ora / 10 'timp; offset = 0 Tim(1) = Getreg(r24) Tim(2) = Minut / 10 Tim(3) = Getreg(r24) 'Minut Mod 10 Tim(4) = 11 '-, offset = 4 Tim(5) = Tempds / 10 'offset = 5 Tim(6) = Getreg(r24) 'Tempds Mod 10 'Tim(7) = 12 'grad 'Tim(8) = 15 'C 'Tim(9) = b 'bright; offset = 9 'Tim(10) = r Tim(11) = Bright / 10 Tim(12) = Getreg(r24) 'Bright Mod 10 'Tim(13) = o 'option; offset = 13 'Tim(14) = P 'Tim(15) = t Tim(16) = Option 'Tim(17) = b 'buna; offset = 17 'Tim(18) = u 'Tim(19) = n 'Tim(20) = a 'Tim(21) = tip digit 'versiune; offset = 21 'Tim(22) = tip RTC 'Tim(23) = versiune (zeci) 'Tim(24) = versiune (unitati) If Tim(0) = 0 Then Tim(0) = 10 'ora (stinge zero din stanga) If Tim(5) = 0 Then Tim(5) = 10 'temperatura If Tim(11) = 0 Then Tim(11) = 10 'bright Return ' - - - - - - - - - - - - - - - - - - 'level 0 => timp 'level 1 => set minute 'level 2 => set ore 'level 3 => set bright 'level 4 => set option 'level 5 => buna 'level 6 => versiune Disp_level: Offset = Lookup(level , Tbl_offset ) Leds = Hsec Select Case Level Case 0 Select Case Option 'se iese prin option Case 1 If Flag_temp < 2 Then Goto Disp_temp Case 2 Goto Disp_temp End Select Case 1 'set minute T01 = &H0A0A 'Tim(0)=sp,Tim(1)=sp Case 2 'set ore T23 = &H0A0A 'Tim(2)=sp,Tim(3)=sp Case 3 To 6 'set bright Leds = Cst_led_off End Select Return '- - - - - - - - - - - - - - - - - - 'se afiseaza 4 digiti din Tim() avand ca baza offset (exemplu mai jos) 'digiti display in ordinea 0 1 2 3 'Offset 0 [ ] 'Offset 5 [ ] 'idx Disp 0 1 2 3 0 1 2 3 'idx Tim 0 1 2 3 4 5 6 7 8 'Tim() = oz, ou, mz, mu, -, tempz, tempu, o, C Display_digit: Ndig = Ndig + 1 If Ndig = 4 Then Ndig = 0 Offset = Offset + Ndig Cod_chr = Lookup(tim(offset) , Font_7seg) If Ndig = 1 Then Cod_chr = Cod_chr And Leds Digit = Lookup(ndig , Digits) Return ' - - - - - - - - - - - - - - - - - - Disp_temp: If Valid_temp <> 0 Then Offset = Valid_temp : Leds = Cst_led_off End If Return ' - - - - - - - - - - - - - - - - - - Change_bright: Brightt = Bright If Level = 0 Then If Ora > 21 Or Ora < 6 Then Brightt = Bright / 4 End If Return ' - - - - - - - - - - - - - - - - - - 'Read Key 'F_key > 0 aceiasi tasta este apasata 'Key_start <> 0, permite o singura apasare 'Portd.4=kmode 'Portd.5=kup Read_key: Key = Cst_key_mask In_key = Pind And Cst_key_mask If In_key <> Old_key Then Tim_key = 10 'debounce 25 ms F_key_start = 0 '= F_key = 0: Key_start = 0 End If If Tim_key = 0 Then If In_key <> Cst_key_mask Then If Key_start = 0 Then 'tasta apasata Key = In_key 'tasta confirmata Incr F_key If F_key = 1 Then Tim_key = 200 'dupa 0,5 sec repet If F_key > 2 Then Tim_key = 50 'la fiecare 100 ms End If End If End If Old_key = In_key 'Action key Select Case Key Case 0 Tims = 5 : Level = 6 'afisare versiune Case 16 Gosub Kup Case 32 Gosub Kmode End Select Return '- - - - - - - - - - - - - - - - - - 'Key Mode/Set Kmode: Key_start = 1 Tims = Cst_set Incr Level If Level > 4 Then Tims = 0 'buna si versiune Return ' - - - - - - - - - - - - - - - - - - 'Key Increment Kup: Select Case Level Case 0 Return Case 1 'set minute si secunde Ds_ab = 0 'Ds_addr = 0 : Ds_byte = 0 '########### Tip RTC ############### #if Rtc = 7940 Set Ds_byte.7 'oscilator on #endif '########### Tip RTC ############### Gosub Ds_send1 Gosub Incr_var Case 2 To 4 'set ore, bright, option Gosub Incr_var Case 6 'versiune Return End Select Ds_addr = Level Ds_byte = Ds(level) If Level < 3 Then Gosub Ds_send Tims = Cst_set Return ' - - - - - - - - - - - - - - - - - - 'incrementez variabila determinata de level pana la valoarea maxima din Tbl_max Incr_var: Incr Ds(level) Change_ds1: Ds_max = Lookup(level , Tbl_max) If Ds(level) > Ds_max Then Ds(level) = 0 Return ' - - - - - - - - - - - - - - - - - - 'afisare temperaturi pozitive/negative 'Valid_temp=0 fara temperatura 'Valid_temp=4 temperatura negativa 'Valid_temp=5 temperatura pozitiva Get_temp: Valid_temp = 0 I2crepstart I2cwbyte Ds75r ' send address I2crbyte Tempds , Nack 'get temp I2cstop If Err = 1 Then Return Valid_temp = 5 If Tempds.7 = 1 Then 'temp negative Tempds = 0 - Tempds 'complement fata de 2 Valid_temp = 4 End If Return ' - - - - - - - - - - - - - - - - - - 'citesc timpul din RTC in vectorul Ds(), timpul este in cod BCD 'idx 0 1 2 3 4 'Ds() sec min ore Get_time: Ds_addr = 0 Gosub I2head I2crepstart ' Generate start code I2cwbyte Ds_rtc_r ' send address I2crbyte Enosc , Ack I2crbyte Minut , Ack I2crbyte Ora , Nack I2cstop '########### Tip RTC ############### #if Rtc = 7940 Secunda = Enosc And &H7F 'sterg bitul 7 #else Secunda = Enosc #endif '########### Tip RTC ############### Secunda = Makedec(secunda) Minut = Makedec(minut) Ora = Makedec(ora) Return ' - - - - - - Ds_send: Ds_byte = Makebcd(ds_byte) Ds_send1: Gosub I2head I2cwbyte Ds_byte I2cstop Return ' - - - - - - - - - - - - - - - - - - I2head: I2crepstart 'start code I2cwbyte Ds_rtc_w 'send address I2cwbyte Ds_addr 'start address Return '************************************ 'afisez pe display continutul bufferului curent 'Timer0 subroutine Timer_0_int: ! push r24 ! in r24,sreg ! push r24 ! clr r24 'Stop Timer1 ! Out Tccr1b , R24 ! ldi r24,Cst_ntim0 'Timer0 = Cst_ntim0 ! Out Tcnt0 , R24 '########## Tip display ############# #if Tip_disp = Ac Or Tip_disp = Cc0 'Ac sau Cc0 ! ser r24 'Sting anozii #else 'Ac0 sau Cc ! ldi r24,&HF0 'Sting anozii #endif '########## Tip display ############# ! Out Portd , R24 ! ser r24 ! Out Tcnt1h , R24 'Tcnt1h = 255 ! lds r24,{Brightt} 'Tcnt1l = Brightt &H0066 ! com r24 'Brightt = 255 - Brightt ! Out Tcnt1l , R24 ! ldi r24,1 'Disp_time = 1 &H008D ! sts {Disp_time},r24 ! lds r24,{Cod_chr} 'Ac, Ac0 '####### Tip display segmente ####### #if Tip_disp = Cc Or Tip_disp = Cc0 ! com r24 'inversez bitii din Cod_chr #endif '####### Tip display segmente ####### ! Out Portb , R24 ! lds r24,{Digit} 'Portd = Digit &H0064 ! Out Portd , R24 'timer soft Timer_key ! lds r24,{Tim_key} 'verific Timer_key ! cpi r24,0 'daca este on (>0) ! breq timer_0_a ! dec r24 'daca da, decrementez ! sts {Tim_key},r24 'si salvez Timer_key Timer_0_a: 'end timer soft ! ldi r24,5 'Start Timer1 ! Out Tccr1b , R24 ! pop r24 ! Out Sreg , R24 ! pop r24 Return '************************************ 'Timer1 'sting anozii/catozii mai devreme in functie de bright Timer_1_int: ! push r24 ! in r24,sreg ! push r24 '########## Tip display ############# #if Tip_disp = Ac Or Tip_disp = Cc0 'Ac sau Cc0 ! ser r24 'Sting anozii #else 'Ac0 sau Cc ! ldi r24,&HF0 'Sting anozii #endif '########## Tip display ############# ! Out Portd , r24 'sting anozii ! ser r24 ! Out Tcnt1h , r24 ! clr r24 ! Out Tccr1b , r24 'Stop Timer1 ! pop r24, ! Out Sreg , r24 ! pop r24 Return End 'end program '************************************ 'messages Digits: '########## Tip display ############# #if Tip_disp = Ac Or Tip_disp = Cc0 'AC sau Cc0 Data 254 , 253 , 251 , 247 #else 'Ac0 sau Cc Data 241 , 242 , 244 , 248 #endif '########## Tip display ############# Msg: Data 10 , 10 , 12 , 15 'xxoC Data 14 , 25 , 10 , 10 'br xx Data 23 , 24 , 26 , 10 'opt x Data 14 , 27 , 22 , 13 'buna Data Vdisp , Vrtc , Vdec , Vunit 'display/rtc/versiune Tbl_offset: Data 0 , 0 , 0 , 9 , 13 , 17 , 21 Tbl_max: ' sec min ore br opt 'lev 0 1 2 3 4 Data 0 , 59 , 23 , 19 , 2 'data pentru 7seg display (activ in zero) - dp(bit7),g,f,e,d,c,b,a(bit0) 'cifra 7 se poate scrie abc (HF8) sau versiunea asiatica abcf (HD8) Font_7seg: 'adresa 0 1 2 3 4 5 6 7 8 9 'data 0 1 2 3 4 5+S 6 7(HF8) 8 9 Data &HC0 , &HF9 , &HA4 , &HB0 , &H99 , &H92 , &H82 , Cst7 , &H80 , &H90 '----------------------------------------------------------------------- 'adresa 10 11 12 13 14 15 16 17 18 19 'data sp - o grad a b C d E F h Data &HFF , &HBF , &H9C , &HA0 , &H83 , &HC6 , &HA1 , &H86 , &H8E , &H8B '----------------------------------------------------------------------- 'adresa 20 21 22 23 24 25 26 27 28 29 'data i L n o P r t u A c Data &HFB , &HC7 , &HAB , &HA3 , &H8C , &HAF , &H87 , &HE3 , &H88 , &HA7 '----------------------------------------------------------------------- 'Data_eeprom: $eeprom ' Dummy Br_e Opt_e Tempo_e Data &HFF , &H07 , &H01 , &HFF $data '************************************ '************************************ Link spre comentariu
daniels Postat Iunie 25, 2023 Partajează Postat Iunie 25, 2023 La modulul RTC DS1307 se aprinde ceva atunci cand functioneaza? Link spre comentariu
Postări Recomandate
Creează un cont sau autentifică-te pentru a adăuga comentariu
Trebuie să fi un membru pentru a putea lăsa un comentariu.
Creează un cont
Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!
Înregistrează un nou contAutentificare
Ai deja un cont? Autentifică-te aici.
Autentifică-te acum