here's something to play with.
Code:
' RB0 interrupt
' =============
'
' File name : RB0.bas
' Company : Mister E
' Programmer : Steve Monfette
' Date : 03/05/2005
' Device : PIC16F628
'
' PIC setting
' ===========
'
' Using MPASM to compile the code to target device
'
'
@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _LVP_OFF & _BODEN_ON
' Internal Oscillator
' Enable watch dog timer
' Enable power up timer
' Disable MCLR pin
' Disable low voltage programming
' Enable brown out detect
'
' Hardware definition
' ===================
'
'
TRISB = %00000001 ' RB0 as input, other as output
' Push button between RB0 & ground
'
' I/O Alias definition
' ====================
'
'
RB0LED var PORTB.6
MainLoopLED var PORTB.7
'
' Interrupt Definition
' ====================
'
'
OPTION_REG = 0 ' Enable pull-up on PORTB
' RB0 interrupt on falling edge
INTCON = %10010000 ' Enable Global interrupt
' Enable RB0 interrupt
on interrupt goto RB0Interrupt
'
' Variable definition
' ===================
'
'
Delay var word
'
' MainLoop
' ========
'
'
Start:
' Let's do some led blink on RB.7
'
'
Toggle mainloopled
for Delay = 1 to 500 ' delay loop 500ms
pause 1 ' using 1 ms delay to avoid latency
next '
goto start ' do it forever
Disable Interrupt
RB0Interrupt:
' RB0 interrupt subroutine
'
' will toggle RB6 state everytime we get an interrupt
'
'
Toggle rb0led
while PORTB.0 = 0 ' wait untill RB0 go high
wend
pause 50 ' debounce delay
INTCON.1 = 0 ' Reset RB0 int flag
resume ' return to main loop
Enable interrupt
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks