pic16f877a code

Thread Starter

lina889

Joined Oct 4, 2010
11
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
 

yehdev_cc

Joined Jul 25, 2010
23
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.
 

Thread Starter

lina889

Joined Oct 4, 2010
11
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.
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
 

Attachments

Tahmid

Joined Jul 2, 2008
343
Hi,
It's something like:
Rich (BB code):
program something
main:
   TRISB=%00000011
   PORTB=0
   while true
      if PORTB.B0=1 then
         PORTB.B2=1
      else
         PORTB.B2=0
      end if
      if PORTB.B1=1 then
         PORTB.B3=1
      else
         PORTB.B3=0
      end if
   wend
end.
You should have pull-downs in RB0 and RB2.

Hope this helps.
Tahmnid.
 

gerty

Joined Aug 30, 2007
1,305
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.
 
Top