Microcontroller › 8051 › program for 4 bit lcd interface with 89s52
- This topic has 3 replies, 3 voices, and was last updated 8 years, 3 months ago by Anonymous.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
April 23, 2016 at 11:14 am #4428AkshayParticipant
Hii friends,
I am working on the project of DAS. In that case I designed all the circuit hardwere, but i m troubling with lcd output.
I connected the LCD in this manner using PORT 0
LCD pines : RS – P0.1 ;| R/W – P0.2 ||; EN – P0.3 ;|| DB4 – P0.4 ;|| DB5 – P0.5 ||DB6 – P0.6 ||AND|| DB7 – P0.7
Can u please help to code for this.
I found lots of codes in running mode, but anyone can't help for my case.and also tell the problem why codes are not working.
April 24, 2016 at 8:44 am #13890Ashutosh BhattParticipantyou can find many readymade codes for LCD interfacing in 4 bit mode just make change as per ur pin connections and it should work
May 20, 2016 at 11:42 am #13931AnonymousGuesthi akshay,
here below you can find 4-bit lcd C prgm code.
/*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —LCD clear initialization:===================This is the sub-routine to initialise the lcd to 4bit. this has more advantagethan the 8-bit lcd. One of the advantage is using less pins compared to 8bit lcd.— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */void lcd_init() //LCD_INITIAL SUB-ROUTINE HEADER{cmd(0x01,0); // Lcd clear instructioncmd(0x02,0);cmd(0x30,0); // 8 bit initialisationcmd(0x32,0); // auxillary instruction for 4 bit lcdcmd(0x20,0); // 4 bit initialisationcmd(0x28,0); // 4 bit, 5×7 dot matrixcmd(0x0c,0); // display ON, cursor OFFcmd(0x80,0); // First row, first position}/*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —4-bit lcd program sub routine:=========================This is the sub-routine to send data to the lcd. By seperating the 8bit data into4-4bits and send to lcd using 4-lcd data lines.— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */void cmd(char p,int q) // LCD COMMAND SUB-ROUTINE HEADER{char r; // Declaring the character variablers=q; // selecting whether the hex is command or datalcd=lcd&0xf0; // clearing the lcd's 4bitr=p>>4; // source data is rotated 4 timesr=r&0x0f; // getting upper nibble seperatelylcd=lcd|r; // moving the upper nibble to lcde=1; // enabling lcddelay_us(20); // delay sub-routine is called for 7u.sece=0; // disabling lcdlcd=lcd&0xf0; // clearing the lcd's 4bitr=p; // moving source data to 'r'p=p&0x0f; // getting lower nibble seperatelylcd=lcd|p; // moving the lower nibble to lcde=1; // enabling lcddelay_us(20); // delay sub-routine is called for 7u.sece=0; // disabling lcd}/*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —Sub-routine for to display the string in lcd :===================================This is the sub-routine which simplifies the string to display in the lcd andmake the user to prgm easier.this sub-routine includes displaying string, startingaddress and time spend to display each character.— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */void strg_cmd(char p[],char add,int u) // STRING FUNCTION SUB-ROUTINE HEADER{int i,j; // Declaring the int variablesj=strlen(p); // measuring the string lengthcmd(add,0); // passing the starting address to lcdfor(i=0;i<j;i++) // for loop continues until the last character{cmd(p,1); // cmd sub-routine is calleddelay_ms(u); // delay is called for each char to display}}May 20, 2016 at 11:49 am #13932AnonymousGuest/*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —HEADER FILE DECLARATION:========================— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */#include<REGX52.H>;#include<string.h>;/*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —SFR AND PINS DECLARATION:========================— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */sfr lcd=P0; //sbit e=P3^6;sbit rs=P3^7;/*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —SUB-ROUTINE HEADER DECLARATION:===============================— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */void lcd_init(void);void cmd(char,int);void strg_cmd(char p[],char,int);note: here R/W pin of lcd is not used, so it is not mentioned above.contact: cbiinfrastructures3502gmail.com, [email protected] -
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.