高级会员
主题
回帖0
积分517
阅读权限30
注册时间2012-4-17
最后登录1970-1-1
在线时间 小时
|
楼主 |
发表于 2012-6-15 18:25
|
显示全部楼层
#include <reg51.H>
#define uchar unsigned char
#define uint unsigned int
uchar yid,h;
uint zimuo;
uchar code hanzi[];
uchar i,d=10;
uchar BUFF[4];
void in_data(void);
void rxd_data(void);
void scan();
void sbuf_out();
sbit key=P1^7;
sbit key1=P3^7;
sbit key2=P3^6;
uchar code table[]={
0x80,0x00,0x80,0x00,0x80,0x00,0xFC,0x1F,0x84,0x10,0x84,0x10,0xFC,0x1F,0x84,0x10,
0x84,0x10,0x84,0x10,0xFC,0x1F,0x84,0x10,0x80,0x40,0x80,0x40,0x00,0x7F,0x00,0x00,/*"电",0*/
0x10,0x00,0x10,0x00,0xF8,0x7F,0x08,0x00,0x04,0x00,0xF2,0x1F,0x00,0x00,0xF8,0x0F,
0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x50,0x00,0x50,0x00,0x60,0x00,0x40,/*"气",1*/
0x00,0x00,0xFC,0x3F,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,
0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xFF,0x7F,0x00,0x00,0x00,0x00,/*"工",2*/
0xB0,0x1F,0x8E,0x10,0x88,0x10,0x88,0x10,0xBF,0x10,0x88,0x1F,0x0C,0x00,0xDC,0x3F,
0x2A,0x02,0x0A,0x02,0xC9,0x3F,0x08,0x02,0x08,0x02,0x08,0x02,0xE8,0x7F,0x08,0x00,/*"程",3*/};
void delay1s(unsigned int count) //软件延时
{
for(;count>0;count--){;}
}
void main(void)
{
yid=0;
zimuo=0;
while(1)
{
while(yid<16)
{
scan();
for(i=0;i<d;i++)
{
sbuf_out();
}
yid++;
}
yid=0;
zimuo=zimuo+32;
if(zimuo>=96)
zimuo=0;
}
}
void sbuf_out()
{
for(h=0;h<16;h++)
{
in_data();
rxd_data();
P1=0x7f;
key=1;
P1=h;
}
}
void in_data(void)
{
char s;
for(s=1;s>=0;s--)
{
BUFF[2*s+1]=table[zimuo+1+32*s+2*h];
BUFF[2*s]=table[zimuo+32*s+2*h];
}
}
void rxd_data(void)
{
char s;
uchar inc,tempyid,temp;
if(yid<8)
inc=0;
else
inc=1;
for(s=0+inc;s<2+inc;s++)
{
if(yid<8)
tempyid=yid;
else
tempyid=yid-8;
temp=(BUFF<<tempyid)|(BUFF[s+1]>>(8-tempyid));//右移算法。如果改成temp=(BUFF>>tempyid)|(BUFF[s+1]<<(8-tempyid));// 左移一切显示正常。
SBUF=temp;while(!TI);
TI=0;
}
}
void scan()
{
if(key1==0)
{delay1s(20);
if(key1==0)d--;
while(!key1);
}
if(key2==0)
{delay1s(20);
if(key2==0)d++;
while(!key2);
}
} |
|