#ifndef __1602_h__ #define __1602_h__
#include
sbit RS = P2^2; //定义端口 sbit RW = P2^1; sbit EN = P2^0;
#define RS_CLR RS=0 #define RS_SET RS=1 #define RW_CLR RW=0 #define RW_SET RW=1 #define EN_CLR EN=0 #define EN_SET EN=1
unsigned char pro_data(unsigned char mda); void LCD_write_com(unsigned char com); void LCD_write_Data(unsigned char Data); void LCD_init(void);
void lcd_pos(unsigned char pos); void disp(unsigned char *p); void dispchar1(unsigned char *p); void dispchar2(unsigned char *p); void dispchar3(unsigned char *p); #endif
(d) 1602.c程序清单:
#include \#include \
- 21 -
void LCD_write_com(unsigned char com) { RS_CLR; RW_CLR; EN_SET;
com = pro_data(com); P1 = com; delay_us(5); EN_CLR;
}
void LCD_write_Data(unsigned char Data) { RS_SET; RW_CLR; EN_SET;
Data = pro_data(Data); P1 = Data; delay_us(5); EN_CLR;
}
void LCD_init(void) {
LCD_write_com(0x38); delay_ms(5);
LCD_write_com(0x38); delay_ms(5);
LCD_write_com(0x38);
- 22 -
// 显示模式设置
delay_ms(5);
LCD_write_com(0x38);
LCD_write_com(0x08); // 显示关闭 LCD_write_com(0x01); // 显示清屏 LCD_write_com(0x06); // 显示光标移动设置 delay_ms(5);
LCD_write_com(0x0c); // 显示开及光标设置 }
void lcd_pos(unsigned char pos) { }
void disp(unsigned char *p) {
unsigned char i; lcd_pos(0x43); for(i=0;i<6;i++)
// 第二行显示数据
LCD_write_com(0x80|pos);
{ }
void dispchar1(unsigned char *p) // 第一行显示需要显示的提示字符串 {
}
if(4==i) { }
LCD_write_Data('0'+(*p)); p++;
LCD_write_Data(0x2e);
lcd_pos(0x00); while(*p != '\\0')
- 23 -
{ LCD_write_Data(*p); p++;
}
lcd_pos(0x4c); LCD_write_Data('f');
}
void dispchar2(unsigned char *p) { lcd_pos(0x40); while(*p != '\\0') { LCD_write_Data(*p);
p++;
}
}
void dispchar3(unsigned char *p) { unsigned char i; lcd_pos(0x00); while(*p != '\\0') { LCD_write_Data(*p); p++;
}
lcd_pos(0x40); for(i=0;i<16;i++) {
LCD_write_Data(' ');
// 第二行显示需要显示的提示字符串 // 第一行显示 第二行清空 - 24 -