Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic16f877a code and Proteus anyone can help

Status
Not open for further replies.

lina889

Member level 1
Joined
Aug 20, 2010
Messages
35
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
JORDAN
Activity points
1,557
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 they gave me a error File Proteus.bmp not allowed extension. :roll:
 

Hai,

Can you post your circuit.Please convert your file to pdf,then upload it.
 

this is the pic
 

Attachments

  • protues.pdf
    11.6 KB · Views: 148

Hi,
I read this as something written in mikroBASIC, am I right?
Code:
program sensor_test
main :
   TRISB=%00000011
   PORTB=0
   while true
      if PORTB.B0=1 then
         PORTB.B2=1
      else
        if PORTB.B1=0 then
         PORTB.B3=1
        end if
     end if
   wend
end.

Always, indent your code so it's easy to read. Try the code I've posted here.

Hope this helps.
Tahmid.
 

Hi,
I read this as something written in mikroBASIC, am I right?
Code:
program sensor_test
main :
   TRISB=%00000011
   PORTB=0
   while true
      if PORTB.B0=1 then
         PORTB.B2=1
      else
        if PORTB.B1=0 then
         PORTB.B3=1
        end if
     end if
   wend
end.

Always, indent your code so it's easy to read. Try the code I've posted here.

Hope this helps.
Tahmid.

thank you for reply i try your code but it give me errors for all part like this
PORTB.B0=1 it should be PORTB.0=1
i correct it and there is no errors but when i load it to the Proteus schismatic its doesn't work and the program don't do the job i want it
 

Which version of mikroBASIC are you using? I'm using v3.20 and PORTB.B0 is perfectly fine. That's one of the ways you can do bit manipulation.
Anyway, go to Project > Edit Project. Did you set the configuration bits right? Turn watchdog timer off, and set oscillator to INTOSC/XTAL as per requirement.
Also, check if you've connected pin 1 - MCLR to +5v via 10k resistor. Maybe you missed this, that's why nothing's happening.

I've tested on Proteus with the code I posted and it's fine. Ok did you connect the necessary pull-up/pull-down resistor?

Hope this helps.
Tahmid.
 

Not sure what language it is but this works for me

Code:
TRISB = %00000011'set B0&B1 has input all others output
main:

If PORTB.0 =1 Then
PORTB.2 = 1
ElseIf PORTB.0 = 0 Then
PORTB.2 = 0
End If

GoTo main

When PORTB.0 = 1 then PORTB.2 lights the LED. I'm not sure because I not sure what langauge your uisng but with this
TRISB=%00000011
PORTB=0
You set TRISB for B0&B1 has input then with this PORTB.0 this is setting all PORTB to inputs, Not inputs and outputs This may be why your not lighting any LED'S
 

Hi,
The code is in mikroBASIC and it's fine.
Where is he setting PORTB all to inputs? That's only done in the first line where he writes to TRISB. When PORTB.0 = 1 then PORTB.2 = 1. This means that when input RB0 = 1 then RB2 outputs 1.
 

Well if I remove TRISB=.0 it works for me.
 

Well, it works as it is. Which line are you exactly removing? And did you use mikroBASIC? This is in mikroBASIC.
 

I used Proton, It does work but I found out where I went wrong
This is what it works in PDS
Code:
Device 16F877

main:
 TRISB = %00000011
 PORTB=0
 While 1=1
If PORTB.0 =1 Then
PORTB.2 = 1
ElseIf PORTB.0 = 0 Then
PORTB.2 = 0
End If
 Wend
This is the way that did not work
Code:
main:
 TRISB = %00000011
 PORTB=0
 
If PORTB.0 =1 Then
PORTB.2 = 1
ElseIf PORTB.0 = 0 Then
PORTB.2 = 0
End If
GoTo main
Well it worked but LED was flashing like a good one, I missed out the wend
 

Can i ask you which compiler are you using lina889?
Regards,
Jerin.
 

Which version of mikroBASIC are you using? I'm using v3.20 and PORTB.B0 is perfectly fine. That's one of the ways you can do bit manipulation.
Anyway, go to Project > Edit Project. Did you set the configuration bits right? Turn watchdog timer off, and set oscillator to INTOSC/XTAL as per requirement.
Also, check if you've connected pin 1 - MCLR to +5v via 10k resistor. Maybe you missed this, that's why nothing's happening.

I've tested on Proteus with the code I posted and it's fine. Ok did you connect the necessary pull-up/pull-down resistor?

Hope this helps.
Tahmid.

am using micro basic for microchip PIC MCUs but am also try your previous code on v3.20 microbasic it's work but when i load the code to the Proteus no output on the led i do the other thing that u told me but the same happened this is the Proteus
 

Attachments

  • protues.pdf
    11.6 KB · Views: 119

Can i ask you which compiler are you using lina889?
Regards,
Jerin.

am using micro basic for microchip PIC MCUs but am also have the micro basic v3.20
this is my 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.
and this is my protues
 

Attachments

  • protues.pdf
    11.6 KB · Views: 100

For the Proteus simulation it don't require the crystal ocsr & the supply voltage for the controller. You need to provide it when you are doing that in a bread board or in a PCB. I have not used mickro Basic but used MikroC. So there would be change in instructions between both the compilers rite? Is there any similarity?
Regards,
Jerin.
 

Hi,
The code is fine, I've tested it. What you need to do is connect a 10k resistor from RB0 to ground and another 10k resistor from RB1 to ground.
Try it.

Hope this helps.
Tahmid.
 

Also have you enable the pull up resistors of PORTB by clearing the MSB of OPTION_REG @ the main program? Please see that too.
Regrads,
Jerin.
 

Hi,
If you use external resistors, you don't need to enable internal ones. But if you use internal pull ups then you won't need the external resistors.
Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top