How do I get DATA @ to work with a 18F452?


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    jessey's Avatar
    jessey Guest

    Default How do I get DATA @ to work with a 18F452?

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.

    Code:
        '
        '    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Thanks Steve

    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
    Attached Files Attached Files

  4. #4
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default still searching

    Quote Originally Posted by mister_e
    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.

    Code:
        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

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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/show...ghlight=EE_var

    There's also another way to do it
    Code:
    data           @0, $12,$34,$56,$78
    data           word $abcd
    data           word $A1B2
    This will load your EEPROM like this
    Code:
     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
    Last edited by mister_e; - 2nd February 2006 at 04:26.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by jessey; - 2nd February 2006 at 04:19.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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/show...6&postcount=18
    Last edited by mister_e; - 2nd February 2006 at 04:40.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Char. LCD and 18F452 on 20 MHz not work
    By samettin in forum General
    Replies: 11
    Last Post: - 28th July 2008, 09:59
  2. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  3. Internal EEPROM Read/write Addressing Errors with 18F PIC's
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 18
    Last Post: - 12th July 2005, 19:42
  4. help
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th February 2005, 20:42
  5. Need once your help one please
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 9th February 2005, 20:33

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts