Sari la conținut
ELFORUM - Forumul electronistilor

BASCOM


Postări Recomandate

Salut. YO9HNF, ai facut ceasul sa mearga? Ai pus o intrebare si eu m-am invrednicit sa-ti raspund. Eram curios: merge?Si pina se lamureste ce este cu subiectul asta Bascom si o sa apara si exemplele, pun eu o intrebare: ce face comanda GOSUB, caci mie mi se pare a fi un CALL cosmetizat. Comanda CALL am tot folosit-o in proiectele mele, dar uitindu-ma in exemplul cu ceasul de mai sus, mi-am reamintit de ea. Cum de la HC85 au trecut o gramada de ani, putin remember nu strica. Pe curind!!!

Link spre comentariu

Imi exprim disponibilitatea de a furniza celor interesati un curs de programare folosind platforma BASCOM-AVR.

Din pacate fisierul are 33Mb, asa ca ... pm cu o adresa de e-mail.

Desi este in engleza, sper ca va gasi cititori.

 

Cu privire la propunerile din topic, particip cu draga placere si cu bruma de experienta pe care o am.

daca esti doresti m-ar interesa si pe mine acel curs

 

ID-iul meu: [email protected]

Link spre comentariu

Nu e o idee buna sa va dati adresa de e-mail in clar pe o pagina publica. Exista roboti care se ocupa cu strangerea automata de asdrese de e-mail si dupa aia va treziti ca nu se mai termina reclamele si spam-urile din casuta voastra postala... :rade:

 

Gosub si Call fac aproape acelasi lucru, cheama o subrutina.

La call poti sa trimiti si paramentri pe cand la gosub nu.

 

Uite cum se foloseste help-ul din BASCOM. Scrii in programul tau

Gosub

pe urma dai click in interiorul cuvantului Gosub pe care tocmai l-ai scris si apesi tasta F1 (este a doua tasta de pe tastatura, pe randul de butoane cel mai de sus). Se va deschide automat o pagina unde iti spune ce face instructiunea Gosub, cum se foloseste si la sfarsit exemple de cod cu Gosub. Tot acolo ai si trimiteri catre alte instructiuni care au legatura cu gosub, cum ar fi Call.

 

F1 inseamna HELP in aproape orice program, inclusiv in BASCOM.

Folositi F1 cu toata incredearea! :limb:

Link spre comentariu

Salut. YO9HNF, ai facut ceasul sa mearga? Ai pus o intrebare si eu m-am invrednicit sa-ti raspund. Eram curios: merge?

Salut ywar2 !

Din pacate nu merge nici cum mi-ai indicat tu. Am incercat sa pun 254 si aici :

 

For Seconds = 1 To 5Diagdelay = Diagdelay - 20Portd = 1
si tot nu merge.

 

 

LATER EDIT : Am gasit si eu o carticica foarte bine gandita, cu paralela intre algoritm si bascom + exemple scurte.

http://www.scribd.com/document_downloads/direct/41387840?extension=pdf&ft=1292355007&lt=1292358617&uahk=JR52L8Rh80Zu9ViTztHJ7VgTKvo

 

 

SI MAI "LATER" : Am uplodat cartea pe megaupload si am scos din ea lucrurile inutile :

 

http://www.megaupload.com/?d=A3E2UD8H

Link spre comentariu

Salut tuturor. RoGeorge, merci ptr raspuns. Am avut dreptate, GOSUB este un CALL cosmetizat, aceeasi Marie dar cu alta palarie. Ma intreb cit spatiu ocupa intr-un procesor. Uneori cind ajungi cu spatiul la limita, te uiti sa mai ajustezi codul, pe ici, pe colo. Daca un GOSUB ocupa mai mult sau mai putin decit un CALL neconditionat, atunci merita sa stii. Despre F1 stiu de mult, din exemplele din Help ma inspir cel mai mult....invat din mers.YO9HNF, regret ca nu merge codul, in principiu ar fi trebuit sa mearga. Ar fi interesant sa pui codul tau modificat aici, se pare ca sint multi care se pricep la asta si multi care vor sa invete din experienta ta. Pina la proxima, 73!!!

Link spre comentariu

YO9HNF, regret ca nu merge codul, in principiu ar fi trebuit sa mearga. Ar fi interesant sa pui codul tau modificat aici, se pare ca sint multi care se pricep la asta si multi care vor sa invete din experienta ta. Pina la proxima, 73!!!

