#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
uchar dispbuf[]; /*显示缓存*/
uchar code disptab[]={
0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,0x0f,0xf0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
sbit s1=P3^2; /*按键1*/
sbit s2=P3^3; /*按键2*/
sbit dr1=P2^0; /*DR1数据*/
sbit dr2=P2^3; /*DR2数据*/
sbit dg1=P2^1; /*DG1数据*/
sbit dg2=P2^4; /*DG2数据*/
sbit db1=P2^2; /*DB1数据*/
sbit db2=P2^5; /*DB2数据*/
sbit clk=P3^1; /*时钟*/
sbit stb=P1^7; /*锁存*/
sbit oe=P1^6; /*使能*/
sbit a=P0^0; /*A*/
sbit b=P0^1; /*B*/
sbit c=P0^2; /*c*/
uchar h=0;
void senddata(uchar data1,data2) /*发送数据,data1为1到8行数据,data2为9到16行数据,1和9、2和10~8和16行同时显示*/
{ uchar i;
for(i=0;i<8;i++)
{ if ((data1&0x01)==0)
dr1=0;
else
dr1=1;
if ((data2&0x01)==0)
dr2=0;
else
dr2=1;
_nop_();
_nop_();
clk=0;
_nop_();
_nop_();
clk=1;
data1=data1>>1;
data2=data2>>1;
}
}
void display(uchar i) /*显示子程序*/
{ senddata(disptab[i+1],disptab[i+33]);
senddata(disptab[i+2],disptab[i+34]);
senddata(disptab[i+3],disptab[i+35]);
senddata(disptab[i+4],disptab[i+36]);
}
void refresh() /*刷新子程序*/
{ oe=1;
switch (h)
{ case 0: a=0;b=0;c=0;display (0);h=1;break;
case 1: a=1;b=0;c=0;display (4);h=2;break;
case 2: a=0;b=1;c=0;display (8);h=3;break;
case 3: a=1;b=1;c=0;display (12);h=4;break;
case 4: a=0;b=0;c=1;display (16);h=5;break;
case 5: a=1;b=0;c=1;display (20);h=6;break;
case 6: a=0;b=1;c=1;display (24);h=7;break;
case 7: a=1;b=1;c=1;display (28);h=0;break;
default:break;
}
stb=1;
stb=0;
oe=0;
}
main()
{ dg1=0;
dg2=0;
db1=0;
db2=0;
while(1)
{ refresh();
}
} |