📄 cc.c
字号:
#include<reg51.h>
//#include<3.dot>
#define uchar unsigned char
#define uint unsigned int
#define Lcdbusy 0x80
#define poweron 0x3f
#define poweroff 0x3e
#define firline 0xc0
sbit RS=P2^6;
sbit RW=P2^5;
sbit CS1=P2^3;
sbit CS2=P2^2;
sbit E=P2^4;
sfr DB=0x80;
uchar col,row,dat;
/*************************************************************************************/
void wtcc(void);
void Lbusy(void);
void Rbusy(void);
void Wrdat(uchar X);
void Rddat(void);
void Setxy(void);
void wrcmdL(uchar X);
void wrcmdR(uchar X);
void Init(void);
void nop(void);
void Wrdot(uchar x,uchar y,uchar* dot);
void Rollscr(uchar X);
/************************************************************************************/
void main()
{
uchar i;
Init();
for(i=0;i<1600;i+=4)
{
Rollscr(i);
Wrdat(0xff);
/* Wrdot(0,0,&hzdot[0]);
Wrdot(1,16,&hzdot[32]);
Wrdot(2,32,&hzdot[64]);
Wrdot(3,48,&hzdot[96]);
Wrdot(4,64,&hzdot[128]);
Wrdot(5,80,&hzdot[160]);
Wrdot(6,96,&hzdot[192]);
*/
}
}
/************************************************************************************
读状态字(返回状态字state)
************************************************************************************/
void Lbusy()
{
CS1=0;
CS2=1;
wtcc();
}
/***********************************************************************************/
void Rbusy()
{
CS1=1;
CS2=0;
wtcc();
}
/***********************************************************************************/
void wtcc(void)
{
RS=0;
RW=1;
DB=0xff;
E=1;
nop();
while(DB&Lcdbusy);
E=0;
}
/*************************************************************************************
/*************************************************************************************/
void clear()
{
for(row=0;row<8;row++)
{
for(col=0;col<129;col++)
{
Wrdat(0xff);
}
}
}
/*************************************************************************************/
void wrcmdL(uchar X)
{
Lbusy();
RS=0;
RW=0;
DB=X;
E=1;
nop();
E=0;
}
/************************************************************************************/
void wrcmdR(uchar X)
{
Rbusy();
RS=0;
RW=0;
DB=X;
E=1;
nop();
E=0;
}
/************************************************************************************/
void Setxy(void)
{
uchar x,y;
if(col<65)
Lbusy();
else
Rbusy();
x=col&0x3f|0x40;
y=row&0x07|0xb8;
wtcc();
RS=0;
RW=0;
DB=y;
E=1;
nop();
E=0;
wtcc();
RS=0;
RW=0;
DB=x;
E=1;
nop();
E=0;
}
/************************************************************************************/
void Wrdat(uchar X)
{
Setxy();
RS=1;
RW=0;
DB=X;
E=1;
nop();
E=0;
RW=1;
RS=0;
}
/************************************************************************************/
void Rddat(void)
{
Setxy();
DB=0xff;
RS=1;
RW=1;
E=1;
nop();
dat=DB;
E=0;
Setxy();
DB=0xff;
nop();
RS=1;
RW=1;
E=1;
nop();
dat=DB;
E=0;
}
/************************************************************************************/
void Init(void)
{
dat=poweroff;
wrcmdL(dat);
wrcmdR(dat);
dat=poweron;
wrcmdL(dat);
wrcmdR(dat);
dat=firline;
wrcmdL(dat);
wrcmdR(dat);
clear();
col=0;
row=0;
Setxy();
}
/************************************************************************************/
void Rollscr(uchar X)
{
dat=firline|X;
wrcmdR(dat);
wrcmdL(dat);
}
/************************************************************************************/
void nop(void)
{
uchar i=25;
while(i--);
}
/************************************************************************************/
void Wrdot(uchar x,uchar y,uchar* dot)
{
uchar i;
row=x;
col=y;
for(i=0;i<32;i++)
{
if(i==16)
{
row++;
col=y;
}
Wrdat(*dot);
dot++;
col++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -