📄 dianzhen.c
字号:
#include <at89x52.h>
#define uchar unsigned char
uchar i=0x00;
uchar j=0x00;
uchar k=0x00;
uchar t=0x00;
uchar keytemp;
uchar x;
uchar count=0x00;
const uchar b[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//逐列扫描码
const uchar c[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //逐行扫描码
const uchar code a[][8] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x66,0x53,0x4e,0x00,0x3e,0x43,0x43,0x7e,//20
0x3e,0x43,0x43,0x7e,0x00,0x7e,0x4b,0x7a,//06
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1E,0xE0,0x3E,0xE0,0x1E,0x00,0x00,//W
0x00,0x82,0xFE,0x92,0xBA,0x82,0xC6,0x00,//E
0x00,0x82,0xFE,0x82,0x80,0x80,0xC0,0x00,//L
0x00,0x7C,0x82,0x82,0x84,0x66,0x00,0x00,//C
0x00,0x38,0x44,0x82,0x82,0x82,0x44,0x38,//O
0x00,0xFF,0x0C,0x30,0xC0,0x30,0x0C,0xFF,//M
0x00,0x00,0x00,0xDf,0xdf,0x00,0x00,0x00,//!
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xfd,0xe5,0xdf,0xc5,0xff,0xe5,0xfd,0x00,//西
0x00,0x00,0x00,0x00,//0x00,0x00,0x00,0x00,
0xfd,0x35,0x3d,0xf7,0x3d,0xb5,0xfd,0x00,//南
0x00,0x00,0x00,0x00,//0x00,0x00,0x00,0x00,
0x35,0xff,0x35,0x28,0x3e,0x20,0xff,0x30,//科
0x00,0x00,0x00,0x00,//0x00,0x00,0x00,0x00,
0x94,0xff,0x94,0x9a,0x6f,0x6a,0x9a,0x80,//技
0x00,0x00,0x00,0x00,//0x00,0x00,0x00,0x00,
0x84,0x44,0x24,0x1f,0x34,0x44,0x84,0x80,//大
0x00,0x00,0x00,0x00,//0x00,0x00,0x00,0x00,
0x26,0x2b,0xaa,0xfb,0x3a,0x2b,0x22,0x24,//学
0x00,0x00,0x00,0x00,//0x00,0x00,0x00,0x00,
};
void device_init();
void display();
void next();
/******************************************************************************
名称:device_init
功能:初始化端口、状态寄存器。打开定时器0,按方式1工作,设计数初值为0x3caf
参数:无
******************************************************************************/
void device_init()
{
TL0=0xbf; //置定时器初值0xf0bf
TH0=0xf0;
TMOD=0x01; //设定定时器/计数器0工作方式为1
IE=0x82; //允许全局中断,允许定时器/计数器0溢出中断
TR0=0x01; //启动定时器/计数器0
}
/******************************************************************************
名称:Base_Send
功能:发送8bit到1个74HC595中 P1_5 控制线 P1_6 数据线 P1_7 时钟线
参数:send_data,为欲发送的数据
******************************************************************************/
void base_send(uchar send_data)
{
uchar index = 0x00;
for (index=0x00; index<0x08; index++)
{
P1_7 = 0;
P1_6 = send_data & (0x80 >> index);
P1_7 = 1;
}
}
/******************************************************************************
名称:Send
功能:发送16bit到级联的2个74HC595中
参数:first,second 分别为欲发送到2个74HC595中的数据
******************************************************************************/
void send(uchar first,uchar second)
{
P1_5= 0;
base_send(first); //发送列控制码
base_send(second); //发送行控制码
P1_5= 1;
}
//---------------------------------------
void display()
{
if(j>t%8)
x=i;
else
x=(i+1)%0x15;
send(c[k],a[x][j]);
j++;
if(j==0x08)
{
j=0x00;
}
k++;
if(k==0x08)
{
k=0x00;
}
}
//---------------------------------------
void next()//字符移动
{
t++;
if(t==(0x15)*8)
{
t=0x00;
}
i=t/8;
j=t%8;
}
/******************************************************************************
名称:timer0_over
功能:定时器/计数器0溢出中断服务程序,每1秒钟更新显示一次
参数:无
******************************************************************************/
void timeover()(void) interrupt 1
{
count++;
if(count==0x40)
{
count=0x00;
next();
}
display(); //调用显示函数
TL0=0xbf; //置初值0xf0bf
TH0=0xf0;
}
//---------------------------------------
void main()
{
device_init();
while(1)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -