nico_2010 Postat Decembrie 16, 2010 Partajează Postat Decembrie 16, 2010 @yo9hnf:Salut!Acum ne lasi in ceata!Pana la urma, merge ceasul in varianta cu anod comun?Din curiozitate intreb!!O zi buna Link spre comentariu
yo9hnf Postat Decembrie 16, 2010 Autor Partajează Postat Decembrie 16, 2010 @nico_2010Inca nu mi-a iesit...codul ar fi asta : $regfile "m32def.dat"$crystal = 16000000'6 mhz crstal$hwstack = 32 ' default use 32 for the hardware stack$swstack = 8Dim Once_a_sec As BitDim Clock_word As WordDim Hours As Byte , Minutes As Byte , Seconds As ByteDim Red As Byte , Green As ByteDim Count As Byte , X As Byte , Segment As ByteDim Number As Byte , Digit_select As ByteDim Del As Byte , Diagdelay As ByteDim Large As WordDel = 1' delay variable in milliseconds' all ports 0Portc = 0 'P0'redPortd = 255 'portd'yellow all high for sw inputsPortb = 0 'portb'green'P3 = 0'blue not usedConfig Debounce = 30' key debounce time in milli secondsConfig Timer0 = Timer , Prescale = 8'Timer0 use timer 0'Gate = Internal no external interrupt'Mode = 2 8 bit auto reload'Gosub Diag' diagnostic routine' set t0 internal interruptOn Timer0 Timer_0_intTimer0 = 250'Priority Set Timer0Enable InterruptsEnable Timer0Start Timer0Hours = 0Minutes = 0Seconds = 0Clock_word = 0Do' yellow port-1 key inputs for settingDebounce Pind.0 , 0 , Hup , SubDebounce Pind.1 , 0 , Hdown , SubDebounce Pind.2 , 0 , Mup , SubDebounce Pind.3 , 0 , Mdown , SubDebounce Pind.4 , 0 , Zero , SubIf Once_a_sec = 1 Then' once_a_sec=calculation every secondOnce_a_sec = 0'update hh mm ssIncr SecondsIf Seconds = 60 ThenSeconds = 0Incr MinutesIf Minutes = 60 ThenMinutes = 0Incr HoursIf Hours = 24 ThenHours = 0End IfEnd IfEnd IfEnd If' display time constantly' hoursNumber = Hours / 10Portb = 31Gosub DispWaitms DelPortc = 0'-------Number = Hours Mod 10Portb = 47Gosub DispWaitms DelPortc = 0'-------'minutesNumber = Minutes / 10Portb = 55Gosub DispWaitms DelPortc = 0'-------Number = Minutes Mod 10Portb = 59Gosub DispWaitms DelPortc = 0'-------'SECONDSNumber = Seconds / 10Portb = 61Gosub DispWaitms DelPortc = 0'-------Number = Seconds Mod 10Portb = 62Gosub DispWaitms DelPortc = 0'-------Loop' - - - - - - - - - - - - - - - - - -' set keys belowHup:Incr HoursIf Hours >= 24 ThenHours = 0End IfReturnHdown:Decr HoursIf Hours = 255 ThenHours = 23End IfReturnMup:Incr MinutesIf Minutes >= 60 ThenMinutes = 0End IfReturnMdown:Decr MinutesIf Minutes = 255 ThenMinutes = 59End IfReturnZero:Hours = 0 : Minutes = 0 : Seconds = 0Return' - - - - - - - - -- - - - - - - -- - - - - -Diag:'diagnostics'if zero button pressed then goto zero label and returnDiagdelay = 121For Seconds = 1 To 5Diagdelay = Diagdelay - 20Portb = 1For Green = 0 To 5Portc = 1For Red = 0 To 7Debounce Pind.4 , 0 , Zero , SubWaitms DiagdelayRotate Portc , LeftNext RedRotate Portb , LeftNext GreenNext Seconds' next diag show 000000 to 999999 on all digits' - - - - - - - -- - - - - -- - - - - - - -- - - -For Number = 0 To 9Portb = 1For Large = 1 To 50' approx 1 second time loop with 200 in largeFor Green = 0 To 5Debounce Pind.4 , 0 , Zero , SubGosub DispWaitms DelRotate Portb , LeftNext GreenNext LargeNext NumberReturn'Displaying routineDisp:Restore Tabela' scan 7-seg table to get byte for the digit to displayFor X = 0 To 9Read SegmentIf X = Number Then'if X = value to displayPortc = Segment'then set this value to Port0-redExit For'and exit FOR loopEnd IfNextReturn' int subroutine -----------------Timer_0_int:Incr Clock_wordIf Clock_word > 2000 ThenClock_word = 0Once_a_sec = 1End IfReturn'---- data for 7-seg LED display ------Tabela:Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7C , &H07 , &H7F , &H67' end of programPS : Nu-i vorba inca de ajustarea Timer0 inca...problema e ca nu pot afisa nimic pe Anod Comun. Link spre comentariu
nico_2010 Postat Decembrie 16, 2010 Partajează Postat Decembrie 16, 2010 Din curiozitate intreb: comanda afisoarelor cum o faci?Ai o interfata, gen ULN2803 sau 2003 si catozii conectati la portul uC? Link spre comentariu
yo9hnf Postat Decembrie 16, 2010 Autor Partajează Postat Decembrie 16, 2010 Din curiozitate intreb: comanda afisoarelor cum o faci? Ai o interfata, gen ULN2803 sau 2003 si catozii conectati la portul uC? Asta este schema partii de afisare de pe placa de evaluare. Link spre comentariu
nico_2010 Postat Decembrie 16, 2010 Partajează Postat Decembrie 16, 2010 codul pentru afisor cu anodul comun.Inlocuieste-le in tabela si spune-mi si mie cum e! Link spre comentariu
yo9hnf Postat Decembrie 16, 2010 Autor Partajează Postat Decembrie 16, 2010 Am pus asa :Tabela:Data &H81 , &HCF , &H92 , &H86 , &HCC , &HA4 , &HF0 , &H8F , &H80 , &H8CSi nu "zice" nimic. Link spre comentariu
nico_2010 Postat Decembrie 16, 2010 Partajează Postat Decembrie 16, 2010 Sigur ai respectat corespondenta conexiunilor cu specificatiile din program?Tranzistoarele le-ai conectat la portul corespunzator si pe primii 6 pini ai portului cu pricina (PORTB) - in cazul tau primii 4, respectiv PORTB.0 - PORTB.3? Link spre comentariu
yo9hnf Postat Decembrie 16, 2010 Autor Partajează Postat Decembrie 16, 2010 Sigur ai respectat corespondenta conexiunilor cu specificatiile din program?Tranzistoarele le-ai conectat la portul corespunzator si pe primii 6 pini ai portului cu pricina (PORTB) - in cazul tau primii 4, respectiv PORTB.0 - PORTB.3?Am respectat totul...-PORTB.0-PORTB.3 - digiti-PORTC.0-PORTC.6 - segmentele-PORTD.0-PORTD.4-butoane. Link spre comentariu
nico_2010 Postat Decembrie 16, 2010 Partajează Postat Decembrie 16, 2010 Pune un osciloscop pe portul de digiti si vezi daca ai semnal si, la fel, si pe cel de segmente.Daca nu ai asa ceva, schimba fusebitul de oscilator al uC pe ceas intern 8 MHz si vezi cum se comporta.Asta pentru ca, pe simulator, programul functioneaza partial, respectiv nu ia comenzi de setare a orelor si minutelor, insa functioneaza secundele! Link spre comentariu
ywar2 Postat Decembrie 16, 2010 Partajează Postat Decembrie 16, 2010 Salut. Faptul ca nu indica nimic nu mi se pare nici mie ok. Alta problema. In tabela ptr "0" avem 63, unde segmrentul A este D0 si G este D6 ptr catod comun. Pentru anod comun negat ar trebui sa fie 192 sau punind D7 in 0 ar fi 64. Cred eu ca tabela aia atasata este pe invers, dar este adevarat ca nici YO9HNF nu a aratat in desen ordinea cum a conectat pini la integrat. Putina atentie nu strica...poate gresesc si eu. Link spre comentariu
nico_2010 Postat Decembrie 16, 2010 Partajează Postat Decembrie 16, 2010 Salut ywar2!Din schema atasata am presupus ca segmentul a va fi conectat la PORTC.6 si descendent, segmentul g la PORTC.0, iar punctul zecimal (care nu este folosit in schema) a fost alocat ipoteticului PORTC.7 (disponibil numai in varianta TQFP).In consecinta, tabela a fost redactata avand la baza rationamentul de mai sus.Totusi, nu inteleg de ce la YO9HNF nu functioneaza? Link spre comentariu
yo9hnf Postat Decembrie 16, 2010 Autor Partajează Postat Decembrie 16, 2010 Dar programul pus de mine pe prima pagina, cel care numara pe un digit de la 1 la F merge , la fel si voltmetrul (care decat imi afiseaza) de pe pagina a doua. Link spre comentariu
ywar2 Postat Decembrie 16, 2010 Partajează Postat Decembrie 16, 2010 Salut. Ptr YO9HNF, m-am uitat pe codul tau si cred ca ar trebui ca sa declari porturile ca fiind intrari si iesiri, iar eu nu am vazut asta la tine. Uite un cod: Config Portc = OutputPortc = 0 'P0'redConfig Portd = InputPortd = &B11111111Portd = 255 'portd'yellow all high for sw inputsConfig Portb = OutputPortb = 0 'portb'greenDeasemenea, valorile din tabela ar trebui sa fie cele date de tine in al doi-lea exemplu de la inceputul acestui subiect. Value_table: Data &H40 , &H79 , &H24 , &H30 , &H19 , &H12 , &H02 , &H78, &H00 , &H10---73!--- Link spre comentariu
nico_2010 Postat Decembrie 17, 2010 Partajează Postat Decembrie 17, 2010 salut tuturor! Intr-adevar, a sesizat bine ywar2 lipsa configurarii porturilor din program, insa cam asta e totul. Dupa verificari practice, programul de mai jos functioneaza cu afisoare cu anod comun si "bate secunda" relativ exact!! Tabela pentru segmentele afisoarelor a avut ca logica de redactare conectarea segmentului "A" la PORTD.6 si segmentul "G" la PORTD.0 PORTC.0 este digitul de secunde, PORTC.1 cel de zeci de secunde s.a.m.d. De asemenea, setarea prescalerului TIMER0 la 64, iar a variabilei "Clock_word" (din subrutina de intrerupere) la 748 si nu 2000 (ca in programul original) a fost impusa de "precizia" (!?) secundei. $regfile "m8def.dat" $crystal = 12000000 '6 mhz crstal $hwstack = 32 ' default use 32 for the hardware stack $swstack = 8 Dim Once_a_sec As Bit Dim Clock_word As Word Dim Hours As Byte , Minutes As Byte , Seconds As Byte Dim Red As Byte , Green As Byte Dim Count As Byte , X As Byte , Segment As Byte Dim Number As Byte , Digit_select As Byte Dim Del As Byte , Diagdelay As Byte Dim Large As Word Del = 1 ' delay variable in milliseconds ' all ports 0 Config Portc = Output Config Portd = Output Config Portb = Input Portd = 255 'P0 'red Portb = 255 'portd 'yellow all high for sw inputs Portc = 255 'portb 'green 'P3 = 0 'blue not used Config Debounce = 30 ' key debounce time in milli seconds Config Timer0 = Timer , Prescale = 64 'Timer0 use timer 0 'Gate = Internal no external interrupt 'Mode = 2 8 bit auto reload 'Gosub Diag ' diagnostic routine ' set t0 internal interrupt On Timer0 Timer_0_int Timer0 = 100 'Priority Set Timer0 Enable Interrupts Enable Timer0 'Start Timer0 Hours = 0 Minutes = 0 Seconds = 0 Clock_word = 0 Do ' yellow port-1 key inputs for setting Debounce Pinb.0 , 0 , Hup , Sub Debounce Pinb.1 , 0 , Hdown , Sub Debounce Pinb.2 , 0 , Mup , Sub Debounce Pinb.3 , 0 , Mdown , Sub Debounce Pinb.4 , 0 , Zero , Sub If Once_a_sec = 1 Then ' once_a_sec=calculation every second Once_a_sec = 0 'update hh mm ss Incr Seconds If Seconds = 60 Then Seconds = 0 Incr Minutes If Minutes = 60 Then Minutes = 0 Incr Hours If Hours = 24 Then Hours = 0 End If End If End If End If ' display time constantly ' hours Number = Hours / 10 Portc = 31 Gosub Disp Waitms Del Portc = 0 '------- Number = Hours Mod 10 Portc = 47 Gosub Disp Waitms Del Portc = 0 '------- 'minutes Number = Minutes / 10 Portc = 55 Gosub Disp Waitms Del Portc = 0 '------- Number = Minutes Mod 10 Portc = 59 Gosub Disp Waitms Del Portc = 0 '------- 'SECONDS Number = Seconds / 10 Portc = 61 Gosub Disp Waitms Del Portc = 0 '------- Number = Seconds Mod 10 Portc = 62 Gosub Disp Waitms Del Portc = 0 '------- Loop ' - - - - - - - - - - - - - - - - - - ' set keys below Hup: Incr Hours If Hours >= 24 Then Hours = 0 End If Return Hdown: Decr Hours If Hours = 255 Then Hours = 23 End If Return Mup: Incr Minutes If Minutes >= 60 Then Minutes = 0 End If Return Mdown: Decr Minutes If Minutes = 255 Then Minutes = 59 End If Return Zero: Hours = 0 : Minutes = 0 : Seconds = 0 Return ' - - - - - - - - -- - - - - - - -- - - - - - Diag: 'diagnostics 'if zero button pressed then goto zero label and return Diagdelay = 121 For Seconds = 1 To 5 Diagdelay = Diagdelay - 20 Portd = 1 For Green = 0 To 5 Portc = 1 For Red = 0 To 7 Debounce Pinb.4 , 0 , Zero , Sub Waitms Diagdelay Rotate Portd , Left Next Red Rotate Portc , Left Next Green Next Seconds ' next diag show 000000 to 999999 on all digits ' - - - - - - - -- - - - - -- - - - - - - -- - - - For Number = 0 To 9 Portc = 1 For Large = 1 To 50 ' approx 1 second time loop with 200 in large For Green = 0 To 5 Debounce Pinb.4 , 0 , Zero , Sub Gosub Disp Waitms Del Rotate Portc , Left Next Green Next Large Next Number Return 'Displaying routine Disp: Restore Tabela ' scan 7-seg table to get byte for the digit to display For X = 0 To 9 Read Segment If X = Number Then 'if X = value to display Portd = Segment 'then set this value to Port0-red Exit For 'and exit FOR loop End If Next Return ' int subroutine ----------------- Timer_0_int: Incr Clock_word If Clock_word > 748 Then Clock_word = 0 Once_a_sec = 1 End If Return '---- data for 7-seg LED display ------ Tabela: Data &H01 , &H4F , &H12 , &H06 , &H4C , &H24 , &H60 , &H0F , &H00 , &H0C YO9HNF, daca ai timp, poti verifica acest program si daca totusi ai probleme spune-ne si noua Putin mai tarziu: O constatare: se pare ca zecile de minute ale lor nu sunt la fel cu ale noastre Daca incerci sa scazi minutele din butonul aferent zecilor de minute se constata ca valoarea afisata incepe de la 9 !? Link spre comentariu
ywar2 Postat Decembrie 17, 2010 Partajează Postat Decembrie 17, 2010 Salut NICO. Cu ce zici tu ca faci simularea softului? Eu am incercat o data simularea cu ajutorul Bascom-ului si mergea foarte lent asa ca in final am renuntat. Merci anticipat!!! 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