Well once again I've learned a lot of things, thanks as ever.
In the UK there's a famous comedy sketch where a musician says "I was playing all the right notes
but not necessarily in the right order".
I was a little (ok a lot) like that in this last exercise. I had written down I = 0 to reset the counter, I knew
I had to do that which is something and I'd figured I = I + 1 to add to / increment the counter, so not all bad.
Henrik highlighted within the program:
Code:
INTCON.2 = 1 THEN 'TMR0 Interrupt?
I guess that's because as mackrackit pointed out to me that for the program to be there the INTERRUPT
must have already occured?
Code:
ANSEL = %00000000 'Disable analog select so ports work as digital i/o
CMCON0 = %00000111 'Disable analog comparators
TRISIO = %11111110 'TRISIO.0 set as OUTPUT
GPIO = %00000000 'All bits set LOW
INTCON.5 = 1 'ENABLE TMR0
OPTION_REG = %10000101 '16BIT 1:64 PRESCALE
ON INTERRUPT GOTO TLOOP 'ON INTERRUPT GOTO the INTERRUPT handler LABEL 'TLOOP'
i var byte 'Set I as a VARIABLE BYTE
Main:
Not_pressed:
PAUSE 25 'Leave 25mili_sec for a button press to occur.
if GPIO.5 = 1 THEN GOTO Not_pressed 'Keep waiting for +0v button press on GPIO.5
IF GPIO.5 = 0 THEN goto LED 'Button has been pressed move to LABEL LED:
LED:
TOGGLE GPIO.0 'Change state of GPIO.0 pin
GOTO Not_pressed 'Start again
DISABLE 'Disable INTERRUPT in handler
TLOOP:
IF INTCON.2 = 1 THEN 'TMR0 Interrupt?
I = I + 1 'Increment counter
IF I = 100 THEN 'Has it reached 100?
TOGGLE GPIO.2 'If so, toggle LED...
I = 0 '...and reset counter
ENDIF
INTCON.2 = 0 'Reset interrupt flag
ENDIF
RESUME:ENABLE 'ENABLE INTERRUPT in handler start prog again
10/10 for you guys.
Dave (not clever just persistent).
Bookmarks