PDA

View Full Version : LED var Byte



zmet68
- 16th February 2005, 16:56
LED var Byte 'LED variable setup as a byte. Can some one explain this to me i'm not sure what its there for or what it does? I know this is a dumb question but I need to know. after two weeks of reading the manual I just dont seem to be getting it.

Thanks

mister_e
- 16th February 2005, 18:01
O.K. i don't know if i can explain it as you wish but...

When you do your program, you need to use some variable. Depending how you work you may need 3 different type of them

BIT
BYTE
WORD

Bit is only 2 conditions: 1 or 0 : usually to test bit or set test flag
BYTE : 256 condition or items
WORD : 65536 conditions or items

By using LED VAR BYTE, you are able to store/read 256 different items to it. BYTE = 8 bits

LED is the name of the variable BYTE is it's size.



TRISB = 0 'Set PORTB as output on all pins
LED VAR BYTE

start:
FOR LED = 0 TO 255
PORTB=LED ' send content of LED var to PORTB
PAUSE 500 ' wait .5 sec
NEXT B
GOTO Start ' redo the loop


hope this help

PICMAN
- 16th February 2005, 22:52
its very simple, inorder to declare a varible,, you must know how large ( within reason) it will be , i believe steve already gave ya a technical explanition, so i wont go into which is for what amount etc
for an led, im pretty sure its on or off, so bit should work, but for instance,, lets say the varible is reading a rotation , if theres thousands of rotations, word would be used, all it is doing ,, is telling the chip how many variants there is, and how to store it, is the answer going to be between 0 and 1, 1 / 256 etc etc,,

keep in mind that not all pic's consider a word the same amount,, as per there total memory might not facilitate the standard value of word, but for the most part , bit and byte will remain standard,

i might even be able to provide some documentation which more clearly explains how this works, but i warn ya , theres alot of info, and unless your wiling to read it blind for a few weeks , it will just overwhelm ya,, but eventually it al catches up , feel free to pm me with some contact info, ill see if i cant hook ya up with some good docs

Dwayne
- 16th February 2005, 23:53
Hello Zmet,

Z>>LED var Byte 'LED variable setup as a byte. Can some one explain this to me i'm not sure what its there for or what it does? I know this is a dumb question but I need to know. after two weeks of reading the manual I just dont seem to be getting it.<<

Steve did a great job of explaining.

LED var Byte.

Do not confuse the Initials for a Light Emittiing Diode (LED) with the LED used here.

it could also read :

counter Var Byte
Recieve Var Byte
Transmit Var Byte
Or (as your example
LED var Byte.

The person who "chose" the letters LED for his variable, probably wanted something very simple to use, so that he will be able to read his program better.

LED var byte 'This variable (LED) will count the number of times this Porta.0 is high.

LED2 var byte 'this variable will count the number of times the Porta.1 is high.

LED=0;
LED2=0;

Loop:
if Porta.0=1 LED=LED+1 0 'is it on? add another to counter
if Porta.1=1 LED2=LED2+1 'is it on? add another to counter
if LED>10 then finish program
....
....
goto loop:
Finish program:

LCDout "Number of times first LED was on is", LED,"TIMES"
LCDout "Number of times second LED was on is",LED2,"Times"
end


This is PSUEDO code. but gives you a example of what a person can do.

Dwayne