PDA

View Full Version : How do I get DATA @ to work with a 18F452?



jessey
- 27th January 2006, 00:26
Hello Everyone,

I have a question if anyone can help, on how to use the Data statement for the 18F452. I want to be able to load default values for some of my variables that will be set when the chip is initially programmed but will only execute once when the program is run. I've been using a pushbutton to set (save) the variables in an IF...THEN statement after I finish programming a new code segment and when the program is first run which is easier than manually setting each one of them from an initial value of 255 but it still becomes a hassle after frequent re-programming. According to the manual I should be able to use, as an example:

DATA @11, 72

to store a value of 72 @ location 11 of my eeprom data byte but it doesn't work? Also what would the set-up be for my word variable MinutesSet? I have my word variables set-up as follows:

Hour VAR word
Minute VAR word

EEPROMData14 var word
MinutesSet VAR EEPROMData14 ' alias
Read 14, EEPROMData14.byte0 ' Load MinutesSet variable from EEPROM
Read 15, EEPROMData14.byte1

'do the math for our display here..................
Hour = MinutesSet / 60 : Minute = MinutesSet // 60

LCDOut $fe, 1, "Hi Temp On Time "
LCDOut $fe, $c0, "Hr = ",DEC Hour, " Min = ", DEC Minute

I'd like to use DATA to load a value of 45 minutes to display to my Lcd as a factory default setting for the MinutesSet variable. This set-up above works good to save using the READ & WRITE commands. But the DATA statements below don't work.

'DATA @14,45
'DATA @15,0

Can anyone suggest what I'm doing wrong here?

Thanks
jessey

mister_e
- 27th January 2006, 03:31
it must work AS IS but maybe your PIC programmer software is not set correctly.

Check for a PROGRAM EEPROM location or something like that.




'
' PIC Configuration
' =================
DEFINE LOADER_USED 1
DEFINE OSC 20

'
' Hardware configuration
' ======================
TRISC = %10111111

'
' Serial Communication definition
' ===============================
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 129 ' 9600 Bauds

