please help me it is not working

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
psaundary
Posts: 4
Joined: 03 Oct 2014 18:35

please help me it is not working

#1 Post by psaundary » 03 Oct 2014 19:20

:( i just want a push button on port b0 and use port a0 as o/p
sbit b at RB0_bit; // b button

sbit led at RA0_bit; // led o/p

sbit button_direction at TRISB0_bit;

sbit led_direction at TRISA0_bit;

void main() {
if(b=0){
PORTA=!PORTA;
}

while(1);

}
there is no error in compile this code bt not working in proteus :'(

please help me :'(

MaGiK
Posts: 897
Joined: 19 Apr 2013 10:00

Re: please help me it is not working

#2 Post by MaGiK » 04 Oct 2014 11:03

Hello psaundary and welcome to the forum :D

I'm not sure, but I think you may have to change a part of your code into this:

Code: Select all

void main()
{
While (1)
   {
if(b==0)
      {
      PORTA=!PORTA;
      }
   }
}
The main difference is the double equal sign '=' in the condition statement.

I didn't focus on your post since I'm a little busy at the moment. So, it might not solve your issue.
Please let me know if it didn't solve your issue :D
Best Regards
My hobby is collecting MikroElektronika products.
Gotta catch them all!

psaundary
Posts: 4
Joined: 03 Oct 2014 18:35

not working again

#3 Post by psaundary » 09 Oct 2014 12:32

may you give me mikroc program to on/off led by using pushbutton .. :idea:

sbit b at RB0_bit;
sbit led at RC0_bit;
sbit button_direction at TRISB0_bit;
sbit led_direction at TRISC0_bit;
void main() {

button_direction = 1;
led_direction=0;
if(b==1){
led=!led;}
while(1);
}


i am new in this field , please help me :oops: my compiler successfully compile the code bt if i use hex code in proteus ,port c0 reamin same every time when i press button

MaGiK
Posts: 897
Joined: 19 Apr 2013 10:00

Re: please help me it is not working

#4 Post by MaGiK » 10 Oct 2014 12:21

Hello psaundary :D

Of course I'm going to try to help you out :D
But the thing is, it's a little hard to help you without knowing the schematic, so could you please attach a picture here of your schematic?
It will give us a better picture of what's going on :mrgreen:

Best Regards
My hobby is collecting MikroElektronika products.
Gotta catch them all!

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: please help me it is not working

#5 Post by p.erasmus » 10 Oct 2014 12:36

As a beginner you should learn when you ask help in the Forum you need to give the inforamtion about your setup we can not see over your pc to your hardware
what you are doing
so what mcu are you using ??
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

johnt
Posts: 204
Joined: 01 Jul 2010 13:24

Re: please help me it is not working

#6 Post by johnt » 10 Oct 2014 13:15

You might also find this page helpful.

http://www.mikroe.com/chapters/view/17/ ... ples/#c4v8

psaundary
Posts: 4
Joined: 03 Oct 2014 18:35

Re: please help me it is not working

#7 Post by psaundary » 11 Oct 2014 06:48

i am using pic 16f877a with 10 MHz crystal oscillator ..
i want use port b0 as input port and want to take response on port c0
in this fig i did not use led on c0 , i am using proteus professional 8 version there is no need to give vcc voltage source (i hope) for simulation ,actually i tested lcd program without using vcc for mcu.
please help :(
Untitled.png
Untitled.png (16.21 KiB) Viewed 2854 times
i did not use led on c0 ,bcs Proteus can show port status if low blue if high it will be red 8)

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: please help me it is not working

#8 Post by p.erasmus » 11 Oct 2014 10:57

You have to pull MCLR pin up to VDD as in the real circuit ,as you did not do it, your model will never Run as the PIC is in Reset state
Attached a Proteus 8.2 model and mikroC code project of your PIC with Button which switch states on RC0 as you press the button and a Led on RC4 which Toggles every 100mSec
Attachments
11.10.png
11.10.png (9.88 KiB) Viewed 2844 times
Proteus_16F.zip
(75.89 KiB) Downloaded 86 times
Last edited by p.erasmus on 11 Oct 2014 14:41, edited 1 time in total.
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

hasan hadi
Posts: 138
Joined: 27 Jul 2014 07:49

Re: not working again

#9 Post by hasan hadi » 11 Oct 2014 14:13

psaundary wrote:may you give me mikroc program to on/off led by using pushbutton .. :idea:

sbit b at RB0_bit;
sbit led at RC0_bit;
sbit button_direction at TRISB0_bit;
sbit led_direction at TRISC0_bit;
void main() {

button_direction = 1;
led_direction=0;
if(b==1){
led=!led;}
while(1);
}

i am new in this field , please help me :oops: my compiler successfully compile the code bt if i use hex code in proteus ,port c0 reamin same every time when i press button
Hi,
this correct code

Code: Select all

sbit b at RB0_bit;
sbit led at RC0_bit;
sbit b_direction at TRISB0_bit;
sbit led_direction at TRISC0_bit;
void main() 
{
 adcon1=6;
 b_direction = 1;
 led_direction=0;
 led=0;// off led
  while(1){
            if(b==1){
                     led=!led;
                     delay_ms(250);
                    }
          }
}

psaundary
Posts: 4
Joined: 03 Oct 2014 18:35

yupee we did it .

#10 Post by psaundary » 16 Oct 2014 17:25

thank you to all ,for help me .. it is now working good and also i found that what mistake i did .. thanks to all :D

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: please help me it is not working

#11 Post by p.erasmus » 16 Oct 2014 19:08

good luck :D
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

Post Reply

Return to “mikroC PRO for PIC General”