📄 lcdinf.c
字号:
#include <avr/io.h>
#define uch unsigned char
#define uint unsigned int
#define s_b(sfr,bit) (sfr|=(1<<bit))
#define c_b(sfr,bit) (sfr&=~(1<<bit))
#define test_b(sfr,bit) (sfr&(1<<bit))
#define NOP() __asm__ __volatile__ ("nop" ::)
#define DATA_i PINC //数据输入
#define DATA_o PORTC//数据输出
#define DATA DDRC
#define cont PORTB//控制端口\
#define RS 0
#define RW 2
#define ES 1
char xy_ch[2][8];//显示缓存
uch ascii_s(uch x){
if(x<10)return x+0x30;
else return (x-9)+0x40;
}
void dlay(){ //短延时
NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();
}
void dlay2(uch x){ //短延时
for(;x!=0;x--){NOP();NOP();NOP();NOP();NOP();}
}
void w_by(uch x){//写数据
s_b(cont,RS);
c_b(cont,RW);
NOP();
NOP();
NOP();
NOP();
s_b(cont,ES);NOP();NOP();
DATA_o=x;NOP();NOP();NOP();
c_b(cont,ES);
dlay();
}
void w_com(uch x){//写指令
c_b(cont,RS);
c_b(cont,RW);
NOP();
NOP();
NOP();
NOP();
s_b(cont,ES);NOP();NOP();
DATA_o=x;NOP();NOP();NOP();
c_b(cont,ES);
dlay();
}
void xini(uch x){
if(x>7)x+=0x38;
w_com(x|0x80);}
void lcdini(void){
uch x;
for(x=250;x!=0;x--)dlay2(250);
w_com(0x1);//清显示
for(x=10;x!=0;x--)dlay2(250);
w_com(0x38);//显示设置
dlay2(80);
w_com(0x6);//显示设置
dlay2(80);
w_com(0xc);//清显示
dlay2(80);
for(x=200;x!=0;x--)dlay2(250);
//w_com(0xc0);//清显示
w_com(0x40);
/*
dlay2(80);
w_by(0x40);
dlay2(80);
w_by(0xff);
dlay2(80);
w_by(0);
dlay2(80);
w_by(0xff);
dlay2(80);
w_by(0);
dlay2(80);
w_by(0xff);
dlay2(80);
w_by(0);
dlay2(80);
w_by(0xff);
*/
for(x=200;x!=0;x--)dlay2(250);
}
void dis_chs(char *ch,uch a)
{
uch i;
for(i=0;i<8;i++){
xy_ch[a][i]=*ch;
ch++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -