Hi, you need to do some decimal to binary conversion
D= Bin
0= 0000 all PORT pins set to 0
1= 0001 only PORT.0 is set
2= 0010 only PORT.1 is set
3= 0011 PORT.0 and PORT.1 are set
4= 0100
5= 0101
6= 0110
7= 0111
8= 1000
and so on
Hi, you need to do some decimal to binary conversion
D= Bin
0= 0000 all PORT pins set to 0
1= 0001 only PORT.0 is set
2= 0010 only PORT.1 is set
3= 0011 PORT.0 and PORT.1 are set
4= 0100
5= 0101
6= 0110
7= 0111
8= 1000
and so on
OK Guys Let's just pretend I am a dummy, I think we can all do that.
I get the binary value of each pin, 00000001 = pin 0 = 1 and 00000010 pin 1 = 1 and so on. I get that the code "FOR led = 0 to 7 "makes it count 0 to seven, What statement in this code makes it not count only on pin 0 where it starts and makes it go pin to pin. I am using a FOR NEXT statement in one of my own programs to flash some LEDs a given amount of counts and it stays on the pin I told it to, so my question is " Exactly which statement makes this code select pins instead of flashing only 1 pin"? This code is so short and sweet as to be elegant, but it has outsmarted me, for the time being anyway.
Anyway, Thank you all for the help, and if you are, jumping up and down hollering "You Idiot" ...Ok I'm good with that, DEIDIOFY ME!
HMMMMM Dangerous . .
I think it it the [LED] call to the variable, I took it out of the second section of the code and addad a pause and now it swweps in only 1 direction and flashes 8 times port 0 then cycles all over again.
JS
Joe -
The author is using a different method for telling the micro which pin to turn on or off. He's using an array. With this method you can minimize the amount of code needed, and hence the cleaner, tidier code. Let's walk through it with some more comments.
Now look at Sayzer's post and it should make much more sense.Code:LED var Byte 'LED variable setup as byte PortB = %00000000 'Initiate all port B pins to low Trisb = %00000000 'Setup port b as all outputs main: 'Label for beginning of main loop ' *********** Light LEDs in right direction for led = 0 to 7 'Loop through all LEDs This variable not only counts up, but also indicates which pin should turn on or off. portB.0[LED] = 1 'Set each pin of portb high (5 volts) which turns the LED on The first time through the loop, LED = 0. So the statement PORTB.0[LED] = 1 is the same as writing portB.0 = 1. The next time through the loop, LED will = 1, which is the same as writing portB.1 = 1 and so on. Think of it as turn on PORTB.0 + the value in the LED variable. pause 1000 'Pause 1000 milliseconds (1 second) with LED on
Last edited by rhino; - 24th August 2006 at 00:31.
Wisdom is knowing what path to take next... Integrity is taking it.
Ryan Miller
So thats how an array works !
Melanie gripes about people not taking classes, but here in the states you try to go to class and they start you out learning how to solder, regardless of your experience, so 5 years later you do not remember why you started to class, and still never got to programming PICs, and thats OK if your 20, not if your 50, and yes Melanie, I am enrolled in school, I do buy the books, I talk a little too much Smack, and apoligize for my seemingly condecending tone, it's not intended . .
I am much too impressed with her Brains and Wit, anyway I'll hit the books some more, so my posts are more meaningful. Soooo THANK YOU ALL who posted and helped me understand, sorry if I bored you
JS
You know something.... I tried to find in the PBP manual where it explains this functionality, but couldn't find it. I'm sure it's buried in there somewhere, but I didn't see it. I was planning on adding what the manual said to my post. The only reason I knew of this method was from reading up on this forum. Believe me, I know it can get frustrating sometimes trying to make something work or understanding what's under the hood, but with this forum and the manual.... you're sitting on a gold mine of knowledge. Can't think of too many things that other people haven't asked or answered here before. What's cool about the forum are the guru's that expose either the undocumented features of the compiler or add functionality to it by publishing include files. It really is a great resource to have at your finger tips.
Wisdom is knowing what path to take next... Integrity is taking it.
Ryan Miller
Bookmarks