Code:
;#######################################################
; #
; 868.3 MHz RF Link - Control Unit #
; #
; Rob Lane 22-4-2013 #
; #
;#######################################################
'
'
;*****************************************************************************
;
; Target Controller - PIC16F628A
; __________
; RF MODULE PIN 2--RA2 |1 18| RA1--- R SELECT
; RF MODULE PIN 3--RA3 |2 17| RA0--- E BIT
; --RA4 |3 16| OSC1--
; +5V--via 4.7k-!MCLR |4 15| OSC2--
; Ground----Vss |5 14| VDD--- +5 V
; sig strength on--RB0 |6 13| RB7--- data 0
; SWITCH --RB1 |7 12| RB6--- data 9
; GREEN LED --RB2 |8 11| RB5--- data 8
; RED LED --RB3 |9 10| RB4--- data 7
; ----------
;
; ****************************************************************************
; * Configuration fuse information:
; ****************************************************************************
@ __config _HS_OSC & _WDT_OFF & _MCLRE_OFF & _BODEN_OFF & _LVP_OFF & _CP_OFF
'
INCLUDE "modedefs.bas"
DEFINE OSC 10
TRISA=%00000000
TRISB=%11110000
CMCON=7 ; comparators off
redled VAR PortB.3
greenled VAR PortB.2
jump VAR PortB.0 ; signal strength switch
switch VAR PortB.1
redstop VAR BYTE
greengo VAR BYTE
rfon var byte
flip VAR BYTE
sigfield var word
sigcontrol var word
DEFINE DEBUG_REG PORTA ; Set Debug pin port
DEFINE DEBUG_BIT 3 ; Set Debug pin bit
DEFINE DEBUG_BAUD 9600 ; Set Debug baud rate
DEFINE DEBUG_MODE 0 ; Set Debug mode: 0 = true, 1 = inverted
DEFINE DEBUGIN_REG PORTA ; Set Debugin pin port
DEFINE DEBUGIN_BIT 2 ; Set Debugin pin bit
DEFINE DEBUGIN_MODE 0 ; Set Debugin mode: 0 = true, 1 = inverted
' LCD Display
' -----------
' Adjust these to suit your chosen LCD pinout
'
Define LCD_DREG PORTB ' Port for LCD Data
Define LCD_DBIT 4 ' Use upper 4 bits of Port
Define LCD_RSREG PORTA ' Port for RegisterSelect (RS) bit
Define LCD_RSBIT 1 ' Port Pin for RS bit
Define LCD_EREG PORTA ' Port for Enable (E) bit
Define LCD_EBIT 0 ' Port Pin for E bit
Define LCB_BITS 4 ' Using 4-bit bus
Define LCD_LINES 2 ' Using 2 line Display
Define LCD_COMMANDUS 1200 ' Command Delay (uS)
PAUSE 500
LCDOut $FE,1 ' Clear LCD
PAUSE 10
LCDOUT $FE,$80," Rob Lane "
LCDOUT $FE,$C0," 2013 "
PAUSE 2000
redstop = 1
greengo = 2
rfon = 3
LCDOUT $FE,1
pause 10
LCDOUT $FE,$80, "Waiting"
IF SWITCH = 1 THEN FLIP = 0 ; check staus of switch at power up
IF switch = 0 then flip = 1 ; counter setup flipflop for single command send
main:
if jump = 0 then rssion
IF switch = 1 AND flip = 0 THEN GOSUB red
PAUSE 50
IF switch = 0 AND flip = 1 THEN GOSUB green
GOTO main
red:
PAUSE 1
DEBUG "BOB",redstop
if jump = 0 then rssion ; check if signal strength display needed
DEBUGIN 500,red,[WAIT("ACK")]
LOW greenled ; turn off green led
HIGH redled ; turn on red led
LCDOUT $FE,1 ; clear lcd
Pause 10
LCDOUT $FE,$80," Light is RED "
flip = 1 ; flip flop counter to ensure send only once
RETURN
green:
PAUSE 1
DEBUG "BOB",greengo
if jump = 0 then rssion
DEBUGIN 500,green,[WAIT("ACK")]
LOW redled
HIGH greenled
LCDOUT $FE,1
PAUSE 10
LCDOUT $FE,$C0," Light is GREEN "
flip = 0
RETURN
rssion:
LCDOUT $FE,1
Pause 10
LCDOUT $FE,$80," Test Mode "
pause 1500
; ############### TEST MODE ON #####################
ison:
debug "BOB",rfon
if jump = 1 then rssioff
debugin 1000,ison,[WAIT("ACK")]
PAUSE 1100 ; wait 1 second
debug "+++"
debugin 1500,ison,[WAIT("OK")]
PAUSE 1100 ; wait 1 second
LCDOUT $FE,$80, "Pass +++"
pause 1500
debug "ATNT3",13,10
debugin 1500,ison,[WAIT("OK")]
LCDOUT $FE,$80, "Pass ATNT3"
pause 1500
DEBUG "ATDN",13,10
debugin 1500,main,[WAIT("OK")]
LCDOUT $FE,$80, "Pass ATDN"
pause 1500
LCDOUT $FE,$80, "Signal Strength"
Pause 10
sigstrength:
if jump = 1 then rssioff ; check input to reset to serial
debugin 1000,sigstrength,[WAIT("aSSRSSIS-",sigfield)] ; get slave signal strength value
debugin 1000,sigstrength,[WAIT("aMMRSSIM-",sigcontrol)] ; get control signal strength value
LCDOUT $FE,$80," Light Unit ",sigfield
LCDOUT $FE,$C0," Control Unit ",sigcontrol
goto sigstrength
rssioff:
LCDOUT $FE,1
Pause 10
PAUSE 1100 ; wait 1 second
debug "+++"
debugin 1500,rssioff,[WAIT("OK")]
PAUSE 1100 ; wait 1 second
debug "ATNT0",13,10
debugin 1500,rssioff,[WAIT("OK")]
debug "ATDN",13,10
debugin 1500,main,[WAIT("OK")]
LCDOUT $FE,1
pause 10
goto main
END
Code:
;#######################################################
; #
; 868.3 MHz RF Link - Field Unit #
; #
; Rob Lane 22-4-2013 #
; #
;#######################################################
'
'
;*****************************************************************************
;
; Target Controller - PIC16F628A
; __________
; RF MODULE PIN 2--RA2 |1 18| RA1--------- RELAY
; RF MODULE PIN 3--RA3 |2 17| RA0---------
; -RA4 |3 16| OSC1--------
; +5V-----------!MCLR |4 15| OSC2--------
; Ground----------Vss |5 14| VDD---------+5 V
; -----------RB0 |6 13| RB7---------
; -----------RB1 |7 12| RB6---------
; ---RB2 |8 11| RB5---------
; --RB3 |9 10| RB4---------
; ----------
;
; ****************************************************************************
; * Configuration fuse information:
; ****************************************************************************
@ __config _HS_OSC & _WDT_OFF & _MCLRE_OFF & _BODEN_OFF & _LVP_OFF & _CP_OFF
'
INCLUDE "modedefs.bas"
DEFINE OSC 10
TRISA=%00000100
CMCON=7
relay VAR PortA.1
signal VAR BYTE
DEFINE DEBUG_REG PORTA ; Set Debug pin port
DEFINE DEBUG_BIT 3 ; Set Debug pin bit
DEFINE DEBUG_BAUD 9600 ; Set Debug baud rate
DEFINE DEBUG_MODE 0 ; Set Debug mode: 0 = true, 1 = inverted
DEFINE DEBUGIN_REG PORTA ; Set Debugin pin port
DEFINE DEBUGIN_BIT 2 ; Set Debugin pin bit
DEFINE DEBUGIN_MODE 0 ; Set Debugin mode: 0 = true, 1 = inverted
LOW relay
' Program
main:
debugin [WAIT("BOB"),signal]
IF signal = 1 THEN
GOSUB redstop
ENDIF
IF signal = 2 THEN
GOSUB greengo
ENDIF
IF signal = 3 THEN
GOSUB rssion
ENDIF
GOTO main
redstop:
HIGH relay
PAUSE 1000
debug "ACK"
RETURN
greengo:
LOW relay
PAUSE 1000
debug "ACK"
RETURN
rssion:
debug "ACK"
pause 10
debug "ACK"
pause 10
debug "ACK"
PAUSE 1100
debug "+++"
debugin 1500,rssion,[WAIT("OK")]
PAUSE 1100
high relay ;relay has led for ON
pause 500
debug "ATNT4",13,10
debugin 1500,rssion,[WAIT("OK")]
low relay
pause 500
debug "ATDN",13,10
debugin 1500,rssion,[WAIT("OK")]
high relay
pause 15000 ; waiting time in test mode before return to normal
goto rssioff
rssioff:
PAUSE 1100 ; wait 1 second
debug "+++"
debugin 1500,rssioff,[WAIT("OK")]
PAUSE 1100 ; wait 1 second
debug "ATNT0",13,10
debugin 1500,rssioff,[WAIT("OK")]
debug "ATDN",13,10
debugin 1500,rssioff,[WAIT("OK")]
goto main
END
Bookmarks