Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

implermenting a CONST array

Status
Not open for further replies.

MrDEB

Well-Known Member
trying to figure out how to implement a CONST array as shown here.
Keep getting as syntax error.
Can't be all that hard but trying to find an example of an easy method?
Trying to control a 5x7 LED matrix and using a const arry looks like the easiest way as I need to use the same basic patterns over and over.
Then need to have the LEDs to LOOK like they are staying on (POV)
Code:
Device = 18f452
Clock = 20 // 20mhz clock
Include "Utils"
                    //  colum 7   colm 6      colm 5    colm 4   colm 3
Const colm(7) As Word =(%00000001, %00000010, %00000100, %00001000,  %00010000,
// colm 2    colm 1
%00100000,  %01000000 )
//                    row 3 on  row 2&4  rows 1&5
Const row(3) As Word =( %11011,  %10101,  %01110 )
Sub RightToLeft()
    Dim i As colm(2) Or bits.  
    For i = 0 To 4
        PORTB.Bits(i) = 1
        DelayMS(500)
        PORTB.Bits(i) = 0        
    Next
End Sub
[//cpde]
 
Are you going to give us a clue where the error is? My guess would be the comment splitting the line,
Code:
Const colm(7) As Word =(%00000001, %00000010, %00000100, %00001000, %00010000,
// colm 2 colm 1
%00100000, %01000000 )

Mike.
 
using swordfish compiler

sorry I didn't mention
I tried changing a few things around but still no avail. Using examples I found here and there but ?
 

Attachments

  • const arrays.PNG
    const arrays.PNG
    46.2 KB · Views: 179
using other codes as example

I got this code so I have no syntax errors but do I still need to put SetAllDigital in and did I set up portA and D correctly?
been just tinkering with code trying to understand what I have and did??
maybe not correct way but any suggestions on what I did or have wrong?
Code:
Device = 18f452
Clock = 20 // 20mhz clock
Include "Utils"
dim i as byte
dim x as byte
dim row_s as byte
dim rwos as portA
dim col as portD        // set up port D 
dim rwostris as portD   // clear port D


                    //  colum 7   colm 6      colm 5    colm 4   colm 3
Const colm(7) As Word =(%00000001, %00000010, %00000100, %00001000,  %00010000,
// colm 2    colm 1
%00100000,  %01000000 )
//                    row 3 on  row 2&4  rows 1&5
Const row(3) As Byte =( %11011,  %10101,  %01110 )
//Dim row_s As PORTA    // assign port A to row_s
//Dim colm_s As PORTD   // assign portD to colum
//setALLDigital ???????????????????? where to put

Sub RightToLeft()
    //Dim i As colm(6)   
    For i = 0 To 4
         col= colm(i)   // select colum 
       for x = 0 to 3
       row_s =row(x)    // select row
       DelayMS(500)
    next       
        Next
End Sub
End
[//code]
 
Try this it shows you on a lcd how it works don't change but your inosc.bas

Code:
///////////////////////////////////////////////////////////////////////////////
    Device = 18F1320           // Set to your chip
    Clock = 8 // 8MHz clock
    Config OSC = INTIO2, WDT = OFF, LVP = OFF, MCLRE = OFF
    #option LCD_DATA = PORTB.4         // you can use any 18F chip
    #option LCD_RS = PORTB.3           // just set whats in here to match your chip
    #option LCD_EN = PORTB.2
    ////////////////////////////////////////////////////////////////////////////////
    Include "IntOSC8.bas"
    Include "LCD.bas"
    Include "Utils"
    Include "convert.bas"

    
Const TestArray(8) As String = ("Maybe", "you", "want", "to ", "learn", "baisc", "I know ", "I do")
Dim i As Word
Dim Counter As Byte
Dim ArrayString As String(8)
ADCON1 = $07 // PORTB as digital (LCD)
i = 0
LCD.Cls
While True

    
   For i = 16 To 0 Step -8
       // DelayMS(250)
    For Counter = 0 To Bound(TestArray)
        ArrayString = TestArray(Counter)
        LCD.MoveCursor (1,i)
        LCD.Write(ArrayString)
        DelayMS(1000)
        LCD.Cls
    Next    
  Next


Wend

here one with numbers
Code:
 ///////////////////////////////////////////////////////////////////////////////
    Device = 18F1320           // Set to your chip
    Clock = 8 // 8MHz clock
    Config OSC = INTIO2, WDT = OFF, LVP = OFF, MCLRE = OFF
    #option LCD_DATA = PORTB.4         // you can use any 18F chip
    #option LCD_RS = PORTB.3           // just set whats in here to match your chip
    #option LCD_EN = PORTB.2
    ////////////////////////////////////////////////////////////////////////////////
    Include "IntOSC.bas"
    Include "LCD.bas"
    Include "Utils"
    Include "convert.bas"

    Const port_scan (9) As Byte = (0, 1, 2, 3, 4, 5, 6, 7, 8) //Constant arrays
         Dim Index As Byte        //holds value of the constant
    ADCON1 = $07 // PORTB as digital (LCD)
         
    While true
               Cls  // clears the lcd
              For Index = 0 To Bound(port_scan)   //Sends out the constant values
                    LCD.MoveCursor (1,1)    
                    LCD.Write ("Counter = ",DecToStr(Index) )  //shows you on the LCD
                  DelayMS (250)  // little delay to see the counter change
              Next
    Wend


The only thing you'll need to change is this
Code:
Include "IntOSC.bas"

Make it match what your using
 
Last edited:
Going to Missioula today so won't hae time to test BUT taking a printout to study on the way
Oh yea and I is driving --- lol
 
Status
Not open for further replies.

Latest threads

Back
Top