mikroC Pic16f628a. my buttons program dont work!

Thread Starter

Peon501

Joined Mar 29, 2014
4
Rich (BB code):
void priekin()
{
  if(PORTA.RA0 == 1 && PORTA.RA1 == 0) //if button is pressed
  {
            PORTB =  0x03;
          Delay_ms(5); 
            PORTB =  0x06;
          Delay_ms(5);
            PORTB =  0x0C;
          Delay_ms(5);
            PORTB =  0x09;
          Delay_ms(5);
          } else { PORTB =  0x00; }
}
void atgal()
{

if(PORTA.RA1 == 1 && PORTA.RA0 == 0)
{
            PORTB =  0x09;
          Delay_ms(5);
            PORTB =  0x0C;
          Delay_ms(5);
            PORTB =  0x06;
          Delay_ms(5);
            PORTB =  0x03;  //1 lygu 0 0 lygu 1
          Delay_ms(5);        //WAIT 1000/1S;
 } else { PORTB =  0x00; }
 }
 void stop()
{

if(PORTA.RA2==1)
{
PORTB =  0x00;
 TRISA.RA0 = 0;
 TRISA.RA1 = 0;
 }
 }
void main()                      //MAIN;
{
 TRISB = 0x00;                   //SET PORTB TO BE OUTPUT;
 PORTB = 0x00;                   //TURN OFF LEDs ON PORTB;

 TRISA.RA0 = 1;
 TRISA.RA1 = 1;
 TRISA.RA2 = 1;
while(1)
{
stop();
atgal   ();
priekin ();
}
}


//where is a problem ?
//Code works on Proteus 8 Professional, but dont work in real.
bad project config, code or schematic ?
Write back fast
<SNIP>
 

Attachments

Last edited by a moderator:

MrChips

Joined Oct 2, 2009
30,824
You have a serious problem the way the push buttons are connected to RA0, RA1 and RA2.
You cannot connect them to one pull up resistor R9.

You need to connect the buttons to GND.
Then use individual pull up resistors, one for each of the three pins.
 
Top