Simple Array Demo


Results 1 to 6 of 6

Threaded View

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

    Default Simple Array Demo

    Hello,
    this little example just cycles through a 26 element array and displays it's value. I wrote it to
    teach myself array function, and with help from Jerson it works as expected. I am posting it here to assist noobies trying to grasp array function.
    Code:
    '****************************************************************
    '*  Name    : ARRAY DEMO.BAS                                    *
    '*  Author  : Joe S. with Thanks to Jerson in Bombay            *
    '*  Notice  : Copyright (c) Joe S.                              *
    '*          : No Rights Reserved, Use as you see fit            *
    '*  Date    : 5/21/08                                           *
    '*  Version : 1.0                                               *
    '*  Notes   :Demo Array Counter reads array 1 BYTE at a time    *
    '*           and displays serially on backpack LCD              *
    '*          :PBP VER 2.50                                       *
    'DEMONSTRATES USE OF FOR NEXT LOOP TO READ ARRAY                *                                   *
    'THIS PROGRAM PROVES SERIN AND SERIN2 WILL WORK ON THE SAME PIN *
    'WITHIN A SINGLE PROGRAM. DEMONSTRATES USE OF STR FUNCTION WITH *
    'SERIN2.COMPILE WITH MPASM ASSEMBLER.COMPILES TO 419 WORDS IN   *
    '16F628A                                                        *
    '****************************************************************
    @ __config  _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF  & _BODEN_OFF
    DEFINE OSC 20
    include "modedefs.bas"
    '    
    LETTERS VAR BYTE ' VARIABLE TO HOLD CHARACTERS IN F/N LOOP
    '
    CHAR var byte[26]' ARRAY VARIABLE NAMED CHAR 26 ELEMENTS
    '
    serout PortB.6,T9600,[254,128,"ARRAY DEMO"]   ' SHOW US YOU ARE ALIVE 
    '
    pause 500        ' TIME TO VIEW LCD SPLASH STATEMENT
    '
    serout PortB.6,T9600,[$FE,1]'CLEAR LCD PRIOR TO WRITING
    '
    '* * * * * * LOAD ARRAY WITH STRING VALUE
    CHAR[0]= "A"
    CHAR[1]= "B"
    CHAR[2]= "C"
    CHAR[3]= "D"
    CHAR[4]= "E"
    CHAR[5]= "F"
    CHAR[6]= "G"
    CHAR[7]= "H"
    CHAR[8]= "I"
    CHAR[9]= "J"
    CHAR[10]="K"
    CHAR[11]="L"
    CHAR[12]="M"
    CHAR[13]="N"
    CHAR[14]="O"
    CHAR[15]="P"
    CHAR[16]="Q"
    CHAR[17]="R"
    CHAR[18]="S"
    CHAR[19]="T"
    CHAR[20]="U"
    CHAR[21]="V"
    CHAR[22]="W"
    CHAR[23]="X"
    CHAR[24]="Y"
    CHAR[25]="Z"
    '* * * * * * * DISPLAY ARRAY ELEMENTS VALUES SEQUENTIALY
    loop:
         FOR LETTERS = 0 to 25 'CYCLE FROM A TO Z
    '
         serout PortB.6,T9600,[254,128,"CHAR is ",(CHAR[LETTERS])]
         pause 500            'TIME TO VIEW LETTER
    NEXT LETTERS
    
         FOR LETTERS=25 TO 0 STEP -1 'CYCLE  THEM IN REVERSE Z TO A
         serout PortB.6,T9600,[254,128,"CHAR is ",(CHAR[LETTERS])]
         PAUSE 500 ' TIME TO VIEW LETTERS
    NEXT LETTERS
    '
         PAUSE 500 'TIME TO VIEW LAST LETTER
    goto LOOP2
    '* * * * * * * * * * DISPLAY ENTIRE ARRAY VALUE AT ONCE
    LOOP2:
          serout2 portb.6,84,[$FE,1]     'CLEAR LCD PRIOR TO WRITING TO IT
    '
          PAUSE 50     'TIME FOR LCD TO SETTLE, DROPS 4 CHARS WITHOUT THIS
    '
          serout2 PortB.6,84,10,[str char\26]
    '     PACE 10 ALLOWS SEROUT2 TO QUICKLY WRITE ARRAY'S FULL VALUE TO LCD
    '
          pause 2000 ' TIME TO VIEW FULL ARRAY'S CONTENT
    '
          serout2 portb.6,84,100,[$FE,1] 'CLEAR LCD BEFORE LOOP
    goto loop
    '
    end
    I realise there are likely easier ways to load the ARRAY . . .Baby Steps
    Anyone wishing to post more or better examples of ARRAY functions are invited to do so on this post.
    Thank You,
    JS
    Last edited by Archangel; - 10th April 2011 at 03:16. Reason: make code more readable.
    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 : 1

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