You are on page 1of 4

#include #include”delay1sec.

h” #define lcd_dat P1 sbit rs=P3^0; sbit rw=P3^1; sbit en=P3^2; void write_lcd(char); void cmd_lcd(char); void disp_lcd(char); void init_lcd(); void str_lcd(char *s); void int_lcd(unsigned int); void float_lcd(float); void write_lcd(char dat) { lcd_dat=dat; rw=0; en=1; //for latching one byte info en=0; //clear for latching next info delay_ms(2); } void cmd_lcd(char cmd) { rs=0; //set cmd register write_lcd(cmd); } void disp_lcd(char c) { rs=1; //set data register write_lcd(c); } void init_lcd() { cmd_lcd(0×02); //return cursor home cmd_lcd(0×38); //8bit mode of operation cmd_lcd(0x0e); //display on cur off cmd_lcd(0×01); //clr DDRAM (display data ram) cmd_lcd(0×06); //shift cursor right after each character displayed

str_lcd(“*****”). cmd_lcd(0×80). cmd_lcd(0×01). for(i=0.H if you want to see deep details on 89C51 architecture.i<16. Special register addressing information //Go into REGX51. while(1). init_lcd(). #define RW P0_1 //This is simple way to assign names to Port Pins. str_lcd("WELCOME").H" //It contains all the Register.cmd_lcd(0×80). } /* main() { init_lcd(). delay_ms(500).i++) { cmd_lcd(0×80+i). str_lcd(“******”). } } #include "REGX51. cmd_lcd(0xc0). //begin disp from line 1 pos 0 } void str_lcd(char *s) { while(*s) disp_lcd(*s++). } */ main() { unsigned char i. RW is named as Port 0 Bit 1 #define RS P0_0 //RS is named for Port 0 Bit 0 .

k++) { DATA=x[k].#define EN P0_2 //EN is named for Port0 Bit 2 #define DATA P2 //DATA bus is named for Port 2 (8-bit) void delay(int n). DATA=0X0. s_latch(). DATA=0X10. Use 0x10 to write on line 1. char x[6]="Macjan". //Send This instruction on Databus Port 2 on LCD databus. s_latch(). //EN=1 for unlatch. s_inst(). //Latch the above instruction once. Make port 2 =0x0 so that LCD receives nothing . //universal Delay routine for your code. //Change the input type to Data. Make port 2 =0x0 so that LCD receives nothing s_data(). s_latch(). s_latch(). s_latch(). //Select RW=0 to write Instruction/data on LCD EN=1. //You can name it whatever you want. s_latch(). DATA=0X0. char y[9]="Fernandes". s_latch(). //Initialize RS=0 for selecting instruction Send RW=0. Or it will clone each character twice if you latch twice. // Set cursor on line 2. void s_inst(void).// Send Second Instruction on Port 2. (used at initial condition) delay(100000). for(k=0. // Set cursor on line 1. //Latch the above instruction 1 time. //It will send x[0]='M' as = 0x4D on Port 2. //Send Instruction Function Select routine void s_data(void). //Before changing to write data select. void main(void) //Main function { int k=0. } //to type on line 2 call instruction routine first then send instruction on port 2.k<=5. //you can name it whatever you want. RS=0. //Call Instruction Select routine DATA=0X38. // Latch Data/Instruction on LCD Databus. Use 0xC0 to write on line 2. //Send Data Select routine void s_latch(void). DATA=0X0F. //Latch this above instruction 4 times s_latch(). //Before changing to write data select. //Latch the above instruction only once. can be customised for your use. //Instruction Select routine called DATA=0XC0. //some LCDs takes time to initialize at startup s_inst().(before it was instruction input) s_latch().

EN=0. //Latch the above instruction only once. s_latch(). Or it will clone each character twice if you latch twice.s_data().j=0. RW=0.i++) for(j=0.k++) { DATA=y[k]. } while(1). for(k=0.j++). //infinite loop after completing task } void delay(int n) //Universal delay routine { int i=0. } void s_data(void) // Data select routine { RS=1. delay(1000).i<=n. //Change the input type to Data. delay(1000). } void s_inst(void) //Instruction select routine { RS=0.(before it was instruction input) //Now it will show Fernandes on line 2. RW=0. } void s_latch(void) // Latch routine { EN=1.j<=10. } // END of program .k<=8. for(i=0. //It will send y[0]='F' as = 0x45 on Port 2.