Nicio problema ! Ii dam noi de cap...
'--------------------------------------------------------------$regfile = "m32def.dat"$crystal = 16000000'6 mhz crstalDim 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 0Porta = 1'redPortb = 255'yellow all high for sw inputsPortd = 255'greenPortc = 0'blue not usedConfig Debounce = 30' key debounce time in milli secondsConfig Timer0 = Timer , Gate = Internal , Mode = 2'Timer0 use timer 0'Gate = Internal no external interrupt'Mode = 2 8 bit auto reloadGosub Diag' diagnostic routine' set t0 internal interruptOn Timer0 Timer_0_intLoad Timer0 , 250'PrioritySet Timer0                                                  'EROARE RADUEnable InterruptsEnable Timer0Start Timer0Hours = 0Minutes = 0Seconds = 0Clock_word = 0Do' yellow port-1 key inputs for settingDebounce Portb.0 , 0 , Hup , SubDebounce Portb.1 , 0 , Hdown , SubDebounce Portb.2 , 0 , Mup , SubDebounce Portb.3 , 0 , Mdown , SubDebounce Portb.4 , 0 , Zero , SubIf Once_a_sec = 1 Then' once_a_sec=calculation every secondOnce_a_sec = 0'update hh mm ss'inc SecondsIf Seconds = 60 ThenSeconds = 0'inc MinutesIf Minutes = 60 ThenMinutes = 0'inc HoursIf Hours = 24 ThenHours = 0End IfEnd IfEnd IfEnd If' display time constantly' hoursNumber = Hours / 10Portd = 254Gosub DispWaitms DelPorta = 0'-------Number = Hours Mod 10Portd = 253Gosub DispWaitms DelPorta = 0'-------'minutesNumber = Minutes / 10Portd = 251Gosub DispWaitms DelPorta = 0'-------Number = Minutes Mod 10Portd = 247Gosub DispWaitms DelPorta = 0'-------'SECONDSNumber = Seconds / 10Portd = 239Gosub DispWaitms DelPorta = 0'-------Number = Seconds Mod 10Portd = 223Gosub DispWaitms DelPorta = 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 - 20Portd = 1                                                   'INAINTE ERA 1For Green = 0 To 5Porta = 1For Red = 0 To 7Debounce Portb.4 , 0 , ZeroWaitms DiagdelayRotate Porta , LeftNext RedRotate Portd , LeftNext GreenNext Seconds' next diag show 000000 to 999999 on all digits' - - - - - - - -- - - - - -- - - - - - - -- - - -For Number = 0 To 9Portd = 1                                                   'INAINTE ERA 1For Large = 1 To 50' approx 1 second time loop with 200 in largeFor Green = 0 To 5Debounce Portb.4 , 0 , ZeroGosub DispWaitms DelRotate Portd , 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 displayPorta = 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 63 , 6 , 91 , 79 , 102 , 109 , 125 , 7 , 127 , 111Data 192 , 249 , 164 , 176 , 153 , 146 , 130 , 248 , 128 , 144' end of program' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Link spre comentariu

Salut!

Dupa o "profunda" analiza a schemei si programului de ceas, va propun urmatorul program, cu mentiunea ca nu se obtin rezultate satisfacatoare la simulare din cauza depasirii unora dintre parametrii simulatorului (P****us).

Programul este pentru ATMEGA 8, iar pentru ATMEGA32 se modifica $regfile, $hwstack si $swstack.

$regfile = "m8def.dat"

$crystal = 8000000

'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 = 1

Gosub Disp

Waitms Del

Portc = 0

'-------

Number = Hours Mod 10

Portb = 2

Gosub Disp

Waitms Del

Portc = 0

'-------

'minutes

Number = Minutes / 10

Portb = 4

Gosub Disp

Waitms Del

Portc = 0

'-------

Number = Minutes Mod 10

Portb = 8

Gosub Disp

Waitms Del

Portc = 0

'-------

'SECONDS

Number = Seconds / 10

Portb = 16

Gosub Disp

Waitms Del

Portc = 0

'-------

Number = Seconds Mod 10

Portb = 32

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

Afisarea se face pe afisoare cu catod comun.

Link spre comentariu

Salut1

Pentru codurile segmentelor, te rog sa folosesti modelul de tabel din celalalt topic, tinand cont de nivelul logic care activeaza segmentele afisorului, iar pentru partea de multiplexare, inlocuieste in codul pe care l-am postat (si care este adaptarea programului pentru 8051) cu urmatoarele:

secunde: PORTB = 62 (111110)

zeci de secunde: PORTB = 61 (111101)

minute: PORTB = 59 (111011)

zeci de minute: PORTB = 55 (110111)

ore: PORTB = 47 (101111)

zeci de ore: PORTB = 31 (011111)

Cred ca trebuie sa ajustezi si prescalerul pentru Timer 0, deoarece este foarte posibil sa nu bata secunda.

Recunoasc ca in momentul asta mi-e lene sa adaptez placa cu afisoare la "placa de dezvoltare" pentru ca lucrez la un analizor de spectru 2,4 GHz care e mai captivant.

Link spre comentariu

Alătură-te conversației

Poți posta acum și să te înregistrezi mai târziu. Dacă ai un cont, autentifică-te acum pentru a posta cu contul tău.
Notă: Postarea ta va necesita aprobare moderator înainte de a fi vizibilă.

Vizitator
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Răspunde la acest subiect...

×   Alipit ca text avansat.   Restituie formatare

  Doar 75 emoji sunt permise.

×   Linkul tău a fost încorporat automat.   Afișează ca link în schimb

×   Conținutul tău precedent a fost resetat.   Curăță editor

×   Nu poți lipi imagini direct. Încarcă sau inserează imagini din URL.

×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări