PDA

View Full Version : Where is the problem?



SuB-ZeRo
- 20th June 2005, 22:31
I was trying to use internal eeprom of the pic 16F628.My experiment is trying to write values of a counter.When i remove the battery i want to see the last value of the counter.But always give me something difrent.Here re my codes

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
LCDOut $Fe,1
LCDOut "counter"
LCDOut $Fe,$C0
LCDOut "total="
time VAR BYTE
time =0
counter VAR WORD
counter =0
LCDOut $Fe,1
LCDOut "Counting"
LCDOut $Fe,$C0
LCDOut "total=",#counter
loop:
Pause 2000
counter=counter + 1
time =time +1
IF time=10 Then GoTo total_show
LCDOut $Fe,1
LCDOut "Counter"
LCDOut $Fe,$C0
LCDOut "total=",#counter
Write 10,counter
GoTo loop
total_show:
Read 10,counter
LCDOut $Fe,1
LCDOut "Counter"
LCDOut $Fe,$C0
LCDOut "total=",#counter
time=0
GoTo loop
End
'''''''''''''''''''''''''''''''''''''''''
Each 10 seconds LCD shows the total but when i remove the battery and start pic again , i can't see the total :( i always see another numbers.

Sharky
- 20th June 2005, 23:25
Hi SuB-ZeRo,

I'm a beginner to PBP but I think that you are trying to write a WORD into a BYTE.
If I look in the PBP manuel under WRITE there is this example:

w var word
WRITE 0,w.BYTE0
WRITE 1,w.BYTE1

Regards
Gert K.

mister_e
- 20th June 2005, 23:50
look at this part located at the top


time VAR BYTE
time =0
counter VAR WORD
counter =0


replace your counter=0 by read 10, counter

SuB-ZeRo
- 21st June 2005, 02:52
Yes i change the codes and now i can write to eeprom.The new problem is counting can't go more than 255 whats the problem?

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
sayac var word
b1 var byte
sayac =0
lcd_goster:
read 5,sayac
lcdout $Fe,1
Lcdout "sayac"
LCDOut $Fe,$C0
lcdout "total=",#sayac
loop:
button porta.4 ,0,0,0,b1,1,ok
goto loop:
ok:
data @5,0
read 5,sayac
sayac=sayac+1
write 5,sayac
goto lcd_goster
end

mister_e
- 21st June 2005, 03:34
i'm not sure on how PBP handle WRITE when using a WORD sized var but i think Sharky was right on his previous post.

SO what about using something like...



MyVar var word
AnotherVar var word

myvar=12345

Write 0,Myvar.highbyte
write 1,myvar.lowbyte
' code
' code
' code
' code
Read 0,anothervar.highbyte
read 1,anothervar.lowbyte

SuB-ZeRo
- 21st June 2005, 05:20
Ok! I resolved the problem by u re suggests.Here re the working codes.
I am always wrting the codes coz if somebody has or will the same problem they can find the way how to resolve by working codes :)

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
sayac var word
sayac=0
sayac_goster var word
sayac_goster = 0
b1 var byte
lcd_goster:
read 5,sayac_goster.highbyte
read 6,sayac_goster.lowbyte
lcdout $Fe,1
Lcdout "sayac"
LCDOut $Fe,$C0
lcdout "total=",#sayac_goster
loop:
button porta.4 ,0,0,0,b1,1,ok
goto loop:
ok:
data @5,0
data @6,0
read 5,sayac_goster.highbyte
read 6,sayac_goster.lowbyte
sayac_goster = sayac_goster + 1
sayac=sayac_goster
write 5,sayac.highbyte
write 6,sayac.lowbyte
goto lcd_goster
end