📄 66666666.c
字号:
#include <AT89X51.H>
sbit CS=P0^2;
sbit WRITE=P3^6;
sbit READ=P3^7;
sbit CD=P0^3;
sbit LED=P3^4;
unsigned char x,y;
char psin[18]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0};
void check(void);
void w_data(unsigned char d);
void w_command(unsigned char d);
void draw(x,y);
//发送数据
void w_data(unsigned char d)
{CS=0;
check();
CD=0;P0=d;WRITE=0;WRITE=1;
CS=1;
}
//发送命令
void w_command(unsigned char d)
{CS=0;
check();
CD=1;P0=d;WRITE=0;WRITE=1;
CS=1;
}
//查状态
void check(void)
{unsigned char M;
do{P0=0xff;
CD=1;READ=0;
M=P0;
READ=1;
}
while((M&0x03)<0x03);
}
//画点
void draw(x,y)
{unsigned int m;
unsigned char n,t;
n=0x12;
t=0x34;
m=(y&0x7f)*0x20;
n=x/8;
t=m-(m/0x100)*0x100+n;
w_data(t);
t=m/0x100+0x08;
w_data(t);
w_command(0x24);
if(y>=0x80) n=0xf8;
else n=0xf0;
t=x%8;
t=(~t)&0x07;
t=n|t;
w_command(t);
}
void init(void)
{
w_data(0x00);
w_data(0x00);
w_command(0x40);
w_data(0x20);
w_data(0x00);
w_command(0x41);
w_data(0x00);
w_data(0x08);
w_command(0x42);
w_data(0x20);
w_data(0x00);
w_command(0x43);
w_command(0xa7);
w_command(0x80);
w_command(0x9c);
}
void clear(void)
{unsigned int i;
w_data(0x00);
w_data(0x00);
w_command(0x24);
w_command(0xb0);
for(i=0;i<128;i++)
{check();
w_data(0x0f);
}
w_command(0xb2);
}
void main(void)
{LED=0;
init();
clear();
for(x=0;x<18;x++)
{
y=psin[x];
y=y|0x80;
draw(x,y);
}
LED=1;
while(1){}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -