thannara123
Advanced Member level 5
hello experts please correct the code below
lcd 4 bit interfacing with 8051
lcd 4 bit interfacing with 8051
Code:
[FONT=Courier New][COLOR=#339933]#include <REGX51.H>[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#339933]#include <stdio.H>[/COLOR]
[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New][COLOR=#339933]#define LCDPORT P2[/COLOR][/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New]sbit RS = LCDPORT ^ [COLOR=#CC66CC]4[/COLOR];
[/FONT]
[FONT=Courier New]sbit EN = LCDPORT ^ [COLOR=#CC66CC]5[/COLOR];
[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] delay[COLOR=#66CC66]([/COLOR][COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]int[/COLOR] msec[COLOR=#66CC66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#993333]int[/COLOR] i, j;
[/FONT]
[FONT=Courier New][COLOR=#B1B100]for[/COLOR] [COLOR=#66CC66]([/COLOR]i = [COLOR=#CC66CC]0[/COLOR]; i < msec; i++[COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#B1B100]for[/COLOR] [COLOR=#66CC66]([/COLOR]j = [COLOR=#CC66CC]0[/COLOR]; j < [COLOR=#CC66CC]1275[/COLOR]; j++[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR][/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#993333]void[/COLOR][COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]EN = [COLOR=#CC66CC]1[/COLOR];
[/FONT]
[FONT=Courier New] delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]1[/COLOR][COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New]EN = [COLOR=#CC66CC]0[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] dt[COLOR=#66CC66]([/COLOR][COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]char[/COLOR] c[COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR][/FONT]
[FONT=Courier New]RS = [COLOR=#CC66CC]1[/COLOR];
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]50[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]LCDPORT = [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]c >> [COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR] & 0x0f[COLOR=#66CC66])[/COLOR] | EN | RS;
[/FONT]
[FONT=Courier New]LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New] LCDPORT = [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]c >> [COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR] & 0x0F[COLOR=#66CC66])[/COLOR] | RS[COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New]LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] cmd[COLOR=#66CC66]([/COLOR][COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]char[/COLOR] c[COLOR=#66CC66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]RS = [COLOR=#CC66CC]0[/COLOR];
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]50[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]LCDPORT = [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]c >> [COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR] & 0x0f[COLOR=#66CC66])[/COLOR] | EN;
[/FONT]
[FONT=Courier New] LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New]LCDPORT = [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR]c >> [COLOR=#CC66CC]4[/COLOR][COLOR=#66CC66])[/COLOR] & 0x0F[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]LCDSTROBE[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] lcdclear[COLOR=#66CC66]([/COLOR][COLOR=#993333]void[/COLOR][COLOR=#66CC66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x01[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]2[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] lcd_init[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]15[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New] cmd[COLOR=#66CC66]([/COLOR]0x38[COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]1[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x38[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]100[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x38[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New] cmd[COLOR=#66CC66]([/COLOR]0x28[COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// Function set (4-bit interface, 2 lines, 5*7Pixels)[/I][/COLOR][/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x28[COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// Function set (4-bit interface, 2 lines, 5*7Pixels)[/I][/COLOR]
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x0c[COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// Make cursorinvisible[/I][/COLOR]
[/FONT]
[FONT=Courier New]lcdclear[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// Clear screen[/I][/COLOR]
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x6[COLOR=#66CC66])[/COLOR]; [COLOR=#808080][I]// Set entry Mode(auto increment of cursor)[/I][/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR][/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] [COLOR=#993333]string[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#993333]const[/COLOR] [COLOR=#993333]char[/COLOR] *q[COLOR=#66CC66])[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#B1B100]while[/COLOR] [COLOR=#66CC66]([/COLOR]*q[COLOR=#66CC66])[/COLOR] [COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New] dt[COLOR=#66CC66]([/COLOR]*q++[COLOR=#66CC66])[/COLOR];[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New]
[/FONT]
[FONT=Courier New]main[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66CC66]{[/COLOR]
[/FONT]
[FONT=Courier New]delay[COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]50[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]lcd_init[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]LCDPORT = 0x00;
[/FONT]
[FONT=Courier New] [COLOR=#B1B100]while[/COLOR] [COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]1[/COLOR][COLOR=#66CC66])[/COLOR] [COLOR=#66CC66]{[/COLOR][/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0x80[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#993333]string[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#FF0000]"HELLO WORLD"[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New]cmd[COLOR=#66CC66]([/COLOR]0xc0[COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New][COLOR=#993333]string[/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#FF0000]"IT IS WORKING:-)"[/COLOR][COLOR=#66CC66])[/COLOR];
[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
[FONT=Courier New][COLOR=#66CC66]}[/COLOR]
[/FONT]
Last edited by a moderator: