# Display message with input switchs

Status
Not open for further replies.

#### Parth86

##### Member
Hello
please look at attached picture there is microcontroller connected with LCD and two input switches.

I want to write c program that will do following things
* start LCD
*display message on first line" do you like dog"
*display message on second line like option " YES NO"
*if I press YES switch button than display message " you like dog"
*If I press NO switch than display message " you don't like dog"
*display message on first line" do you like CAT"
*display message on second line like option " YES NO"
*if I press YES switch button than display message " you like CAT"
*If I press NO switch than display message " you don't like CAT"
* stop LCD

C:
// Program for LCD Interfacing with 8051 Microcontroller

#include<reg51.h>
#define display_port P1      //Data pins connected to port 2 on microcontroller
sbit rs = P2^0;  //RS pin connected to pin 2 of port 3
sbit rw = P2^1;  // RW pin connected to pin 3 of port 3
sbit e =  P2^2;  //E pin connected to pin 4 of port 3
sbit yes = P3^0; // yes button connected to p3_0 pin
sbit No  = P3^3; // no button connected to P3_3 pin

void msdelay(unsigned int time)  // Function for creating delay in milliseconds.
{
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcd_cmd(unsigned char command)  //Function to send command instruction to LCD
{
display_port = command;
rs= 0;
rw=0;
e=1;
msdelay(1);
e=0;
}

void lcd_data(unsigned char disp_data)  //Function to send display data to LCD
{
display_port = disp_data;
rs= 1;
rw=0;
e=1;
msdelay(1);
e=0;
}
void lcd_init()    //Function to prepare the LCD  and get it ready
{
lcd_cmd(0x0d);  // turn display ON, cursor blinking
}
void main()
{
lcd_init();
while (1)
{

}
}
what I have to write in main function to do all work ?

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
I like helping you Vead! BUT!! When you are asking about RTOS and Kernels.... Then about simple LCD interfacing, I can't help but wonder if you are reading your books backwards... You seem to be running before you can crawl..

First write a "print at" function ( which you will find in my tutorial ) that can blit a string to the LCD..

#### Parth86

##### Member
I like helping you Vead! BUT!! When you are asking about RTOS and Kernels.... Then about simple LCD interfacing, I can't help but wonder if you are reading your books backwards... You seem to be running before you can crawl..
Yes I want to write simple real time operating system for microcontroller and yes I have been asking some question regarding rtos. I am still thinking about simple idea for rtos project I wanted to start with LED. I wanted to write rtos program for LED because I have knowledge and I have been written program for LED and its easy for beginner to work with LED.

In previous thread I started to write one program for all task (led, LCD and motor) than I tested my program with three LED's for multitasking. my program worked fine, but I realized that I am too long to write real time operating system.

I thought writing c program for LED, LCD and motor is not enough to start rtos programming. my approach was wrong to learn rtos programing and my programming skill is not enough to write rtos program. so this is reason that's why I started to asking low level basic. this question is also related to rtos program. I will implement this function in my rtos project. I have downloaded book and I am reading now some basic. May be my wording is weird so don't mind it
You seem to be running before you can crawl..
Yes I think also, what could be simple way to learn RTOS programming. I wanted to divided all parts in to small tasks. I know the rtos is combination of many header files and source file (with.c file). I have downloaded some sample code but that was very complex for me

Last edited by a moderator:

#### ci139

##### Active Member
100pcs New original AT89C51 PDIP-40 AT89C51-24PI 51 bit 8 MCU microcontroller

Price: US $135.00 / lot , 100 pieces / lot , US$1.35 / piece
Sorry, this item is no longer available!

↑↑ makes sense for OS dev. -- as by qty. as by \$price -- as compared against

• In-System Reprogrammable Flash Memory – Endurance: 1,000 Write/Erase Cycles
128 x 8-bit byte Internal RAM
• extendable 2.15.1 Multiprocessor Communications (from (►)Documentation )

PS! ↑↑ is to illustrate an estimate for what the ► testing learning modifying/developing/improving ◄◄ would require and that for each./multiple OS features . . .
NB! -- don't buy anything for just incase

to write simple real time operating system
you'll likely learn from the attempt

• to set up and program a specific device/appliance controller
• to set up and program an I/O controller
• the low level CPU/SYS programming
to go for more complex OS (greater no of specific devices) or for multi-processor "system" -- it makes sense to get familiar the OS theory first
• why to read the OS theory 1-st -- is that interfacing different combination of devices is a specialized field of engineering and you likely wont make right assumptions about how to manage this simply by your own experience
• how much OS theory you should know -- is exactly that what you need for your application -- it does not necessarily require fluent graduation of a full scale university course (though the more you know of it - the better)
• why to read the multitasking theory 1-st -- is much like with OS theory -- only i guess it's a bit more complex to grasp and navigate in -- as anything not so strigth forward here to grasp when you haven't time sliced parallel tasks and shared the processor time in between

Last edited:
Status
Not open for further replies.