Simple Array Demo


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Array and external EEPROM Demo

    Still playing with and learning about arrays, mostly by trying to solve newbies problems. Here is a demo to write to and read from a 24LC01B I2C EEPROM using a 12F675. It outputs to a serial LCD.
    Code:
    ' I2CREAD and I2WRITE Commands with External EEPROM on 12-bit core
    '
    ' Write to the first 36 locations of External I2C EEPROM
    ' Read from eeprom and output sequentaly then as strings
    ' Tested on 12F675  using 24LC01B EEPROM
    @ __config _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _WDT_ON & _MCLRE_ON & _CP_OFF & _BODEN_OFF
    DEFINE OSC 4
     
    DEFINE DEBUG_REG	GPIO
    DEFINE DEBUG_BIT	2
    DEFINE DEBUGIN_BIT	5
    DEFINE DEBUG_BAUD	2400
    DEFINE DEBUG_MODE	0
    DEFINE SHIFT_PAUSEUS 1000
    
    EECON1   = 7  'Probably not needed here, enables internal eeprom
    CMCON    = 7  'Disable comparators
    ADCON0.0 = 0  'Disable A/D converters
    ANSEL    = 0  'Disables Analog Select
    DPIN var GPIO.0   'Assign Data pin
    CPIN var GPIO.1   'Assign Clock pin
                ' a nice place to store things
    B0 var byte
    B1 var byte
    B2 var byte
    B3 VAR BYTE
    
    GPIO   = 0 ' set port latches low
    TRISIO = 0 ' set ports as outputs
    
    pause 1000 ' Waste time while serial LCD initiailizes
    
    For B2 = 0 To 35   ' counter for lookup table
    lookup b2,["A","B","C","D","E","F","G","H","I","J","K","L","M",_
    "N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2",_
    "3","4","5","6","7","8","9"],B0 ' store each char in b0 1 at a time
    
    I2CWRITE DPIN,CPIN,$A0,B2,[ b0]  'write to 24C01 eeprom 1 character
    Pause 20
    Next B2       'next character write to eeprom
    DEBUG 254,1   'clear LCD of any leftover data
    loop:
    DEBUG 254,1   'clears away the leftovers each loop
    
    For B3 = 0 To 35   ' counter for reading 35 characters
    I2CREAD DPIN,CPIN,$A0,b3,[B1]  ' read each character 1 at a time
    pause 500           ' time to see each character on the LCD
    
    
    DEBUG 254,2,"CHAR ",B1,"          " ' display the characters 1 at a time
    '
    Next B3                             ' get next character
    
    I2CREAD DPIN,CPIN,$A0,0,[STR B1\20] ' read a string of  20 characters
    DEBUG 254,2,STR B1\20               ' display those 20 characters
    I2CREAD DPIN,CPIN,$A0,16,[STR B1\16]' get the last 16 characters
    DEBUG 254,$C0,STR B1\16,"    "      ' display those 16 characters
    DEBUG 254,$94,"I2C EEPROM DEMO"     ' display this program's purpose
    DEBUG 254,$D4,"USING ARRAY & STRING" 
    PAUSE 1500                          ' time to read the LCD
    'NEXT B3                            ' go do it all again
    Goto loop
    end
    POKECODE @$3FF, $4C  'read your PIC before erasing and put the cal. data here
    Last edited by Archangel; - 11th May 2009 at 22:43.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default A For-Next Loop

    Hi,

    "A,B,C..." all have an ASCII value. For example "A"=65 so an iteration like this can help

    Code:
    For I = 0 to 25
    char[I] = I + 65
    Next I
    P.S. PBP Manual has the ascii chart
    Attached Images Attached Images  
    Regards

    Sougata

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sougata View Post
    Hi,

    "A,B,C..." all have an ASCII value. For example "A"=65 so an iteration like this can help

    Code:
    For I = 0 to 25
    char[I] = I + 65
    Next I
    P.S. PBP Manual has the ascii chart
    As I look at this a year later, I now understand what this snippet does.
    "I realise there are likely easier ways to load the ARRAY . . .Baby Steps"
    It loads the variable CHAR with the Alphabet,<font color = BLUE> A Belated Thanks, Sougata .</font color>
    This response is to point that fact out to anyone new to arrays. Attention Newbies
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Joe,

    Did you know you can do this?

    Code:
    Dat VAR BYTE
    Alphabet VAR BYTE[26]
    
    Main:
        FOR Dat = "A" to "Z"
         Alphabet[Dat-65]=Dat ' load Alphabet array 0-25 with A-Z
         HSEROUT [Alphabet[Dat-65],13,10]
         PAUSE 50
        NEXT Dat
        PAUSE 5000
        GOTO Main
        
        END
    Last edited by Bruce; - 14th February 2010 at 18:56. Reason: Better example
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Nope !

    Quote Originally Posted by Bruce View Post
    Joe,

    Did you know you can do this?

    Code:
    Dat VAR BYTE
    Alphabet VAR BYTE[26]
    
    Main:
        FOR Dat = "A" to "Z"
         Alphabet[Dat-65]=Dat ' load Alphabet array 0-25 with A-Z
         HSEROUT [Alphabet[Dat-65],13,10]
         PAUSE 50
        NEXT Dat
        PAUSE 5000
        GOTO Main
        
        END
    Woo Hoo, another tidbit of knowledge! I did not know that.
    Thank You Bruce.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. 16f887 44 pin demo board code problem?
    By jessey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th December 2008, 14:17
  3. Schematic for simple demo
    By iandonahue in forum USB
    Replies: 7
    Last Post: - 4th March 2008, 15:18
  4. RS232 receive an array (packet)
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th February 2008, 05:02
  5. Array to simple Variable converting
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd September 2006, 16:44

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