Il mio obiettivo era quello di fare un semplice programma asm per PIC 16f84 che potesse far lampeggiare un led e tenerlo spento per alcuni secondi.
In più volevo che quando andavo a premere un pulsante questo tempo da un lampeggio e l'altro si andasse attenuando arrivando a 0 (led fisso)
a questo punto quando ripremevo il pulsante il led tornava nella posizione iniziale, cioè lampeggio ogni tot di secondi (costante).
Ho provato a farlo così... è MOLTO poco elegamente:
CODICE
LED1 EQU 0
LED2 EQU 1
LED3 EQU 2
LED4 EQU 3
SW1 EQU 4
SW2 EQU 5
SW3 EQU 6
SW4 EQU 7
ORG 0x0C
Count RES 2
;Reset Vector
;Start point at CPU reset
ORG 0x00
bsf STATUS,RP0
movlw 00011111B
movwf TRISA & 7FH
movlw 11110000B
movwf TRISB & 7FH
bcf STATUS,RP0
clrf PORTB
MainLoop
call Beep
btfss PORTB,SW1
goto Premuto
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
goto MainLoop
Beep
bsf PORTB,LED1
call Delay
bcf PORTB,LED1
return
Premuto
call Beep
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Beep
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Beep
call Delay
call Delay
call Delay
call Beep
call Delay
call Delay
call Delay
call Beep
call Delay
call Delay
call Beep
call Delay
call Delay
goto Costante
Costante
bsf PORTB,LED1
btfsc PORTB,SW1
goto MainLoop
goto Costante
Delay
clrf Count
clrf Count+1
movlw 200
movwf Count+1
DelayLoop
decfsz Count,1
goto DelayLoop
decfsz Count+1,1
goto DelayLoop
return
END
LED2 EQU 1
LED3 EQU 2
LED4 EQU 3
SW1 EQU 4
SW2 EQU 5
SW3 EQU 6
SW4 EQU 7
ORG 0x0C
Count RES 2
;Reset Vector
;Start point at CPU reset
ORG 0x00
bsf STATUS,RP0
movlw 00011111B
movwf TRISA & 7FH
movlw 11110000B
movwf TRISB & 7FH
bcf STATUS,RP0
clrf PORTB
MainLoop
call Beep
btfss PORTB,SW1
goto Premuto
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
goto MainLoop
Beep
bsf PORTB,LED1
call Delay
bcf PORTB,LED1
return
Premuto
call Beep
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Beep
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Beep
call Delay
call Delay
call Delay
call Beep
call Delay
call Delay
call Delay
call Beep
call Delay
call Delay
call Beep
call Delay
call Delay
goto Costante
Costante
bsf PORTB,LED1
btfsc PORTB,SW1
goto MainLoop
goto Costante
Delay
clrf Count
clrf Count+1
movlw 200
movwf Count+1
DelayLoop
decfsz Count,1
goto DelayLoop
decfsz Count+1,1
goto DelayLoop
return
END
Si, si fa schifo, ma per migliorare c'è tempo...
Volevo sapere se l'input va messo a massa o ai 5V.
E poi perchè provandolo ogni tanto il tenpo di lampeggiamento cambia di brutto (nel mainloop) senza che io prema nulla.
E' possibile che lagga un input senza che io lo dia veramente?
Gli osillatori RC sono poco affidabili? Può essere questa al causa di un variare della frequenza anche nel mainloop?
Grazie, ciao