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.

Push button and pic16f877a

Status
Not open for further replies.

Milenia

Newbie level 4
Joined
Oct 13, 2012
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,342
Hi guys.

I am beginner in microcontroller. Current I’m doing my assignment. My assignment has one push button and lcd by using pic16f877a. When my push button is press, I want the LCD is dispIay “AVAILABLE 2” and LED ‘1’. I have try my coding. But it seems not works correctly same as my expected. Its only display “AVAILABE 2” and LED ‘1’ without I press the push button. Same when I press the push button. It will display the same thing. How to make it correctly?Maybe there is some mistaken that I did.
push button.jpg
Code:
Coding

[syntax=c]// LCD module connections
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;

sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
void main()
{
  TRISA.F0 = 1;   //PortA bit 1 input
  TRISD.F0 = 0;      //Port D pada bit 0,1,2 output
  

while (1)
  {
    if(PORTA.F0 == 0)   //If the switch is pressed
      {
       Delay_ms(1000);    //Switch Debounce
         PORTD.F0 = 0; //LED port 0 ON
         Lcd_Init();                        // Initialize LCD
         Lcd_Cmd(_LCD_CLEAR);               // Clear display
          Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
          Lcd_Out(1,1,"FULL ");
          }

   else
      {
        Delay_ms(1000);    //Switch Debounce
       PORTD.F0 = 1; //LED port 0 ON
       Lcd_Init();                        // Initialize LCD
       Lcd_Cmd(_LCD_CLEAR);               // Clear display
       Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
       Lcd_Out(1,1,"AVAILABLE 2");
       }      // Write text'Hello World' in first row




  }
}[/syntax]
 
Last edited by a moderator:

Move LCD_Init(); and Lcd_Cmd(_LCD_CURSOR_OFF); after main() but before the while() loop. you only need to initialize the LCD once, not every time it goes around the loop.

Also note that the LED output is active low so you need the LED and series resistor to connect between PORTD bit 0 and VDD. You also check for PORTA bit zero going low when the button is pushed but do you have a pull-up resistor so it goes high again when the switch is released?

Brian.
 

You should have a pull up resistor(10K) on the switch. Alternatively connect the switch to portB and enable the pull up resistors. In practice Vee needs to be connected to ground via a potential divider, otherwise you will not get a display, t does not matter on the simulator. A series resistor of around 220R needs to be connected in series with the LED
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top