How to display number on LCD through user input

Discussion in 'Embedded Systems and Microcontrollers' started by Parth786, Jul 18, 2017.

  1. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    previously I learned how to display message on LCD screen. Now I want to increase complexity of program. I want to make program for following condition
    if button 1 pressed than display number 1 on LCD
    if button 2 pressed than display number 2 on LCD
    else don't show any value


    upload_2017-7-18_14-10-24.png

    Code (Text):
    1. #include<reg51.h>
    2. #define port P1           /* Data pins connected to port P1 */
    3. sbit RS = P2^0;           /* RS pin connected to pin 0 of port P2 */
    4. sbit RW = P2^1;           /* RW pin connected to pin 1 of port P2 */
    5. sbit EN = P2^2;           /* EN pin connected to pin 2 of port P2 */
    6. sbit B1 = P3^0;           /* push button 1 */
    7. sbit B2 = P3^3;           /* push button 2 */
    8.  
    9. void Delay(unsigned int wait)
    10. {
    11.     unsigned i,j ;
    12.     for(i=0;i<wait;i++)
    13.     for(j=0;j<1200;j++);
    14. }
    15. /* Function to send command instruction to LCD */
    16. void LCD_Command(unsigned char cmd)
    17. {
    18.     port = cmd;
    19.     RS=0;
    20.     RW=0;
    21.     EN=1;
    22.     Delay(2);
    23.     EN=0;
    24. }
    25. /*Function to send display dato LCD */
    26. void LCD_Data(unsigned char Data)
    27. {
    28.     port = Data;
    29.     RS=1;
    30.     RW=0;
    31.     EN=1;
    32.     Delay(2);
    33.     EN=0;
    34. }
    35.  
    36. /* function for delay */
    37.  
    38. /* Function to prepare the LCD */
    39. void LCD_init()
    40. {
    41.     LCD_Command(0x38);
    42.     Delay(20);
    43.     LCD_Command(0x0f);
    44.     Delay(20);
    45.     LCD_Command(0x01);
    46.     Delay(20);
    47.     LCD_Command(0x81);
    48.     Delay(20);
    49. }
    50. void main()
    51. {
    52.   unsigned char string[15]="This is Parth";
    53.   char *buffer = string;
    54.   LCD_init();
    55.   while(*buffer)
    56.         {
    57.          LCD_Data(*buffer++);
    58.          Delay(60);
    59.         }
    60. }
    61.  
    I am having problem to write program. I have knowledge of loop , conditional statement , array strings data type ...etc but I have no idea how to write program.?
     
  2. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    may be posted complicated task. ok Try to explain what I want to do. here is my general approach.
    Note: its just hand made code
    Code (Text):
    1. #include <reg51.h>
    2. define lcd port
    3. set B1 P3.1
    4. set B2 P3.2
    5. delay function ()
    6. data function ()
    7. command function ()
    8. LCD initialize function ()
    9. int main
    10. {
    11.    LCD initialize
    12. while (1)
    13. if (B1==1)                    /* if button 1 pressed than display number 1 on LCD
    14.    { display 1 on LCD)
    15.    B2=0;
    16.   if (B2==1)                   /* if button 2 pressed than display number 2 on LCD
    17.   {display 2 on LCD}
    18.    B1=0;
    19. else
    20. { don't display}
    21. }
    22.  
    I think I have to do something like this but I am having problem to develop original program
     
  3. MrChips

    Moderator

    Oct 2, 2009
    19,117
    6,146
    Draw the flowchart first.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,989
    1,848
    You want to do a few more things than just display a message, which your first program does quite nicely. To display multiple message,well, you define multiple message strings.

    But displaying messages is a bit more complicated than say lighting some LEDs with buttons. First you have to erase any old message before you show the new one. Then you have to make sure the finger is off the button before continuing least the display flash as the same data is displays and quickly erased over and over.

    See what you can come up with given these hints.
     
  5. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    Previously I wrote program to display message on LCD after that I wanted to write program for calculator but after my many attempt I couldn't complete the program. than I decided to start with small example and I started with buttons but I think I have selected tough task for me. I just want learn programming where "LCD show message according to user input" what do you think ? what is basic example should I have to use?. I don't have much knowledge just trying to improve. as per my knowledge, I tried to select best example so If I am going in wrong direction please let me know

    I understand general things
    start LCD
    check Button B1 if pressed than Display 1 on LCD
    check Button B2 if pressed than Display 2 on LCD
    else don't display anything on LCD

    I just tried to Implement but sure this not one that I want to work in program.
    I made just for one button

    upload_2017-7-21_0-5-2.png
     
  6. jayanthd

    Active Member

    Jul 4, 2015
    902
    79
    Still need help with the project. I can help you with the project.
     
Loading...