Hi Jessey,
On the 16F688, RA3 is Input Only when MCLR is disabled.
The Pin needs to have output capability to talk to a DS1820.
hth,
Hi Jessey,
On the 16F688, RA3 is Input Only when MCLR is disabled.
The Pin needs to have output capability to talk to a DS1820.
hth,
DT
Hi Darrel,
I didn't realize that, thanks for the heads up. That might also explain why I couldn't get my FireCracker code to work on the 688 a while back.
Thanks Again
jessey
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
Yup, I think that's it too.
$2100 is the first physical address in EEPROM.
When you housetbl data $60, ..., it stores data at location 0. But it's really at 2100h.
So does EEPROM EE_Start, [0]
Both your program and EE_Vars are trying to define the same location in EEPROM.
If you open the EE_Vars.pbp file ...
The first line is ...
Change that to somewhere past the locations used for the existing data.Code:EE_start CON 0 ; Starting address for EE_Vars
Then they shouldn't conflict anymore.
Or you can comment that line, and copy it to your main program. That'll keep it from using the wrong location the next time you use the include file.
As for the firecracker not working.
All those EEPROM locations would have been overwritten by EE_Vars.
If they don't overlap, that won't happen.
<br>
DT
Hi Darrel,
I opened EE_Vars.PBP in MicroCodeStudio and changed the CON 0 TO CON 91 then saved the file and closed it. Then I compiled the firecracker code with the INCLUDE "EE_Vars.PBP" which compiled fine. I then programmed the code into the 688 and although the X, Y and Z variables are being saved when power is removed and re-applied to the circuit the firecracker code still isn't communicating with the firecracker transmitter and the X10 modules still won't turn On/Off?
Also, I tried commenting out the first line in EE_Vars.PBP then pasted it into my program with the starting address set to 91 as you suggested and when I try to compile I get an " ERROR Line 24: Redefinition of CON EE_start.(EE_Vars.PBP) ".
I'll try programming a new 688 micro tomorrow, could it be that my eeprom is corrupted now?
Thanks
jessey
Hi Darrel,
I tried programming a new chip with ee_vars.pbp and I got the same results as before but I got the firecracker code working good using the saving routines below:
EEPROMData91 var BYTE
X VAR EEPROMData91
READ 91, EEPROMData91
'' To write to the eprom
'' ================
'EEPROMData91 = X
'Write 91, EEPROMData91
'-----------------------
EEPROMData92 var BYTE
Y VAR EEPROMData92
READ 92, EEPROMData92
'' To write to the eprom
'' ================
'EEPROMData92 = Y
'Write 92, EEPROMData92
'-----------------------
EEPROMData93 var BYTE
Z VAR EEPROMData93
READ 93, EEPROMData93
'' To write to the eprom
'' =================
'EEPROMData93 = Z
'Write 93, EEPROMData93
''-----------------------
I tried changing the starting address in EE_Vars.pbp from CON 0 to CON 91 and although it compiles it doesn't work but when I comment out your eeprom saving routine and use the program below, the X10 code turns On and Off the X10 appliance modules and saving to the eeprom works like a charm.
As I mentioned in my previous post, when I comment out the con 0 in EE_Vars.pbp and include it in my program as con 91 I get " ERROR Line 24: Redefinition of CON EE_start.(EE_Vars.PBP) " when I try to compile.
It was only a guess on my part that the firecracker code was using some of the same address's as EE_Vars.PBP was using. I still don't quite understand mathematically how the address's of the various eeprom and other registry locations work using the Decimal, Hex and Binary number Systems. I should have stayed in school instead of being a juvenile delinquent then this would be a lot easier but I guess it's better late than never to get a little savy and this is interesting! Any ideas on what's happening with this?
Thanks
jessey
Code:'* Name : Test Program for the Firecracker Interface '* Author : Jessey Montgomery '* Includes: 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 Pins 'VDD + '(pin 1) 'VSS - '(pin 14) ' SET THE TRIS ' PORTA PINS TRISA.0 = 0 '(pin 13) Not Used VAR PORTA.0 TRISA.1 = 0 '(pin 12) ..........................................Led VAR PORTA.1 TRISA.2 = 1 '(pin 11) ..................................Push_Button VAR PORTA.2 TRISA.3 = 0 '(pin 4) Not Used VAR PORTA.3 TRISA.4 = 0 '(pin 3) .....connect to red wire of firecracker - dtr VAR PORTA.4 TRISA.5 = 0 '(pin 2) ...connect to green wire of firecracker - rts VAR PORTA.5 ' PORTC PINS TRISC.0 = 0 '(pin 10) Not Used VAR PORTC.0 TRISC.1 = 0 '(pin 9) Not Used VAR PORTC.1 TRISC.2 = 0 '(pin 8) Not Used VAR PORTC.2 TRISC.3 = 0 '(pin 7) Not Used VAR PORTC.3 TRISC.4 = 0 '(pin 6) Not Used VAR PORTC.4 TRISC.5 = 0 '(pin 5) Not Used VAR PORTC.5 '(2) PIC Config Fuse Definitions for 16f688 @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF & _BOD_ON @ ERRORLEVEL -306; '(3) PIC Hardware Definitions (ie Pin-Out & Port Assignments) ANSEL = 0 ' all pins are digital CMCON0 = 7 ' turn off comparators OSCCON.3 = 1 ' Use internal clock OSCCON = %1110111 ' Use Internal OSC at 8MHz Push_Button VAR PORTA.2 ' pin 11 Led var PORTA.1 ' pin 12 ' Firecracker Interface (Al Williams) rts VAR PORTA.5 ' pin 2 connects to DB9 pin 4 of the firecracker (green wire) dtr VAR PORTA.4 ' pin 3 connects to DB9 pin 7 of the firecracker (red wire) a VAR BYTE a = 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 h1 con $D5 h2 con $AA foot con $AD '4a. EEPROM Assignments ' ================== ' 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 EEPROMData91 var BYTE X VAR EEPROMData91 READ 91, EEPROMData91 '' To write to the eprom '' ===================== 'EEPROMData91 = X 'Write 91, EEPROMData91 '------------------------ EEPROMData92 var BYTE Y VAR EEPROMData92 READ 92, EEPROMData92 '' To write to the eprom '' ===================== 'EEPROMData92 = Y 'Write 92, EEPROMData92 '------------------------ EEPROMData93 var BYTE Z VAR EEPROMData93 READ 93, EEPROMData93 '' To write to the eprom '' ===================== 'EEPROMData93 = Z 'Write 93, EEPROMData93 ''------------------------- gosub resetfirecracker ' Reset the three X10 modules to the states they were before the power-loss IF X = 1 THEN house = 0 : unit = 4 : cmd = 1 'when unit = 4 in code, set X10 receiver to 5 gosub sendcmd : PAUSE 1000 ELSE house = 0 : unit = 4 : cmd = 0 gosub sendcmd : PAUSE 1000 ENDIF IF Y = 1 THEN house = 0 : unit = 2 : cmd = 1 'when unit = 2 in code, set X10 receiver to 3 gosub sendcmd : PAUSE 1000 ELSE house = 0 : unit = 2 : cmd = 0 gosub sendcmd : PAUSE 1000 ENDIF IF Z = 1 THEN house = 0 : unit = 3 : cmd = 1 'when unit = 3 in code, set X10 receiver to 4 gosub sendcmd : PAUSE 1000 ELSE house = 0 : unit = 3 : cmd = 0 gosub sendcmd : PAUSE 1000 ENDIF Led = Is_Turned_On PAUSE 200 Led = Is_Turned_Off IF a = 0 THEN MainLoop ' a always equals zero, use instead of GOTO... ' Start Of Subroutines Area Below ' =============================== ' Firecracker Interface by (Al Williams) ' http://www.awce.com/firecracker.htm 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 ' Always reset firecracker first resetfirecracker: low rts low dtr pause 50 ' reset high rts high dtr pause 50 return '============' Turn_On_Or_Off_4: if X = 0 then ' X toggles the #4 X10 module On/or/Off with each button press X = 1 ' Turn On house = 0 : unit = 4 : cmd = 1 'when unit=4 in code,set X10 receiver to 5 gosub sendcmd ELSE X = 0 ' Turn Off house = 0 : unit = 4 : cmd = 0 gosub sendcmd ENDIF EEPROMData91 = X Write 91, EEPROMData91 '@ EE_write_var _X RETURN Turn_On_Or_Off_3: if Y = 0 then ' Y toggles the #3 X10 module On/or/Off with each button press Y = 1 ' Turn On house = 0 : unit = 2 : cmd = 1 'when unit=2 in code,set X10 receiver to 3 gosub sendcmd ELSE Y = 0 ' Turn Off house = 0 : unit = 2 : cmd = 0 gosub sendcmd ENDIF EEPROMData92 = Y Write 92, EEPROMData92 '@ EE_write_var _Y RETURN Turn_On_Or_Off_5: if Z = 0 then ' Z toggles the #4 X10 module On/or/Off with each button press Z = 1 ' Turn On house = 0 : unit = 3 : cmd = 1 'when unit=3 in code,set X10 receiver to 4 gosub sendcmd ELSE Z = 0 ' Turn Off house = 0 : unit = 3 : cmd = 0 gosub sendcmd ENDIF EEPROMData93 = Z Write 93, EEPROMData93 '@ EE_write_var _Z RETURN 'XXXXXXXXXXX' MainLoop: IF Push_Button = Is_Pressed THEN Timer = 0 WHILE Push_Button = Is_Pressed Timer = Timer + 1 IF Timer = 1 THEN Led = Is_Turned_On IF Timer = 2 THEN Led = Is_Turned_Off IF Timer = 3 THEN Led = Is_Turned_On IF Timer = 4 THEN Led = Is_Turned_Off IF Timer = 5 THEN Led = Is_Turned_On IF Timer = 6 THEN Led = Is_Turned_Off PAUSE 500 WEND Led = Is_Turned_Off PAUSE 100 ' Debounce IF Timer = 1 THEN GOSUB Turn_On_Or_Off_3 IF Timer = 2 THEN GOSUB Turn_On_Or_Off_3 IF Timer = 3 THEN GOSUB Turn_On_Or_Off_4 IF Timer = 4 THEN GOSUB Turn_On_Or_Off_4 IF Timer = 5 THEN GOSUB Turn_On_Or_Off_5 IF Timer >= 6 THEN GOSUB Turn_On_Or_Off_5 ENDIF IF a = 0 THEN MainLoop End
Well, since brittons (in the EE_vars thread) appeared to have a similar problem changing the EE_start location ... I figured I better take another look.
So I did.
I've checked it starting at the default 0 location in EEPROM, and changed EE_start to several other values, and added DATA statements to duplicate your situation ... all with the same results.
I does exactly what it's supposed to do. The EE_var locations move to the appropriate places and everything works fine.
I don't have a Firecracker, so can't test that part.
The only thing I can see in your code, is that you've set the internal oscillator to 8Mhz, but didn't put a DEFINE OSC 8 in there. PBP will default to 4Mhz and all those pauses will only be half as long.
That doesn't explain ANY of the described problems, but it needs to be fixed before you'll be able to see the REAL problem.
<br>
DT
Thanks Darrel,
I did notice that the pauses weren't quite right and after adding the define it works good now. I still couldn't get the EE_vars to work, what starting address did you use in your test code?
Regards
jessey
Bookmarks