PDA

View Full Version : help with write command



cphillips82
- 20th April 2008, 14:47
Hi everyone, Kind of new at this and I'm pulling my hair out. Here's the code I'm having trouble with
dtempset:
lcdout 254,1, "set Daytime Temp"
dtempset2:
lcdout 254,192, dec2 temp," Celsius"
if up = 1 then
temp = temp + 1
if temp > 45 then
temp = 45
endif
endif

if down = 1 then
temp = temp - 1
if temp < 1 then
temp = 1
endif
endif
pause 100

if enter = 1 then
write 13,temp
pause 20
gosub check
goto ntempset
endif
goto dtempset2

ntempset:
lcdout 254,1, "set Night Temp"
ntempset2:
lcdout 254,192, dec2 temp," Celcius"
if up = 1 then
temp = temp + 1
if temp > 45 then
temp = 45
endif
endif

if down = 1 then
temp = temp - 1
if temp < 1 then
temp = 1
endif
endif
pause 100

if enter = 1 then
write 14,temp
pause 20
gosub check:
goto dtempset
endif
goto dtempset2

check:
read 13,test
pause 20
read 14, test2
lcdout 254,1, dec test," ",dec test2
pause 5000
return

it seems that the value keeps being pushed into address 13 and over and not into 14???? I'm going crazy!

Acetronics2
- 20th April 2008, 14:55
Hi,

Could your processor be a 18F ???

Alain

mister_e
- 20th April 2008, 14:55
I have no hair to lost so maybe i could help. Can you post your whole code, PIC model, OSC speed here.

OH, please when you post a code use code tags



paste your code here


this make it easier to read.

Maybe temp is a WORD variable?
<hr>
not sure how this would behave..

gosub check:
Never tested it but i see no reason to have colon here.. maybe Skimask see of some ;)

cphillips82
- 20th April 2008, 15:09
pic is a 16f628a 4meg crystal. whole program is very long and messy nearly up to 1600 bytes so I'm not sure if its a good idea to post. if I use an eeprom 13,[??,??] at they start it works fine but i just cannot put temp into 13 and 14. temp is also a byte

mister_e
- 20th April 2008, 15:13
Any interrupt in your code somewhere?

Which version of the compiler?

paste your first code lines... those before the main.

cphillips82
- 20th April 2008, 15:17
eeprom 1,[31,28,31,30,31,30,31,31,30,31,30,31] ' month days lookup

' Set LCD DATA Port
'---------------------------------------------------------------
Define LCD_DREG PORTB
'Set starting data bit
Define LCD_DBIT 4 'rb4,rb5,rb6,rb7
'Set LCD RS Port
DEFINE LCD_RSREG portb
'Set LCD RS Bit
define LCD_RSBIT 3
'Set LCD Enable Port
Define LCD_EREG portb
'Set LCD Enable Bit
Define LCD_EBIT 2
'Set number of LCD Lines
Define LCD_LINES 2
'Set Command Delay time in uS
define LCD_COMMANUS 2000
'Set Data delay time in uS
define LCD_DATAUS 50
test var byte
test2 var byte
'--------------------------ds1820setup-------------------------------
DQ VAR PORTa.4 ' One-wire data pin
temperature VAR WORD ' Temperature storage
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C
'-----------------------------thermostat -----------------------------------
symbol heatmat = porta.3
target var word
heatlevel var word
halfsec var byte
heatlevelx var byte
locate var byte
target = 30
halfsec = 1
locate = 13
temp var byte
temp = 30
temp2 var byte
temp2 = 20
'------------------------------RTCsetup--------------------------------
DS_SCL VAR PORTB.0 ' I2C clock pin
DS_SDA VAR PORTB.1 ' I2C data pin
RTC CON %11010000 ' RTC device address (byte addressing)
' -------------- RTC definitions -----------------
SecReg CON $00 ' seconds address (00 - 59)' MSB of SecReg must be set to a 0 to enable RTC
MinReg CON $01 ' minutes address (00 - 59)
HourReg CON $02 ' hours address (01 - 12) or (00 - 23)
DayReg CON $03 ' day address (1 - 7)
DateReg CON $04 ' date address (01 - 28/29, 30, 31)
MonthReg CON $05 ' month address (01 - 12)
YearReg CON $06 ' year address (00 - 99)
ContReg CON $07 ' control register
RTCflag CON 0 ' RTC flag (location 0 of internal EEPROM)
RTCset VAR BIT ' bit to check if RTC has been set
cntrl CON %00010000 ' sets the SQW/OUT to 1Hz pulse, logic level low
'----------------symbols-------------------------
symbol up = porta.0
symbol down = porta.1 'three button interface
symbol enter = porta.2
'-----------decimal value variables for menu display---------------

second var byte
minute var byte
hour var byte
day var byte
month var byte
year var byte
monthx var byte
wday var byte
second = 0
minute = 0
hour = 12 'set 12.00 1/1/08
day = 1
month = 1
year = 08


'--------hex value variables for actual time display--------------

secondx var byte
minutex var byte
hourx var byte
dayx var byte
monthxx var byte
yearx var byte
tempx var byte '' important this one
wdayx var byte
wdayx = $1 'just in case need a value maybe rubbish
secondx = $00 ' " "

'---------------------other not sure----------------------
decx var byte ' A swap variable
''''''''''''''''''''housekeeping'''''''''''''''''' '''''
trisb = %00000000
trisa = %00000111
cmcon = 7 'switch off comparitor

cphillips82
- 20th April 2008, 15:24
v2.46. no interupts

mister_e
- 20th April 2008, 16:09
:D oh well...this what might happen when you copy/paste your code block... but omit a single Label change... i don't know why i haven't saw at first... anyways, the problem is in your ntempset2 section


if enter = 1 then
write 14,temp
pause 100
gosub check
goto dtempset
endif

goto ntempset2

was dtempset2 before... hence why it never write @ 14... funny huh?

cphillips82
- 20th April 2008, 23:25
must of looked over that 100 times, thankyou mister e

mister_e
- 20th April 2008, 23:49
i know the feeling... hence why the http://www.mister-e.org/Pics/MisterE_Big :D