mikroC Pic16f628a. my buttons program dont work!

Discussion in 'Embedded Systems and Microcontrollers' started by Peon501, Mar 29, 2014.

  1. Peon501

    Thread Starter New Member

    Mar 29, 2014
    4
    0
    Code ( (Unknown Language)):
    1.  
    2. void priekin()
    3. {
    4.   if(PORTA.RA0 == 1 && PORTA.RA1 == 0) //if button is pressed
    5.   {
    6.             PORTB =  0x03;
    7.           Delay_ms(5);
    8.             PORTB =  0x06;
    9.           Delay_ms(5);
    10.             PORTB =  0x0C;
    11.           Delay_ms(5);
    12.             PORTB =  0x09;
    13.           Delay_ms(5);
    14.           } else { PORTB =  0x00; }
    15. }
    16. void atgal()
    17. {
    18.  
    19. if(PORTA.RA1 == 1 && PORTA.RA0 == 0)
    20. {
    21.             PORTB =  0x09;
    22.           Delay_ms(5);
    23.             PORTB =  0x0C;
    24.           Delay_ms(5);
    25.             PORTB =  0x06;
    26.           Delay_ms(5);
    27.             PORTB =  0x03;  //1 lygu 0 0 lygu 1
    28.           Delay_ms(5);        //WAIT 1000/1S;
    29.  } else { PORTB =  0x00; }
    30.  }
    31.  void stop()
    32. {
    33.  
    34. if(PORTA.RA2==1)
    35. {
    36. PORTB =  0x00;
    37.  TRISA.RA0 = 0;
    38.  TRISA.RA1 = 0;
    39.  }
    40.  }
    41. void main()                      //MAIN;
    42. {
    43.  TRISB = 0x00;                   //SET PORTB TO BE OUTPUT;
    44.  PORTB = 0x00;                   //TURN OFF LEDs ON PORTB;
    45.  
    46.  TRISA.RA0 = 1;
    47.  TRISA.RA1 = 1;
    48.  TRISA.RA2 = 1;
    49. while(1)
    50. {
    51. stop();
    52. atgal   ();
    53. priekin ();
    54. }
    55. }
    56.  

    [​IMG]
    //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>
     
    Last edited by a moderator: Mar 29, 2014
  2. Peon501

    Thread Starter New Member

    Mar 29, 2014
    4
    0
    maybe I need to add cristal ?
     
  3. MrChips

    Moderator

    Oct 2, 2009
    14,297
    4,198
    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.
     
    Peon501 likes this.
  4. Peon501

    Thread Starter New Member

    Mar 29, 2014
    4
    0
    Ty... I made epic fail :D
     
  5. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    You need the line..

    CMCON =0x07;

    Or the comparator module is on and portA is unaccessible..
     
    Peon501 likes this.
  6. Peon501

    Thread Starter New Member

    Mar 29, 2014
    4
    0
    Ty It work.
     
Loading...