Files
SyncHome/trunk/workspace/gcb/16c84-interrupt.gcb
2023-03-09 12:51:54 +00:00

84 lines
2.0 KiB
Plaintext

' ########### start ###########
' pic:PIC16C84
' ########### end ###########
'
' ******************************************************************
' Test for a IRQ Routine with a PIC16C84
' 2014-08-18 (c) Paolo Iocco
' ******************************************************************
'
' Circuit diagram
' ---------------
' +--\/--+
' nc-----|1° 18|-------->LED
' nc-----|2 17|-----nc
' nc-----|3 16|<--------H
' +5V--|50K|-->|4 15|<--------H = 4 MHz chrystal+ capacitors
' GND-------->|5 14|<--------+5V
' nc-----|6 13|-----nc
' nc-----|7 12|-----nc
' nc-----|8 11|-----nc
' nc-----|9 10|-----nc
' +------+
'
' ******************************************************************
Config:
#Chip 16C84, 4
#Config OSC = XT, WDT = OFF, PWRTE = ON, CP = OFF
#define Timer_Charge 130 '255-125
#define LED PORTA.1 'led on Pin A1 (18)
Dir LED Out
dim milliseconds as byte
'-------------------------------------------------------------
Startup:
milliseconds=0
Timer_10=0
Timer_1=0
InitTimer0 Osc, PS0_32
TMR0=Timer_Charge
'-------------------------------------------------------------
Interrupts:
On Interrupt Timer0Overflow Call Tmr0_ISR
On Interrupt ExtInt0 Call Irq_ISR
On Interrupt PORTBChange Call Kbd_ISR
'-------------------------------------------------------------
'Main routine
Main:
do
if Timer_10=0 then
LED=not LED
Timer_10=50
end if
loop
' *** Interrupt Routines ***
Sub Tmr0_ISR
'on Timer0 Overflow (IRQ on transition 255 to 0)
T0IF=0 'reset Interrupt Flag
TMR0=Timer_Charge 'reload counter --> Timer_Charge
milliseconds = (milliseconds +1) % 10
if Timer_1>0 then
Timer_1 -- 'decrease Timer 1ms
end if
if (milliseconds=0) and (Timer_10>0) then
Timer_10 -- 'decreases Timer 10ms
end if
End Sub
Sub Irq_ISR
'IRQ pin
INTF=0 'reset Interrupt Flag
End Sub
Sub Kbd_ISR
'PortB Change
RBIF=0 'reset Interrupt Flag
End Sub