📄 1602.c
字号:
#include<REG51.h>
#include<ABSACC.H>
#include <intrins.h>
#include"1602.h"
void inst_lcd(void)
{
LCD_E=0;
LCD_RS=0;
//LCD_RW=0 ; //已经接地,恒为0//
/////////////////////////
//三次显示模式设置
com_h(0x30,10);
com_h(0x30,10);
com_h(0x30,10);
com_h(0x20,10); //4总线模式
delay_lcd(100);//延时5ms//
com_f(0x28); //4总线模式,双行显示
delay_lcd(100);//延时5ms//
com_f(0x01); //清屏
delay_lcd(50);//延时5ms//
com_f(0x02); //光标复位
delay_lcd(50);//延时5ms//
com_f(0x0C); //开显示
delay_lcd(50);//延时5ms//
com_f(0x06); //文字不动,光标右移
delay_lcd(50);//延时5ms//
com_f(0x40); //文字不动,光标右移
delay_lcd(50);//延时5ms//
}
void disp(unsigned char x,unsigned char y,unsigned char dec)
{
unsigned char ge,shi;
shi=dec/10;
ge=dec%10;
shi|=0x30;
ge|=0x30;
dispchar(x,y,shi);
dispchar(x+1,y,ge);
}
void disp_bcd(unsigned char x,unsigned char y,unsigned char bcd)
{
unsigned char ge,shi;
ge=(bcd&0x0f);
shi=(bcd>>4);
shi|=0x30;
ge|=0x30;
dispchar(x,y,shi);
dispchar(x+1,y,ge);
}
void dispchar(unsigned char x,unsigned char y,unsigned char ddat)
{
y&=0x01;
x&=0x0f;
if(y) x|=0x40;
x|=0x80;
com_f(x);
dat(ddat);
}
void com_f(unsigned char ch_temp)
{
unsigned char tt,te;
LCD_RS=0;
delay_lcd(5);
te=P1&0x0f;
tt=ch_temp&0xf0;
//tt=tt>>2;
P1=te|tt;
_nop_();
_nop_();
LCD_E=1;
_nop_();
_nop_();
LCD_E=0;
//写入高4位//
te=P1&0x0f;
tt=ch_temp&0x0f;
tt=tt<<4;
P1=te|tt;
_nop_();
_nop_();
LCD_E=1;
_nop_();
_nop_();
LCD_E=0;
//低4位//
delay_lcd(5);
}
void dat(unsigned char dat_temp)
{
unsigned char tt,te;
LCD_RS=1;
delay_lcd(5);
te=P1&0x0f;
tt=dat_temp&0xf0;
//tt=(tt>>2);
P1=te|tt;
_nop_();
_nop_();
LCD_E=1;
_nop_();
_nop_();
LCD_E=0;
//写入高4位//
delay_lcd(5);
te=P1&0x0f;
tt=dat_temp&0x0f;
tt=tt<<4;
P1=te|tt;
_nop_();
_nop_();
LCD_E=1;
_nop_();
_nop_();
LCD_E=0;
//低4位//
}
void com_h(unsigned char temp,unsigned char time)
{
unsigned char te;
LCD_RS=0;
te=P1&0x0f;
temp&=0xf0;
//temp=temp>>2;
P1=te|temp;
delay_lcd(time);
LCD_E=1;
_nop_();
_nop_();
LCD_E=0;
}
void delay_lcd(unsigned char time)
{
unsigned char i,j;
for (i=0;i<time;i++)
{
j=100;
while(j--);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -