Maker Pro
Maker Pro

pic16f877a not responding

nges

Feb 21, 2014
16
Joined
Feb 21, 2014
Messages
16
i finally wrote my first program using the microc, i compiled it and programed it into the mic successfully, but when i insert the mic into my circuit it does not react. i have simulated the circuit in proteus and it works and i have also used the data sheet to see pin configuration. i am also positive that my practical connections are correct.
what can really cause the pic16f877a not to react
is it possible to program a bad pic
pls i need some practical considerations when connecting this pic. here is part of my code

Code:
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;

 
     
void main()
 {
  cmcon = 0;
  TRISA = 0xFF;
  TRISB = 0x00;
  trisd = 0xff;
  portc.f0 = 0;
  portc.f3 = 0;

  lcd_init();
  lcd_cmd(_lcd_cursor_off);
  lcd_cmd(_lcd_clear);
  lcd_out(1,6,"||");
  lcd_out(2,6,"||");
  rb7_bit = 1;

while(1)
 if(button(&portd,0,1,0))
          {
               if(button(&portd,1,1,0)) //overload test   pin d2
               {
                lcd_out(1,1,"     ");//lcd display
               }
               else if(button(&portd,1,0,1))
               {
               lcd_out(1,1,"Schge"); //lcd out something
               lcd_out(2,8,"     ");
               }
                if(button(&portd,3,1,0))
                {
                 lcd_out(1,8,"     ");//lcd display
                } // seat belt test pin d4
                else if(button(&portd,3,0,1))
                {
                  lcd_out(1,8,"Cture");  //lcd out something
                  lcd_out(2,8,"     ");
                }
                if(portd.f0 == 0 && portd.f1 == 0 &&  portd.f3==0)
                {
                portc.f0=0;
                }
                else
                {
                  portc.f0=1;
                }
                 if(portc.f0==0 && portc.f1==0)
                {
                  lcd_out(2,8,"D-Acc");

                  portc.f2=0;
                }
                else
                {
                portc.f2=1;
                }
          }
          else if(portd.f0==1)
          {
              portc.f0=0;
          }
  }
}
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Try making a really simple program that causes some output to follow the status of your button. Or even one that makes a LED flash.

That's remarkably diagnostic that you have some basics working (clock source for example)
 

hexreader

Apr 21, 2011
135
Joined
Apr 21, 2011
Messages
135
Shouldn't there be an opening curly bracket after "while(1)" ?


You seem to be using PORTC as output, but I do not see anywhere that you have cleared TRISC register.


Your code is hard to understand because the commenting is so poor. We have little idea what is connected to each input and output because you have no comments to tell us.

I agree with Steve, get a simple program working first - then build on it, and comment it well as you go.
 
Last edited:

kpatz

Feb 24, 2014
334
Joined
Feb 24, 2014
Messages
334
There's only a single if statement under the while, so curly brackets under the while aren't needed in this case. It is cleaner looking to use them though.

Ditto what others have said, start with a simple program that flashes an LED, then go from there.

Also, what do you have the configuration bits set to? For example, if you have the PIC configured to use a crystal oscillator but no crystal is connected, the PIC won't run but can still be programmed (it uses an internal clock when programming).
 

nges

Feb 21, 2014
16
Joined
Feb 21, 2014
Messages
16
thanks alot, i will try a smaller program and get back to you if it works.
 

hexreader

Apr 21, 2011
135
Joined
Apr 21, 2011
Messages
135
There's only a single if statement under the while, so curly brackets under the while aren't needed in this case. It is cleaner looking to use them though.
In that case a bracket will need to removed further on. The code posted will not compile due to more closing brackets than opening brackets.
 

nges

Feb 21, 2014
16
Joined
Feb 21, 2014
Messages
16
thanks guys, i have been able to correct the problem. i built a smaller program as you suggested and later discovered that the problem was coming from the fact that i did not configure an extenal oscillator during the burning process of the mic. As for the brackets, it was a pasting error because the opening bracket shoul be there
thks again for your ideas
 
Top