LED var Byte


Closed Thread
Results 1 to 4 of 4

Thread: LED var Byte

  1. #1
    zmet68's Avatar
    zmet68 Guest

    Unhappy LED var Byte

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.

    Code:
    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    PICMAN's Avatar
    PICMAN Guest


    Did you find this post helpful? Yes | No

    Default quite posibly an easier way to thik about it

    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

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. LCD freeze
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th October 2009, 08:01
  3. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  4. large program oddity
    By lsteensl in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th April 2007, 06:28
  5. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 11:47

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