'
' Variables definition
' ===================
ByteA var byte
ByteB var byte
ByteC var byte
WordA var word
WordB var Word
'
' Internal EEPROM assignement
' ===========================
DATA @10,10,20,30
DATA @60,$AB,$01,$CD,$02 ' Must split WORD sized in 2 BYtes
' '
' ''' addr = 62
'
''''''''''' addr = 60
'
' ////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
' Program Start Here
'
' ////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
START:
read 10,bytea
read 11,byteb
read 12,bytec
read 60,worda.highbyte
read 61,worda.lowbyte
read 62,wordb.highbyte
read 63,wordb.lowbyte
hserout ["ByteA:",dec bytea,13,10,_
"ByteB:",dec byteb,13,10,_
"ByteC:",dec bytec,13,10,_
"WordA:",hex Worda,13,10,_
"WordB:",hex WordB,13,10,_
rep "*"\50,13,10]
pause 1000
goto start

jessey
- 27th January 2006, 06:20
Hi Steve,

Thanks for your reply. Is the code segment (you make reference to) a test program to check the DATA @ statements? I'm not using a Serial Lcd, I'm using one of Melanie's 2 X 16 character Cool Blue Lcd's set up in a 4 bit mode. If I had a serial Lcd then I would try the code you have posted here but I have no idea what's happening in your code to be able to convert your HSEROUT to LCDOUT commands. I've never seen this code before:

REP "*"\50,13,10]

I looked up the REP command and it sets all kinds of parameters for the Lcd, spacing and such but it's beyond my scope of understanding.

Attached is the configuration of my fuse settings for my 18f452. I'm using PBP ver 2.45 with MicroCode Studio 2.1.0.7 and MPASM v03.50 and EPIC Version 2.46 beta programmer. In the epic programmer I set (selected) Flash Program Write Enable which I think I need? And set in my software, I have Power-up Timer Enable & Watchdog Timer Enable enabled. Maybe there's something off in my fuse configuration settings that should be on, that's quite possible because for a lot of those settings, I have no idea what they do (don't laugh). I'd appreiacate it if you could confirm that my fuses are set properly to be able to utilize the DATA @ command? I'm sure I don't have anything in the main part of my program that would cause the DATA @ statement not to work.

Thanks
jessey

jessey
- 2nd February 2006, 03:40
it must work AS IS but maybe your PIC programmer software is not set correctly.

Check for a PROGRAM EEPROM location or something like that.



DATA @10,10,20,30
DATA @60,$AB,$01,$CD,$02 ' Must split WORD sized in 2 BYtes


Hello Steve,

I didn't quite understand your explanation that it must be split WORD sized in 2 BYtes or how to do that for the particular word variables that I want to use in my DATA statements? If my DATA @ statements must work AS IS then why would the WORD sized variables have to be split into 2 bytes?

Also, which part of my programmer software are you making reference to that may not be set correctly? Would that have anything to do with the way I have my configuration fuse's set in my program?

I've been searching the archives (for many late nights now) and can't find anyone else that's had this problem with the DATA @ statements for the 18F452.

Any further help would be welcomed.

Thanks
jessey

mister_e
- 2nd February 2006, 03:56
I didn't quite understand your explanation that it must be split WORD sized in 2 BYtes or how to do that for the particular word variables that I want to use in my DATA statements? If my DATA @ statements must work AS IS then why would the WORD sized variables have to be split into 2 bytes?


It's just because, as far as i'm aware of, DATA statement don't accept the WORD sized data you enter in. I just re-check it, and if you use
DATA @0, $1234,$5678

The DATA will load $34 @0 and $78 @1. Just for that. You'll need to split your data like...
DATA @0,$12,$34,$56,$78

Now Read back the results to the var as i did in the previous example with .LowByte and HighByte.

There's also other way to do it Using MPASM statement and few assembler lines... up to you.

Darrel Did something interesting in the Code example section.
http://www.picbasic.co.uk/forum/showthread.php?t=2444&highlight=EE_var

There's also another way to do it


data @0, $12,$34,$56,$78
data word $abcd
data word $A1B2


This will load your EEPROM like this


Address 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ASCII

0000 12 34 56 78 CD AB B2 A1 FF FF FF FF FF FF FF FF .4Vx.... ........
0010 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
0020 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
0030 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
0040 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
0050 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
0060 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
0070 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
0080 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
0090 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
00A0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
00B0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
00C0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
00D0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
00E0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
00F0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........


But you still need to load you value with .LowByte and .HighByte

jessey
- 2nd February 2006, 04:16
Thanks Steve,

Yes I am just now trying Darrel's EE_Vars.pbp. Hopefully that will solve my problems.

What about using the DATA @ for my BYTE sized variables? I'd still like to understand what could be causing them not to work. Any idea why their not working as expected? Do you think it would have anything to with the way I have my configuration fuse's set in my program or what other settings that could possibly be causing it?

I'm using EPIC Version 2.46 beta programmer.

Thanks
jessey

mister_e
- 2nd February 2006, 04:37
Look the previous edited post.

For your Melabs programmer.. i can't say as i'm not using it... but i remind one post on this forum somewhere... maybe you already found it?
http://www.picbasic.co.uk/forum/showpost.php?p=10506&postcount=18

jessey
- 2nd February 2006, 04:49
Thanks Steve,

I'll read up on it, in the meantime I'll give Darrel's EE_Vars.pbp a try.

Many Thanks
jessey

jessey
- 2nd February 2006, 10:35
Hello Steve,

I just tried Darrel's "EE_Vars.pbp" and it fixed everything. The include file and routines work great on my 18F452. I couldn't believe how easy it was to set-up and implement. Thanks Darrel!! And thank you Steve for mentioning it.

http://www.picbasic.co.uk/forum/showthread.php?t=2444&highlight=EE_var

Thanks Again
jessey