EE_Vars.PBP error with firecracker code
Hi Darrel,
When I try and compile the firecracker code below using your EE_Vars.PBP I get an error saying:
" 3.asm 141: Overwriting previous address contents (2100) "
I'd sure like to be able to use your EE_Vars.PBP because it has some neat features and is really easy to implement. Possibly the reason it won't compile has something to do with declaring the Data statements for the firecracker taking up some of the same address's as EE_Vars.PBP is using? I tried using EEPROMData100 var BYTE for X and EEPROMData101 var BYTE for Y and EEPROMData102 var BYTE for Z and it seems to be working good but I like your EE_Vars way better.
Also the firecracker code won't work on the 16f688 when I do get it to compile without using your EE_Vars.PBP but the exact same code works perfectly on my 16f877 without your EE_Vars.PBP? I'll try changing the dtr & rts port pins but I can't really see them causing a problem. Any help would really be appreciated.
Thanks
jessey
Code:
'*******************************************************************************
'* Name : Test Program for the Firecracker Interface *
'* Author : Jessey Montgomery *
'* Includes: Darrel Taylor's EE_Vars.PBP & Al Williams Firecracker Interface *
'* Date : April 24/th 2009 *
'* Version : Using PicBasic Pro Ver 2.50, MPASM Ver 5.20, Using MicroCode *
'* : Studio 3.0.0.5, PICkit 2 programmer - Application Version *
'* : 2.50.02 - Device File Version 1.5100 - OS Firmware Version *
'* : 2.30.01. Using a Pic16F688-I/P 04470AY. *
'*******************************************************************************
'(1) Comments & Objectives
' =====================
' this program is just a test program for checking the firecracker
' Clear Each Port Before Setting The TRIS Registers
Clear ' Set all ram registers to zero
PORTA = 0
PORTC = 0
' VSS VDD MCLR Ect. Pins
'VDD + '(pin 1)
'VSS - '(pin 14)
' SET THE TRIS
' PORTA PINS
TRISA.0 = 0 '(pin 13) connect green wire of firecracker - dtr VAR PORTA.0
TRISA.1 = 0 '(pin 12) connect red wire of firecracker - rts VAR PORTA.1
TRISA.2 = 0 '(pin 11) Not Used VAR PORTA.2
TRISA.3 = 1 '(pin 4) Button_5 VAR PORTA.3
TRISA.4 = 0 '(pin 3) Not Used VAR PORTA.4
TRISA.5 = 0 '(pin 2) Led VAR PORTA.5
' PORTC PINS
TRISC.0 = 0 '(pin 10) Blue Lcd Data bit 4
TRISC.1 = 0 '(pin 9) White Lcd Data bit 5
TRISC.2 = 0 '(pin 8) Green Lcd Data bit 6
TRISC.3 = 0 '(pin 7) Orange Lcd Data bit 7
TRISC.4 = 0 '(pin 6) Orange/Black Lcd Register select
TRISC.5 = 0 '(pin 5) Blue/White Lcd Enable bit
'(2) PIC Config Fuse Definitions for 16f688
@ __CONFIG _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF
@ ERRORLEVEL -306; ' turns off cross page boundary message alerts after compile
'(3) PIC Hardware Definitions (ie Pin-Out & Port Assignments)
ANSEL = 0 ' all pins are digital
CMCON0 = 7 ' turn off comparators
' Data for house and unit codes
housetbl data $60,$70,$40,$50,$80,$90,$A0,$B0,$E0,$F0,$C0,$D0
data $00,$10,$20,$30
unittbl data 0,$10,$8,$18,$40,$50,$48,$58
DEFINE LCD_RSREG PORTC' LCD Register Select Port
DEFINE LCD_RSBIT 4 ' LCD Register Select
DEFINE LCD_EREG PORTC ' LCD Enable Port
DEFINE LCD_EBIT 5 ' LCD Enable
DEFINE LCD_DREG PORTC ' LCD Data Port
DEFINE LCD_DBIT 0 ' LCD data starting bit 0 or 4
Button_5 VAR PORTA.3 ' pin 4
Led VAR PORTA.5 ' pin 2
' The 3 connections to the firecracker are below...
' Wire Ground (DB9 pin 5) black
dtr VAR PORTA.0 ' pin 13 connects to DB9 pin 7 of the firecracker (green wire)
rts VAR PORTA.1 ' pin 12 connects to DB9 pin 4 of the firecracker (red wire)
a VAR BIT
a = 0
X VAR BYTE
X = 0
Y VAR BYTE
Y = 0
Z VAR BYTE
Z = 0
Timer VAR byte
Timer = 0
' byte to send
byt var byte
tmp var byte
i var BYTE 'was a nib
state var bit(4)
house var byte '0=A 1=B...
unit var BYTE ' 0-15 (must be 0 for bright/dim) 'was a nib
cmd var BYTE ' 0=off 1=on 2=bright 3=dim 'was a nib
Is_Pressed CON 0
Is_Not_Pressed CON 1
Is_Turned_On CON 1
Is_Turned_Off CON 0
' The Firecracker header (2 bytes)
h1 con $D5
h2 con $AA
' the Firecracker footer (1 byte)
foot con $AD
'4a. EEPROM Assignments
' INCLUDE "EE_Vars.PBP"
' Declare The EE Variable - Load A Default Setting For The EE Variable
' X VAR BYTE ': @ EE_var _X, BYTE,0
' Y VAR BYTE ': @ EE_var _Y, BYTE,0
' Z VAR BYTE ': @ EE_var _Z, BYTE,0
' To write to the eeprom @ EE_write_var _X
' @ EE_write_var _Y
' @ EE_write_var _Z
gosub resetfirecracker
IF X = 1 THEN
house = 0 : unit = 4 : cmd = 1 'when unit = 4 in code, set X10 receiver to 5
gosub sendcmd
ELSE
house = 0 : unit = 4 : cmd = 0 'when unit = 4 in code, set X10 receiver to 5
gosub sendcmd
ENDIF
IF Y = 1 THEN
house = 0 : unit = 2 : cmd = 1 'when unit = 2 in code, set X10 receiver to 3
gosub sendcmd
ELSE
house = 0 : unit = 2 : cmd = 0 'when unit = 2 in code, set X10 receiver to 3
gosub sendcmd
ENDIF
IF Z = 1 THEN
house = 0 : unit = 3 : cmd = 1 'when unit = 3 in code, set X10 receiver to 4
gosub sendcmd
ELSE
house = 0 : unit = 3 : cmd = 0 'when unit = 3 in code, set X10 receiver to 4
gosub sendcmd
ENDIF
Led = Is_Turned_Off
PAUSE 500 ' For LCD
IF a = 0 THEN MainLoop ' a always equals zero, use instead of GOTO...
' Firecracker Interface (Al Williams)
' http://www.awce.com/firecracker.htm or http://www.al-williams.com/awce
sendcmd:
byt=h1
gosub sendbyte
byt=h2
gosub sendbyte
read housetbl+house,byt
if unit<9 then lowunit
byt=byt+4
lowunit:
gosub sendbyte
byt=$20
if cmd=0 then addunit
byt=0
if cmd=1 then addunit
byt=$88
if cmd=2 then nounit
byt=$98
if cmd=3 then nounit
' huh???
addunit:
read unittbl+(unit//8),tmp
byt=byt+tmp
nounit:
gosub sendbyte
byt=foot
gosub sendbyte
return
' Send 1 raw byte
sendbyte:
debug hex byt," "
for i=0 to 7
if (byt & $80) = $80 then xmit1
gosub send0
nextbit:
pause 1
byt=byt*2
next
return
' Send a 1
xmit1:
gosub send1
IF a = 0 THEN nextbit
' Send bits (0 or 1)
send0:
low rts
pause 1
high rts
return
send1:
low dtr
pause 1
high dtr
return
'Reset firecracker first
resetfirecracker:
low rts
low dtr
pause 50
high rts
high dtr
pause 50
return
Turn_On_Or_Off_4:
if X = 0 then ' X toggles the #4 X10 module On/Off with each button press
X = 1 ' Turn On #5 X10 module
house = 0 : unit = 4 : cmd = 1 'when unit=4 in code,set X10 receiver to 5
gosub sendcmd : pause 1000
ELSE
X = 0 ' Turn Off #5 X10 module
house = 0 : unit = 4 : cmd = 0 'when unit=4 in code,set X10 receiver to 5
gosub sendcmd : pause 1000
ENDIF
' @ EE_write_var _X ' remember X in case of a power failure
RETURN
Turn_On_Or_Off_3:
if Y = 0 then ' Y toggles the #3 X10 module On/Off with each button press
Y = 1 ' Turn On #3 X10 module
house = 0 : unit = 2 : cmd = 1 'when unit=2 in code,set X10 receiver to 3
gosub sendcmd : pause 1000
ELSE
Y = 0 ' Turn Off #3 X10 module
house = 0 : unit = 2 : cmd = 0 'when unit=2 in code,set X10 receiver to 3
gosub sendcmd : pause 1000
ENDIF
' @ EE_write_var _Y ' remember Y in case of a power failure
RETURN
Turn_On_Or_Off_5:
if Z = 0 then ' Z toggles the #4 X10 module On/Off with each button press
Z = 1 ' Turn On #4 X10 module
house = 0 : unit = 3 : cmd = 1 'when unit=3 in code,set X10 receiver to 4
gosub sendcmd : pause 1000
ELSE
Z = 0 ' Turn Off #4 X10 module
house = 0 : unit = 3 : cmd = 0 'when unit=3 in code,set X10 receiver to 4
gosub sendcmd : pause 1000
ENDIF
' @ EE_write_var _Z ' remember Z in case of a power failure
RETURN
MainLoop:
IF Button_5 = Is_Pressed THEN
Timer = 0
WHILE Button_5 = Is_Pressed
Led = Is_Turned_On
Timer = Timer + 1
IF Timer = 4 THEN Timer = 1
lcdout $fe, 1, "Release Sw When ? #",DEC Timer
LCDOut $fe, $c0, "If # = 1 then X10-3 "
lcdout $fe,$94, "If # = 2 then X10-4 "
lcdout $fe,$d4,"If # = 3 then X10-5 "
PAUSE 1000
WEND
Led = Is_Turned_Off
PAUSE 100 ' Debounce Push Button
IF Timer = 1 THEN GOSUB Turn_On_Or_Off_3
IF Timer = 2 THEN GOSUB Turn_On_Or_Off_4
IF Timer = 3 THEN GOSUB Turn_On_Or_Off_5
ENDIF
LCDOut $fe, 1, "X10 FireCracker Demo"
LCDOut $fe, $c0," Jessey Montgomery "
lcdout $fe,$94,"#3 = ",DEC Y, _
" #4 = ",DEC X," #5 = ",DEC Z
Pause 100
IF a = 0 THEN MainLoop ' a always equals zero, use instead of GOTO...
End