|
|
|
||||||||
| Arcade | Registrazione | Blogs | Regolamento | Feedback | FAQ | Lista Utenti | Calendario | Segna come Letti |
| Ultimi 5 blog pubblicati su PcTuner Blog | ||||||
|
||||||
![]() |
|
|
Strumenti Discussione | Modalità Visualizzazione |
|
|
#1 |
|
Registered User
|
Problema Contaore Pic16f877a
salve a tutti, come da titolo ho un piccolo problema con un contatore/orologio che sto facendo.
addese vi spiego meglio. vorrei decidere con un pulsanti di fare partire il contatore e con uno di interromperlo ma non ci riesco. vi posto il codice in mikrobasic, premetto che non sono un esperto di basic. program prova_orologio dim cnt as word dim sec as byte dim sec10 as byte dim min as byte dim min10 as byte dim premuto as byte dim conta as byte dim ore as byte sub procedure interrupt Inc(cnt) TMR0 = 6 INTCON = $20 end sub main: OPTION_REG = $C4 TRISD = $FF TRISC = 0 PORTC = 1 TMR0 = 6 INTCON = $A0 cnt = 0 sec10 =0 min = 0 min10 = 0 ore = 0 Lcd_Config(PORTB,3,2,1,0,PORTB,4,7,5) LCD_Cmd(LCD_CLEAR) LCD_Cmd(LCD_CURSOR_OFF) while true if (cnt = 250) then 'per 1 secondo 250 PORTC = not PORTC cnt = 0 Inc(sec) if (sec > 9) then Inc(sec10) sec=0 if (sec10 = 6) then Inc(min) sec10=0 if (min=9) then Inc(min10) min=0 if (min10=5) then Inc(ore) min10=0 end if end if end if end if Lcd_Chr(1,2, ore+48) Lcd_Chr(1,3, ":") Lcd_Chr(1,4, min10+48) Lcd_Chr(1,5, min+48) Lcd_Chr(1,6, ":") Lcd_Chr(1,7, sec10+48) Lcd_Chr(1,8, sec+48) end if wend end. ho provato a fare a cosi: al posto del while true ho messo un flag, conta = 0 sotto l'ultima riga di codice per la visualizzazione dei secondi sul display ho messo: if (Button(PORTD, 1, 100, 1)) then conta = 0 end if while conta = 0 if (Button(PORTD, 0, 100, 1)) then conta = 1 end if wend end if end. dove sbaglio?? |
|
|
|
|
|
#2 |
|
RockModerator
|
premetto che di microbasic e affini non mi intendo e penso che non ne farò mai, ma prova qualcosa del tipo
. . . Lcd_Config(PORTB,3,2,1,0,PORTB,4,7,5) LCD_Cmd(LCD_CLEAR) LCD_Cmd(LCD_CURSOR_OFF) while true if (Button(PORTD, 1, 100, 1)) then conta = 0 end if if (Button(PORTD, 0, 100, 1)) then conta = 1 end if if (cnt = 250)AND(conta=1) then 'per 1 secondo 250 PORTC = not PORTC cnt = 0 Inc(sec) if (sec > 9) then Inc(sec10) sec=0 if (sec10 = 6) then Inc(min) sec10=0 if (min=9) then Inc(min10) min=0 if (min10=5) then Inc(ore) min10=0 end if end if end if end if Lcd_Chr(1,2, ore+48) Lcd_Chr(1,3, ":") Lcd_Chr(1,4, min10+48) Lcd_Chr(1,5, min+48) Lcd_Chr(1,6, ":") Lcd_Chr(1,7, sec10+48) Lcd_Chr(1,8, sec+48) end if wend end. Nel senso che ad ongi passaggio prima metti il flag a 1 o a 0 secondo che sia premuto uno o l'altro bottone, poi se conta=1 allora incrementi. Con un pò di lavoro in più potresti fare in modo che quando premi tutti e due i bottoni il contatore va a 0. |
|
|
|
![]() |
Per le vostre immagini su questo forum potete usare PcTunerUp! Iscriviti gratuitamente alla nostra newsletter. |
| Utenti attualmente attivi che stanno leggendo questa discussione: 1 (0 utenti e 1 visitatori) | |
| Strumenti Discussione | |
| Modalità Visualizzazione | |
|
|