📄 lcd.lst
字号:
1: #include "pic18fxx2.h"
2: #include "lcd.h"
3: char int2charLCD[]="0123456789";
4:
5: //void lcd_wait(void);
6: #define RS RC5
7: #define RS_DIR TRISC5
8: #define RW RC6
9: #define RW_DIR TRISC6
10: #define EN RC7
11: #define EN_DIR TRISC7
12: #define INPUT 0X01
13: #define OUTPUT 0X00
14: #define RS_HIGH() RS=1;RS_DIR=OUTPUT
15: #define RS_LOW() RS=0;RS_DIR=OUTPUT
16: #define RW_HIGH() RW=1;RW_DIR=OUTPUT
17: #define RW_LOW() RW=0;RW_DIR=OUTPUT
18: #define EN_HIGH() EN=1;EN_DIR=OUTPUT
19: #define EN_LOW() EN=0;EN_DIR=OUTPUT
20: #define Key_CLK RB0
21: #define CLK_DIR TRISB0
22: #define Key_Data RB5
23: #define Data_DIR TRISB5
24: //#define uchar unsigned char
25: #define TRUE 1
26: #define FALSE 0
27:
28: //static uchar reciv_data=0X00;
29: //static uchar keynumber[17]={0X89,0X9F,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
30: //static uchar dis[32]={0X30,0X30,0X30,0X32,0X33,0X34,0X35,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00};
31: //const uchar table1[ ] = {"DATA 07-090-7"};
32: //const uchar table2[ ] = {"TIME 17:53:34"};
33: //uchar PARITY;
34: //static uchar error=0x00;
35: //bit result;
36: void delay1(uchar ms)
37: {uchar w;
38: while(ms--)
39: {
40:
41: for(w=250;w!=0;w--)
42: ;
43: ;
44: ;
45: ;
46: }
47: }
48: void delay_us(uchar us)
49: {
50: while(us--);
51: }
52: uchar lcd_busy()
53: {
54: uchar result;
55: TRISD=0XFF;
56: PORTD=0XFF;
57: RS_LOW ();
58: RW_HIGH();
59: EN_HIGH();
60: result=(PORTD&0x80);
61: EN_LOW();
62: TRISD=0X00;
63: return result;
64:
65: }
66:
67: void lcd_wcmd(uchar cmd)
68:
69: {
70: while(lcd_busy());
71: RS_LOW();
72: RW_LOW();
73: EN_LOW();
74: ;
75: ;
76: ;
77: ;
78: PORTD =cmd ;
79:
80: ;
81: ;
82: ;
83: ;
84: EN_HIGH();
85: ;
86: ;
87: ;
88: ;
89: EN_LOW();
90:
91: }
92: void lcd_wdat(uchar dat)
93: {
94: while(lcd_busy());
95: TRISD=0X00;
96: RS_HIGH();
97: RW_LOW();
98: EN_LOW();
99:
100: PORTD = dat;
101: ;
102: ;
103: ;
104: ;
105: EN_HIGH();
106: ;
107: ;
108: ;
109: ;
110: EN_LOW();
111: }
112: void lcd_init()
113: { delay1(15);
114: lcd_wcmd(0x38); //16*2显示,5*7点阵,8位数据
115: delay1(5);
116: lcd_wcmd(0x38);
117: delay1(5);
118: lcd_wcmd(0x38);
119: delay1(5);
120: lcd_wcmd(0x0c); //显示开,关光标
121: delay1(5);
122: lcd_wcmd(0x06); //移动光标
123: delay1(5);
124: lcd_wcmd(0x01); //清除LCD的显示内容
125: delay1(5);
126:
127:
128: }
129: void lcd_pos(uchar pos)
130: {
131: lcd_wcmd(pos | 0x80); //数据指针=80+地址变量
132: }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -