Yes, I told you to use DISABLE-ENABLE-RESUME... I thought you were playing with ONINTERUPPT.
Looks like you are still using Bruce's code as a base, so lets go back to it and modify it some.
But first you may want to try Bruce's code as he wrote it to make sure your hardware is working correctly.
Code:
'****************************************************************
'* Name : rfPIC_TX.BAS *
'* Author : B. Reynolds *
'* Notice : Copyright (c) 2007 Reynolds Electronics *
'* : All Rights Reserved *
'* Date : 10/09/2007 *
'* Version : 1.0 *
'* Notes : 2-BIT Encoder for remote control with the *
'* : rfPIC12F675 on Microchip rfPIC demo board *
'****************************************************************
@ DEVICE PIC12F675,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
@ DEVICE PWRT_ON,PROTECT_OFF
' With rfRXD0420 module installed in PICkit 1 board;
' SW1 toggles LED D6 on PICkit 1 board
' SW2 toggles LED D7 on PICkit 1 board
DEFINE OSC 4
DEFINE NO_CLRWDT 1
DEFINE OSCCAL_1K 1
SYMBOL D_OUT = GPIO.2 ' RF serial data output
SYMBOL E_OUT = GPIO.5 ' RF transmitter enable output
DAT_OUT VAR BYTE ' Holds 8-bit data byte
LOOPS VAR BYTE ' Loop var
CHK_SUM VAR BYTE ' Holds calculated checksum of outbound data
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=SW1/SW2 switch inputs (rfPIC board)
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 ' pins will be 0 only when buttons are pressed
E_OUT=0 ' Disable transmitter
INTCON.0 = 0 ' No buttons down, so clear int on change flag
@ SLEEP ' and start snoozin..zzzzzzzzzzz
@ NOP ' Do nothing for 1st instruction on wake-up
ENDIF
E_OUT=1 ' Enable transmitter (+ lights RFEN LED on demo board)
PAUSEUS 25 ' Allow RF stage to stabilize
' Button pressed (or being held down), so keep going
' Here is where you want to put the 5 second loop
Delay:
FOR I = 1 TO 5
PAUSe 1000
NEXT I
'Then check the buttons again
IF (GPIO.3=1) AND (GPIO.4=1) THEN
'Look for ENDIF near the end.
'If button are still pressed then it goes to ENCODE
'If not, go back to MAIN and the INTERRUPT ON CHANGE will be reset
Encode:
' Only DAT_OUT bits 1 and 2 are used. We add a few 1's in bit
' positions 0,3,5,7 to balance out the data packet being sent.
DAT_OUT = %10101001
' Get data on button inputs & invert 0's to 1's
DAT_OUT.0[1]=~GPIO.3
DAT_OUT.0[2]=~GPIO.4
INTCON.0 = 0 ' Clear int on change flag
' Build checksum of 2 data bytes
CHK_SUM = (DAT_OUT * 2)
Transmit:
SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM]
PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.
ENDIF
GOTO Main
END
Bookmarks