thannara123
Advanced Member level 5
- Joined
- Jan 7, 2010
- Messages
- 1,602
- Helped
- 122
- Reputation
- 244
- Reaction score
- 116
- Trophy points
- 1,353
- Activity points
- 10,626
Code:
.............................main...................................
[FONT=Courier New][COLOR=#339933]#include <REGX51.H>[/COLOR][/FONT]
[FONT=Courier New][COLOR=#339933]#define LCDPORT P2[/COLOR][/FONT]
[FONT=Courier New]sbit RS = LCDPORT ^ [COLOR=#cc66cc]2[/COLOR];[/FONT]
[FONT=Courier New]sbit E = LCDPORT ^ [COLOR=#cc66cc]3[/COLOR];[/FONT]
[FONT=Courier New][COLOR=#339933]#include "lcd.h"[/COLOR][/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] main[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66cc66]{[/COLOR][/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New] lcd_init[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] lcd_cmd[COLOR=#66cc66]([/COLOR]0x80[COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] lcd_data[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR]; [COLOR=#808080][I]// just send "1" to lcd to display ;[/I][/COLOR][/FONT]
[FONT=Courier New] [COLOR=#b1b100]while[/COLOR] [COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New][COLOR=#66cc66]}
[/COLOR]..................................................................................................
........................lcd.h.......................
[FONT=Courier New][COLOR=#339933]#include"delay.h"[/COLOR][/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] latch[COLOR=#66cc66]([/COLOR][COLOR=#993333]void[/COLOR][COLOR=#66cc66])[/COLOR][/FONT]
[FONT=Courier New][COLOR=#66cc66]{[/COLOR][/FONT]
[FONT=Courier New] E = [COLOR=#cc66cc]1[/COLOR];[/FONT]
[FONT=Courier New] delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] E = [COLOR=#cc66cc]0[/COLOR];[/FONT]
[FONT=Courier New][COLOR=#66cc66]}[/COLOR][/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New][COLOR=#993333]void[/COLOR] lcd_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]10[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] LCDPORT = c & 0xf0;[/FONT]
[FONT=Courier New] latch[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] c = [COLOR=#66cc66]([/COLOR]c << [COLOR=#cc66cc]4[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] LCDPORT = c & 0xf0;[/FONT]
[FONT=Courier New] latch[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] lcd_data[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]10[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] LCDPORT = c & 0xf0;[/FONT]
[FONT=Courier New] latch[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] c = [COLOR=#66cc66]([/COLOR]c << [COLOR=#cc66cc]4[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] LCDPORT = c & 0xf0;[/FONT]
[FONT=Courier New] latch[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] 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]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] lcd_cmd[COLOR=#66cc66]([/COLOR]0x30[COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] lcd_cmd[COLOR=#66cc66]([/COLOR]0x30[COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] delay[COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] lcd_cmd[COLOR=#66cc66]([/COLOR]0x30[COLOR=#66cc66])[/COLOR];[/FONT]
[FONT=Courier New] lcd_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] lcd_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] lcd_cmd[COLOR=#66cc66]([/COLOR]0x0c[COLOR=#66cc66])[/COLOR]; [COLOR=#808080][I]// Make cursorinvisible[/I][/COLOR][/FONT]
[FONT=Courier New] lcd_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].......................................................................................................[COLOR=#66cc66]
[/COLOR]
................................ delay.h[COLOR=#66cc66][/COLOR].........................[COLOR=#66cc66]
[/COLOR]
[/FONT]
[LIST=1]
[*][FONT=Courier New][COLOR=#993333]void[/COLOR] delay[COLOR=#66cc66]([/COLOR][COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]int[/COLOR] j[COLOR=#66cc66])[/COLOR][/FONT]
[*][FONT=Courier New][COLOR=#66cc66]{[/COLOR][/FONT]
[*][FONT=Courier New] [COLOR=#993333]unsigned[/COLOR] [COLOR=#993333]int[/COLOR] i = [COLOR=#cc66cc]0[/COLOR];[/FONT]
[*][FONT=Courier New] [COLOR=#b1b100]for[/COLOR] [COLOR=#66cc66]([/COLOR]; i < j; i++[COLOR=#66cc66])[/COLOR];[/FONT]
[*][FONT=Courier New][COLOR=#66cc66]}[/COLOR][/FONT]
[*][FONT=Courier New]
[/FONT]
[/LIST]
[COLOR=#66cc66]
[/COLOR]
[/FONT]
Last edited: