pic16f877a code

Discussion in 'Programmer's Corner' started by lina889, Nov 9, 2010.

  1. lina889

    Thread Starter New Member

    Oct 4, 2010
    11
    0
    Hi all ,,
    I have a problem through executing this program that there is no error but no output that I can get this is the circuit and the program I want the led to be on when I press the switch anyone can help
    This is the code

    program sensor_test
    main :
    TRISB=00000011
    PORTB=0
    while true
    if PORTB.0=1
    then
    PORTB.2=1
    else if PORTB.1=0
    then
    PORTB.3=1
    end if
    end if
    wend
    end.

    i have the schismatic for this in Proteus but i don't know how to upload it
     
  2. lina889

    Thread Starter New Member

    Oct 4, 2010
    11
    0
  3. Robin Mitchell

    Well-Known Member

    Oct 25, 2009
    732
    200
    hey! You cant bump posts :p
     
  4. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    What compiler are you using?

    Can you step through the code in the IDE?
     
  5. yehdev_cc

    New Member

    Jul 25, 2010
    23
    0
    the (supposed) schematic picture doesn't show ...
    whatsoever, here are general notes:
    1) you should disable LVP before you're able to use portb (pin3 if my memory doesn't fail me).
    2)'00000011' => are you sure this is the proper way to write binary numbers ?
    for tris, if a pin corresponding bit is '0', then it's output, if it's '1', it's input.
    so, if you want to read pin 0, then its corresponding bit should be 0. so is for pin 2, its bit should be 0.
    you need to re-write your code taking these notes into consideration.
     
  6. lina889

    Thread Starter New Member

    Oct 4, 2010
    11
    0
    am using micro basic for microchip PIC MCUs i also have micro basic v3.20
    this is my code on the first program

    sensor_test
    main :
    TRISB=%00000011
    PORTB=0
    while true
    if PORTB.0=1
    then
    PORTB.2=1
    else if PORTB.1=0
    then
    PORTB.3=1
    end if
    end if
    wend
    end.

    and this is my protues
    i want it if the pinB.0=1 then the pinB.2=1 and the led ON the same for pinB.1=1 the pinB.3=1 and the led ON
     
  7. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi,
    It's something like:
    Code ( (Unknown Language)):
    1.  
    2. program something
    3. main:
    4.    TRISB=%00000011
    5.    PORTB=0
    6.    while true
    7.       if PORTB.B0=1 then
    8.          PORTB.B2=1
    9.       else
    10.          PORTB.B2=0
    11.       end if
    12.       if PORTB.B1=1 then
    13.          PORTB.B3=1
    14.       else
    15.          PORTB.B3=0
    16.       end if
    17.    wend
    18. end.
    You should have pull-downs in RB0 and RB2.

    Hope this helps.
    Tahmnid.
     
  8. gerty

    AAC Fanatic!

    Aug 30, 2007
    1,153
    304
    Values for r1-r2 are too high (10k) they should be much lower.
    Without knowing the specs on the leds I can't say for sure what value you
    need, but I would try 460Ω to 510Ω for starters.
     
Loading...