Jump to content


Photo

BASCOM


  • Please log in to reply
538 replies to this topic

#31 OFFLINE   nico_2010

nico_2010

    Membru avansat

  • Moderatori
  • 1,736 posts
  • Locatie:Bucuresti

Posted 16 December 2010 - 10:30 AM

@yo9hnf:
Salut!
Acum ne lasi in ceata!
Pana la urma, merge ceasul in varianta cu anod comun?
Din curiozitate intreb!!
O zi buna

Cu_reclama

Cu_reclama
  • Membri

#32 OFFLINE   yo9hnf

yo9hnf

    ElForum staff

  • Moderatori
  • 3,073 posts
  • Locatie:BUCURESTI

Posted 16 December 2010 - 10:48 AM

@nico_2010

Inca 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 = 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
Portc = 0 'P0
'red
Portd = 255 'portd
'yellow all high for sw inputs
Portb = 0 'portb
'green
'P3 = 0
'blue not used
Config Debounce = 30
' key debounce time in milli seconds
Config 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 interrupt
On Timer0 Timer_0_int
Timer0 = 250
'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 Pind.0 , 0 , Hup , Sub
Debounce Pind.1 , 0 , Hdown , Sub
Debounce Pind.2 , 0 , Mup , Sub
Debounce Pind.3 , 0 , Mdown , Sub
Debounce Pind.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
Portb = 31
Gosub Disp
Waitms Del
Portc = 0
'-------
Number = Hours Mod 10
Portb = 47
Gosub Disp
Waitms Del
Portc = 0
'-------
'minutes
Number = Minutes / 10
Portb = 55
Gosub Disp
Waitms Del
Portc = 0
'-------
Number = Minutes Mod 10
Portb = 59
Gosub Disp
Waitms Del
Portc = 0
'-------
'SECONDS
Number = Seconds / 10
Portb = 61
Gosub Disp
Waitms Del
Portc = 0
'-------
Number = Seconds Mod 10
Portb = 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
Portb = 1
For Green = 0 To 5
Portc = 1
For Red = 0 To 7
Debounce Pind.4 , 0 , Zero , Sub
Waitms Diagdelay
Rotate Portc , Left
Next Red
Rotate Portb , Left
Next Green
Next Seconds
' next diag show 000000 to 999999 on all digits
' - - - - - - - -- - - - - -- - - - - - - -- - - -
For Number = 0 To 9
Portb = 1
For Large = 1 To 50
' approx 1 second time loop with 200 in large
For Green = 0 To 5
Debounce Pind.4 , 0 , Zero , Sub
Gosub Disp
Waitms Del
Rotate Portb , 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
Portc = 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 > 2000 Then
Clock_word = 0
Once_a_sec = 1
End If
Return
'---- data for 7-seg LED display ------
Tabela:
Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7C , &H07 , &H7F , &H67
' end of program



PS : Nu-i vorba inca de ajustarea Timer0 inca...problema e ca nu pot afisa nimic pe Anod Comun.

#33 OFFLINE   nico_2010

nico_2010

    Membru avansat

  • Moderatori
  • 1,736 posts
  • Locatie:Bucuresti

Posted 16 December 2010 - 10:59 AM

Din curiozitate intreb: comanda afisoarelor cum o faci?
Ai o interfata, gen ULN2803 sau 2003 si catozii conectati la portul uC?

#34 OFFLINE   yo9hnf

yo9hnf

    ElForum staff

  • Moderatori
  • 3,073 posts
  • Locatie:BUCURESTI

Posted 16 December 2010 - 11:02 AM

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.

Posted Image

#35 OFFLINE   nico_2010

nico_2010

    Membru avansat

  • Moderatori
  • 1,736 posts
  • Locatie:Bucuresti

Posted 16 December 2010 - 11:18 AM

codul pentru afisor cu anodul comun.
Inlocuieste-le in tabela si spune-mi si mie cum e!

#36 OFFLINE   yo9hnf

yo9hnf

    ElForum staff

  • Moderatori
  • 3,073 posts
  • Locatie:BUCURESTI

Posted 16 December 2010 - 11:24 AM

Am pus asa :

Tabela:
Data &H81 , &HCF , &H92 , &H86 , &HCC , &HA4 , &HF0 , &H8F , &H80 , &H8C

Si nu "zice" nimic.

#37 OFFLINE   nico_2010

nico_2010

    Membru avansat

  • Moderatori
  • 1,736 posts
  • Locatie:Bucuresti

Posted 16 December 2010 - 11:38 AM

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?

#38 OFFLINE   yo9hnf

yo9hnf

    ElForum staff

  • Moderatori
  • 3,073 posts
  • Locatie:BUCURESTI

Posted 16 December 2010 - 11:43 AM

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.

#39 OFFLINE   nico_2010

nico_2010

    Membru avansat

  • Moderatori
  • 1,736 posts
  • Locatie:Bucuresti

Posted 16 December 2010 - 11:47 AM

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!

#40 OFFLINE   ywar2

ywar2

    Membru

  • Membri
  • PipPip
  • 585 posts

Posted 16 December 2010 - 12:31 PM

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.

#41 OFFLINE   nico_2010

nico_2010

    Membru avansat

  • Moderatori
  • 1,736 posts
  • Locatie:Bucuresti

Posted 16 December 2010 - 12:42 PM

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?

#42 OFFLINE   yo9hnf

yo9hnf

    ElForum staff

  • Moderatori
  • 3,073 posts
  • Locatie:BUCURESTI

Posted 16 December 2010 - 02:01 PM

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.

#43 OFFLINE   ywar2

ywar2

    Membru

  • Membri
  • PipPip
  • 585 posts

Posted 16 December 2010 - 09:37 PM

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 = Output
Portc = 0                                                   'P0

'red
Config Portd = Input
Portd = &B11111111
Portd = 255                                                 'portd

'yellow all high for sw inputs
Config Portb = Output
Portb = 0 'portb
'green
Deasemenea, 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!---

#44 OFFLINE   nico_2010

nico_2010

    Membru avansat

  • Moderatori
  • 1,736 posts
  • Locatie:Bucuresti

Posted 17 December 2010 - 12:38 PM

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 !?

Cu_reclama

Cu_reclama
  • Membri

#45 OFFLINE   ywar2

ywar2

    Membru

  • Membri
  • PipPip
  • 585 posts

Posted 17 December 2010 - 05:39 PM

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!!!




2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users