I'm having a problem getting the rfpic transmitter to Tx when I want it to. I've set up an ON INTERRUPT with DISABLE - RESUME - ENABLE and have the INTCON & IOC set at:
Code:
INTCON = %00001000 & IOC = %00011000
What happens is, when buttons GPIO3/4 are pressed (and released)the RFEN led after a 5sec delay briefly flashes but no data is sent. If GPIO.3/4 are pressed and held down after 10 secs the RFEN led lights up the five seconds later (button still held down) data is Tx'd, the button is then released and five seconds later the RFEN led goes out.
What I'd like is for the buttons GPIO.3/4 to be pressed, ON INTERRUPT runs then five seconds later after the delay loop the data is Tx'd. Does anyone have any idea on what's going wrong?
Code:
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
DEFINE OSC 4
DEFINE OSCCAL_1K 1
DEFINE NO_CLRWDT 1
SYMBOL D_OUT = GPIO.2 ' RF serial data output
SYMBOL E_OUT = GPIO.5 ' RF transmitter enable output
ON INTERRUPT GOTO Delay
DAT_OUT VAR BYTE ' Holds 8-bit data byte
CHK_SUM VAR BYTE ' Holds calculated checksum of outbound data
VISITS VAR WORD ' Loop variable (300 for test)
I VAR word ' Delay Loop Count value
BAUD VAR WORD ' Holds baud rate
' Constants
PreAmble CON $A5 ' 10100101 preamble
Synch CON "~" ' 01111110 synch byte
N4800 CON 188 ' 4800 bps
N2400 CON 16780 ' 2400 bps
GUARD CON 5 ' 5mS guard time pause
' hardware init
GPIO = 0 ' Everything off on boot
' GPIO.2=data out, GPIO.5=RF enable, GPIO.3,4 = Bird_visit_count / It's dark..maybe
TRISIO = %00011011 '
ANSEL = 0 ' Disable A/D
INTCON = %00001000 ' Enable port change wakeup from sleep
WPU = %00010000 ' pull-up on for GPIO.4 (external pull-up already on GPIO.3)
IOC = %00011000 ' Wakeup on change enabled for GPIO.3,4
VRCON = 0 ' Disable internal Vref
CMCON = 7 ' Disable comparators
OPTION_REG = 0 ' Pull-ups on
D_OUT = 0 ' Idles low for inverted serial output
E_OUT = 0 ' Enable for RF transmitter=0 (transmiter off)
BAUD = N2400 ' Set baud rate here
Main:
' Read port to clear missmatch, if with no buttons pressed, then
' clear int-on-change flag & snooze until wake up on change. This
' conserves battery power on the demo board with 3V coin cell.
IF GPIO.3= 1 AND GPIO.4= 1 THEN ' Nothing has happened so SLEEP
E_OUT=0 ' Disable transmitter
INTCON.0 = 0 ' No Inputs detected or it's still light so clear int on change flag
@ SLEEP ' and start snoozin..zzzzzzzzzzz indefinatly / Waiting for IOC
@ NOP
'ON INTERRUPT starts / returns here with Button_press: goes to LABEL - "DELAY":
ENDIF
Encode:
E_OUT=1 ' Turn transmitter on
pauseus 25 ' Let transmitter settle
DAT_OUT = %10101001
'Build checksum of 2 data bytes
CHK_SUM = (DAT_OUT * 2)
Transmit:
'LET VISITS = VISITS / 2 'Just VISITS too not from the box
LET VISITS = 300 'Test data number
SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM,VISITS.highbyte,VISITS.lowbyte]
PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.
GOTO Main
disable
Delay:
FOR I = 1 TO 5
PAUSe 1000
nEXT I
INTCON.0 = 0
resume : enable
goto Main
Dave
Bookmarks