📄 带显示部分1602子函数
字号:
#define Dataport P4OUT //数据口定义
#define DataportDIR P4DIR
#define CommandportDIR P3DIR
#define Commandport P3OUT //命令入口定义
#define Lcd_Rs BIT5
#define Lcd_Rw BIT6
#define Lcd_E BIT7 //RS,RW,E所接具体定义
#define uchar unsigned char
#define uint unsigned int
#define nop _NOP()
void delay(int i);
void Lcd_Write_Command(uchar tempdata){
Commandport&=~(Lcd_Rs+Lcd_Rw+Lcd_E);
nop;
Dataport=tempdata;
nop;
Commandport|=Lcd_E;
nop;
nop;
Commandport&=~Lcd_E;
delay(1);
}
void Lcd_Write_Data(uchar tempdata){
Commandport|=Lcd_Rs;
Commandport&=~Lcd_Rw;
Commandport&=~(Lcd_Rw+Lcd_E);
nop;
Dataport=tempdata;
nop;
Commandport|=Lcd_E;
nop;
nop;
Commandport&=~Lcd_E;
delay(1);
}
void delay(int i){
int j,k;
for(j=0;j<i;j++)
for(k=0;k<10;k++);
}
/*****************************************
功能:1.液晶初始化程序
2.在屏幕上显示table[] table1[]中内容
参数:table[] table1[] temp
返回值:无
*****************************************/
void Lcd_Init(){
DataportDIR=0xff;;
CommandportDIR=Lcd_Rs+Lcd_Rw+Lcd_E;
Lcd_Write_Command(0x38);//设置显示模式:8位2行5x7点阵
delay(5);
Lcd_Write_Command(0x0c);//显示开,光标关,闪烁关
delay(1);
Lcd_Write_Command(0x06);//文字不动光标右移
delay(1);
Lcd_Write_Command(0x01);//
delay(50);
uint temp;
uchar table[]={" Distance "}; //第一行内容
uchar table1[]={" Time 00s "}; //第二行内容
Lcd_Write_Command(0x80); //设置第一行起始地址指针
for (temp=1;temp<10;temp++){
Lcd_Write_Data(table[temp]);}
Lcd_Write_Command(0x80+0x40+0x04);//设置第二行起始地址指针
for (temp=1;temp<10;temp++){
Lcd_Write_Data(table1[temp]);}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -