Hello Anand,
Thanks for the links, I've had some time now to ponder over the firecracker stamp code and have some questions if anyone can help me. I've never had any experience using the Stamp so it'll definitely be a learning experience for me. I ordered a firecracker and expect to have it in a week or so. It sure would be nice to be able to get rid of all the reed relays and transistors that I'm using now on my modified X10 remote control.
I've checked the archives for any conversion tips for converting Stamp code to PBP and I did manage to find someone quoting that there are no NIB's in PBP so I changed all the NIB's to BYTE variables as the thread recommended.
I also found that the stamp code didn't declare the port pins for the push buttons so I declared them as well. Another thing I did was to change the rts & dtr from CON statements to declaring them as port variables to enable setting them high and low in the PBP code for the transmitter (firecracker) and I'm also assuming that all I have to do for the ground of the transmitter is to tie it to the VSS of my 16F877.
What I don't understand is that when I try to compile the code I get 3 errors:
"error.macro and?bbl not found in macro file", is this some sort of an include file that I'm missing or something that I have to add or declare somewhere?
Also I get two bad expressions, one for "READ housetbl+house,byt" and the other for "READ unittbl+(unit//8),tmp", is there a conversion for these two that will work for PBP? Could it be that the Data statement is wrong for PBP and possibly it needs an @ sign in there?
Any help in understanding this code will be greatly appreciated.
Thanks
jessey
Code:
'************************************************************
'* Name : FIRECRACKER.BAS *
'* Author : Jessey Montgomery *
'* Date : Feb. 2nd, 2008 *
'* Version : PBP ver 2.45, MicroCode Studio 2.1.0.7 *
'* : MPASM v03.60, EPIC Version 2.46 beta *
'* : 16F877 *
'* Notes : *
'* : *
'************************************************************
' --------------
' | 16F877 |
' MCLR/Vpp ------> |1 40| <-----> RB7/PGD
' RA0/AN0 <-----> |2 39| <-----> RB6/PGC
' RA1/AN1 <-----> |3 38| <-----> RB5
' RA2/AN2/Vref- <-----> |4 37| <-----> RB4
' RA3/AN3/Vref+ <-----> |5 36| <-----> RB3/PGM
' RA4/TOCK1 <-----> |6 35| <-----> RB2
' RA5/AN4/SS <-----> |7 34| <-----> RB1
' RE0/RD/AN5 <-----> |8 33| <-----> RB0/INT0
' RE1/WR/AN6 <-----> |9 32| <----- Vdd +
' RE2/CS/AN7 <-----> |10 31| <----- Vss -
' + Vdd -----> |11 30| <-----> RD7/PSP7
' _ VSS -----> |12 29| <-----> RD6/PSP6
' OSC/CLKIN -----> |13 28| <-----> RD5/PSP5
' OSC2/CLKOUT <------ |14 27| <-----> RD4/PSP4
' RC0/T1OSO/TICK1 <-----> |15 26| <-----> RC7/RX/DT
' RC1/T1OSI/CCP2 <-----> |16 25| <-----> RC6/TX/CK
' RC2/CPP1 <-----> |17 24| <-----> RC5/SDO
' RC3/SCK/SCL <-----> |18 23| <-----> RC4/SD1/SDA
' RD0/PSP0 <-----> |19 22| <-----> RD3/PSP3
' RD1/PSP1 <-----> |20 21| <-----> RD2/PSP2
' --------------
'-----------------------------------------'
'-- Clear All The Variables And Each Port '
'-- Before Setting The TRIS Registers '
'-----------------------------------------'
Clear ' Set all ram registers to zero
PORTA = 0
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0
'-----------VSS VDD MCLR Ect. Pins -----------'
' MCLR (Pin 1)
' VDD (Pin 11)
' VSS (Pin 12)
' OSC/CLKIN (Pin 13)
' OSC2/CLKOUT (Pin 14)
' VSS (Pin 31)
' Vdd (Pin 32)
'-----------SET THE TRIS PINS BEING USED-----------'
'-------------------- PORTA PINS --------------------'
TRISA.0 = 1 '(pin 2) NOT USED
TRISA.1 = 1 '(pin 3) NOT USED
TRISA.2 = 1 '(pin 4) NOT USED
TRISA.3 = 1 '(pin 5) NOT USED
TRISA.4 = 1 '(pin 6) NOT USED
TRISA.5 = 1 '(pin 7) NOT USED
'-------------------- PORTB PINS --------------------'
TRISB.0 = 1 '(pin 33) NOT USED
TRISB.1 = 1 '(pin 34) NOT USED
TRISB.2 = 1 '(pin 35) NOT USED
TRISB.3 = 1 '(pin 36) NOT USED
TRISB.4 = 1 '(pin 37) NOT USED
TRISB.5 = 1 '(pin 38) NOT USED
TRISB.6 = 1 '(pin 39) NOT USED
TRISB.7 = 1 '(pin 40) NOT USED
'-------------------- PORTC PINS --------------------'
TRISC.0 = 1 '(pin 15) NOT USED
TRISC.1 = 1 '(pin 16) NOT USED
TRISC.2 = 1 '(pin 17) NOT USED
TRISC.3 = 1 '(pin 18) NOT USED
TRISC.4 = 1 '(pin 23) .......Pushbutton or input from LabXT
TRISC.5 = 1 '(pin 24) .......Pushbutton or input from LabXT
TRISC.6 = 1 '(pin 25) .......Pushbutton or input from LabXT
TRISC.7 = 1 '(pin 26) .......Pushbutton or input from LabXT
'-------------------- PORTD PINS --------------------'
TRISD.0 = 0 '(pin 19) ........used to power the firecracker
TRISD.1 = 0 '(pin 20) ........used to power the firecracker
TRISD.2 = 1 '(pin 21) NOT USED
TRISD.3 = 1 '(pin 22) NOT USED
TRISD.4 = 1 '(pin 27) NOT USED
TRISD.5 = 1 '(pin 28) NOT USED
TRISD.6 = 1 '(pin 29) NOT USED
TRISD.7 = 1 '(pin 30) NOT USED
'-------------------- PORTE PINS --------------------'
TRISE.0 = 1 '(pin 8) NOT USED
TRISE.1 = 1 '(pin 9) NOT USED
TRISE.2 = 1 '(pin 10) NOT USED
DEFINE OSC 4 ' 4MHz crystal
@ __CONFIG _HS_OSC &_BODEN_OFF &_PWRTE_ON &_WDT_ON &_CP_OFF
&_LVP_OFF
' turn off the Crossing page boundary warnings
@ errorlevel -306
ADCON1 = 7 ' Set PORTA and PORTE to digital
' This is a link to the orginal code below,
' http://www.awce.com/firecracker.htm
' Define Variables Here
' ---------------------
' byte to send
byt var byte
tmp var byte
i var BYTE 'was a nib
x 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
'these push buttons weren't declared
in11 VAR PORTC.4 ' (pin 23)..Pushbutton or input from LabXT
in10 VAR PORTC.5 ' (pin 24)..Pushbutton or input from LabXT
in9 VAR PORTC.6 ' (pin 25)..Pushbutton or input from LabXT
in8 VAR PORTC.7 ' (pin 26)..Pushbutton or input from LabXT
' Firecracker Interface (Al Williams)
' http://www.al-williams.com/awce
' Wire Ground (DB9 pin 5)
' DTR (DB9 pin 4)
' RTS (DB9 pin 7)
'rts con 1
'dtr con 0
rts VAR PORTD.0 ' pin 19
dtr VAR PORTD.1 ' pin 20
' The Firecracker header (2 bytes)
h1 con $D5
h2 con $AA
' the Firecracker footer (1 byte)
foot con $AD
gosub resetfirecracker
' Sample program
main:
' all off
for x=0 to 3
house=0
unit=x
cmd=0
gosub sendcmd
pause 20
state(x)=0
next
mainloop:
if in11=0 then c0 ' look for buttons on p8-11
if in10=0 then c1
if in9=0 then c2
if in8=0 then c3
goto mainloop
c0:
x=0
goto ccmd
c1:
x=1
goto ccmd
c2:
x=2
goto ccmd
c3:
x=3
ccmd:
unit=x
cmd=state(x)+1
if cmd=1 then gocmd
cmd=0
gocmd:
gosub sendcmd
pause 250
state(x)=cmd
goto mainloop
' End of example program
' Send command
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
goto nextbit
' Send bits (0 or 1)
send0:
low rts
pause 1
high rts
return
send1:
low dtr
pause 1
high dtr
return
' Always reset firecracker first
resetfirecracker:
low rts
low dtr
pause 50 ' reset
high rts
high dtr
pause 50
return
' Data for house and unit codes
' should there be an @ somewhere below for pbp?
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
Bookmarks