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.
i want the LEDs to get off when i off the switch but the problem when i get off the switch the led stay on

Ok. Are you using interrupt routine to make the port pins to logic 0 (pins where LEDs are connected) while the switch is off?
Regards,
Jerin.
 

no am not using any interrupt

Then how did you write the code for that condition without interrupt? Did you use polling method? Can you post the code of that part please i mean the routine where you have written the code to make the LED off?
Regards,
Jerin.
 

this is my code
program final

' Declarations section

main:


TRISB=%00000011
PORTB=0
while true
if PORTB.B0=1 then
PORTB.B2=1
end if
if PORTB.B1=1 then
PORTB.B3=1
end if

wend
end.
end.
end.


---------- Post added at 09:01 ---------- Previous post was at 08:56 ----------

ok ok i find it in my code there is no else statement that return the led off when the switch is off i think it should be like this
program final

' Declarations section

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.
end.
end.
 

this is my code

Let me ask one question.
For the conditional check,normally we use if statement.
Actually its structure should be:
if PORTB.B0 == 1 & not if PORTB.B0 = 1. Isn't it?
Also here you are checking the ON condition of the switch only. I couldn't find the code for the OFF condition check of the switch.

Regards,
Jerin.
 

Let me ask one question.
For the conditional check,normally we use if statement.
Actually its structure should be:
if PORTB.B0 == 1 & not if PORTB.B0 = 1. Isn't it?

Regards,
Jerin.

in micro basic programing we are not using in if statement == it make error ..

but the wrong in my code am not using the OFF statement
thank you very much
 

in micro basic programing we are not using in if statement == it make error ..

but the wrong in my code am not using the OFF statement
thank you very much

I couldn't find the condition for :
if PORTB.B0 = 0 & if PORTB.B1 = 0. These were the conditions for OFF condition of the switch. Check once more & see if the same error repeats.
Regards,
Jerin. ;-)
 

i add for each if statement else part

this is my first program

main:


TRISB=%00000011
PORTB=0
while true
if PORTB.B0=1 then
PORTB.B2=1
end if
if PORTB.B1=1 then
PORTB.B3=1
end if

wend
end.
end.
end.

and with else statement like this
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.
end.
end.

if portb.0=1
then portb.2=1
else portb.2=0
** thats mean if portb.0=1 portb.2=1
and if portb.0=0 portb.2=0
and here the led is getting off when i off the switch
 

try this:

if portb.b0 = 0 then
portb.b2 = 0
else
portb.b2 = 1
end if
 

@Tahmid:
That resistor connected to PORT E pin is PULL UP Resistor. As the port pin is driven to a high impedance state by using the power supply with a resistor,the resistor is called PULL UP resistor. If the resistor is connected to the ground from the port pin that resistor is called Pull down resistor. It creates a low impedance state @ the port pin to which it is connected.
Hi,
I was talking about the resistor from pin to ground, that's why I said pull-down.

---------- Post added at 14:34 ---------- Previous post was at 14:30 ----------

In mikroBASIC, or for that matter, any BASIC compiler within my knowledge, we use = for checking condition, not == like in C.

---------- Post added at 14:36 ---------- Previous post was at 14:34 ----------

Lina,
Why do you have 3 end. statements. You need only 1.
And just as a piece of advice, indent your coding so it is easier to read.

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.

Hope this helps.
Tahmid.
 

Hi,
I was talking about the resistor from pin to ground, that's why I said pull-down.

---------- Post added at 14:34 ---------- Previous post was at 14:30 ----------

In mikroBASIC, or for that matter, any BASIC compiler within my knowledge, we use = for checking condition, not == like in C.

---------- Post added at 14:36 ---------- Previous post was at 14:34 ----------

Lina,
Why do you have 3 end. statements. You need only 1.
And just as a piece of advice, indent your coding so it is easier to read.

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.

Hope this helps.
Tahmid.

it's work thank you all very much for being so helpful
 

i add for each if statement else part

this is my first program



and with else statement like this


if portb.0=1
then portb.2=1
else portb.2=0
** thats mean if portb.0=1 portb.2=1
and if portb.0=0 portb.2=0
and here the led is getting off when i off the switch

Here you could write the code like this:

TRISB=%00000011
PORTB=0
while true
if PORTB.B0=1
PORTB.B2=1
else
PORTB.B2=0
end if
if PORTB.B1=1
PORTB.B3=1
else
PORTB.B3=0
end if
wend
end.

Is the statement then required with the if condition in Micro Basic or you can work out with simply if statement?
Regards,
Jerin. ;-)
 

Hi jerin,
Then is required like:
Code:
if (condition) then
....
end if
or
Code:
if (condition)
then ....
......
end if
or
Code:
if (condition)
then
......
end if

Hope this helps.
Tahmid.
 

Hi jerin,
Then is required like:
Code:
if (condition) then
....
end if
or
Code:
if (condition)
then ....
......
end if
or
Code:
if (condition)
then
......
end if

Hope this helps.
Tahmid.

Ok. Thanks for your reply. So every statement has an end statement also. i never used MikroBasic. So had a doubt.
Regards,
Jerin. :)
 

Yea,
This is the standard format for BASIC compilers and is same for mikroBASIC and Microsoft Visual Basic as well. I think if..then.....end..if is much easier to read and more organized than the C parentheses {}.

Hope this helps.
Tahmid.
 

Yea,
This is the standard format for BASIC compilers and is same for mikroBASIC and Microsoft Visual Basic as well. I think if..then.....end..if is much easier to read and more organized than the C parentheses {}.

Hope this helps.
Tahmid.

Yeah... Thanks for the reply. Now i think i should also try MicroBasic rather than MikroC.
Regards,
Jerin.
 

Hi -

I am trying to interface a dc servo motor with pic16F877A, the code is written in
Basic. I don't see the hardware responding at all to the code. I think it is because of the initialization of the configuration bits. So can you help me out with what and how to initialize parameter in Basic.

Regards
Ankit
 

Hi,
Which compiler? mikroBASIC, PICBASIC or something else?
In mikroBASIC, go to the Projects menu > Edit Project and set the configuration bits there.

Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top