Code:
'****************************************************************
'* Name : Test RDT Interrupt for one-time use
'* Author : Dick Ivers
'* Notice : Copyright (c) 2011
'* : All Rights Reserved
'* Date : 1/30/2011
'* Version : 1.0
'* Notes : 112 words
'* Device : 16F1828
'****************************************************************
'set configurat1on
@ __config _CONFIG1, _FOSC_HS & _MCLRE_ON & _CLKOUTEN_OFF & _WDTE_ON
@ __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
'set registers
ANSELA = 0 'all digital inputs
ANSELB = 0 'all digital inputs
ANSELC = 0 'all digital inputs
OPTION_REG.7 = 0 'global pullups enabled
CM1CON0.7 = 0 'comparator1 off
CM2CON0.7 = 0 'comparator2 off
TRISA = %110 'set porta pin 0 as output
TRISB = %11111111 'set all portb pins as inputs
TRISC = %11000000 'set portc pins 0,1,2,3,4,5 as output
WPUA = %110 'porta pins 1,2 pullups enabled
WPUB = %11110000 'portb pin pullups enabled
INTCON = %10001000 'global int enabled, IOCI enabled, IOCI flag bit 0 clr
IOCAF.1 = 0 'flag bit for porta int pin 1 cleared
IOCAN = %00000010 'porta pin 1 enabled for negative change
DEFINE OSC 16 '16 Mhz oscillator
DEFINE INTHAND RDT
portc.3 = 1 'turn off beeper
'declare variables
LED VAR PORTC.5
j var byte
LED = 0 'flash red LED for 0.5 sec to check circuit function
pause 500
LED = 1
pause 2000 'delay 2 seconds
Main:
gosub beep 'play beep for 1/8 second
PAUSE 1000 '1 second delay
GOTO Main
ASM
RDT
BCF IOCAF,IOCAF1 ;clear IOCA negative change interrupt flag
BCF INTCON,3 ;disable interrupt on change by clearing INTCON bit 3
BCF PORTC,5 ;turn on led solid
RETFIE ;return to main
ENDASM
beep: for j =1 to 240 'buzzer sound for 1/8 second
portc.3 = 0 'buzzer on
pauseus 180 '2.73 khz half period
portc.3 = 1 'buzzer off
pauseus 180 '2.73 khz half period
next
return
halt: END
Bookmarks