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.

adding some flair to my LCD program

Status
Not open for further replies.

MrDEB

Well-Known Member
conducting a basic electronics merit badge class this Saturday, 3/13/10 and now that I have my PIC /LCD working I though about adding some knight rider lights"leds"
Just to get the scouts appetite wet for PICs.
Plus the LEDs would better example of the add on circuit of the toy organ I designed and made 12 pcboards. Its just a 555 with pushbuttons to change the frequencies fed to a speaker. An additional circuit would be to add 2- 4017's to the output (divide by 10 then drive 6 LEDs.
Well I started hashing out a simple code but not real proficient in programing yet!
The code hangs up on the TOGGLE portA.x
X defines which port is on then instead of DEC X plan to INCREMENT X for back and forth
I have pins 2 - 9 with a ribbon cable soldered to them for connection to my breadboard w/ LEDs and a 330 resistor
Code:
Device = 18F452
Clock = 10

// alias to port pin...
Dim porta(5) As Word
Dim x(3)As Word 
//porta

While True
// main program.
 
x=4
High porta.x

DelayMS(500
Toggle porta.x
dec x
 If x = 4 Then repeat 

  // Toggle (LED)
   //DelayMS (500)

//if x>4 then x = 0
//next
 
will try that but I have looked at some examples and they just have an end or wend
 
Right, but I didn't see that in your program either. What compiler are you using?

Other things I noticed off the bat:
1. Missing ending parenthesis on the DelayMS(500 line.
2. Reference to "repeat". Is that a label that it's going to? I don't see the label.
 
starting over with new code BUT?

TRYING TO ADD MARCHING ledS TO MY lcd "hello world" PROGRAM
FIRST GET THE MARCHING LEDs to march
keep getting expected errors (I need to find out why my Swordfish compiler help does not have anything?)
using bits and pieces from other programs as examples here is what I have but getting syntax error on the LOW (led_A)
why? or is there a better way to do this?
Code:
Device = 18F452
Clock = 10

// alias to port pin...
Dim led_A As porta.0,
    led_B As porta.1,
    led_C As porta.2,
    led_D As porta.3,
    led_E As porta.4,
    led_F As porta.5,
//Dim PIN_A As Word,

LOW (LED_A)
low (LED_B)
low (LED_C)
low (LED_D)
low (LED_E)
low (LED_F)
 
It's a syntax error because it's in uppercase? Or because the pins are defined in lowercase and you're using them in uppercase? The comment lines (//...) tells me it's a C variant, and C is case-sensitive.
 
revised code w/ working syntax but won't execute

Code:
Device = 18F452
Clock = 10

// alias to port pin...
Dim ledx1 As PORTA.0,// define ports
    ledx2 As PORTA.1,  //******
    ledx3 As PORTA.2,  //*           *
    ledx4 As PORTA.3,  //**
    ledx5 As PORTA.4,  //*            *
    ledx6 As PORTA.5,  //****************
    ledx(6) As Byte
Dim pt As Word

      ledx(0)=ledx1 //DEFINE LED'S ports
      ledx(1)=ledx2
      ledx(2)=ledx3
      ledx(3)=ledx4
      ledx(4)=ledx5
      ledx(5)=ledx5
      pt=(0)
While (true)  // left to right leds

 ledx(pt)=1
 DelayMS(1000)
 ledx(pt) = 0
 pt=pt +1
 Repeat Until pt >5
Wend
While (true) //right to left leds
 ledx(pt)=1
 DelayMS(1000)
 ledx(pt) = 0
 pt=pt -1
 Repeat Until pt <0
Wend
 
The second WHILE will never execute. You've declared the first one to run forever and it never jumps out of it. Also, check the manual for the use of the REPEAT loop. It's not executing any statements...it'll just run forever.
 
got it going L to R but not backwards R to L

Thanks to Graham over at **broken link removed**

Code:
/ user definable port for LED's
Dim LED as PORTA
DIM LED_TRIS as TRISA
Dim i As Byte

LED_TRIS = $00             // make portb all outputs
LED = $00                  // set portb pins low

While True                 // main program loop
    For i = 0 To 7         // loop through each bit of LED port
        LED.Bits(i) = 1    // set high
        DelayMS(500)       // delay 500mS
        LED.Bits(i) = 0    // set low
    Next
    For i = 7 To 0
     LED.Bits(i) = 1    // set high
        DelayMS(500)       // delay 500mS
        LED.Bits(i) = 0    // set low
    Next
     
Wend
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top