找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

基于51单片机的LED旋转显示器(旋转时钟)

[复制链接]
admin 发表于 2012-9-2 06:52:01 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
程序如下:#include<reg52.h>

unsigned char code shuzi_0[8]={0x82,0x7C,0x7C,0x7C,0x7C,0x7C,0x82,0xfe};/*"0",0*/
unsigned char code shuzi_1[8]={0xfe,0x7e,0x7a,0x00,0x7e,0x7e,0xfe,0xfe};/*"1",1*/
unsigned char code shuzi_2[8]={0x3a,0x3c,0x5c,0x5c,0x6c,0x6c,0x72,0xfe};/*"2",2*/
unsigned char code shuzi_3[8]={0xba,0x7c,0x7c,0x6c,0x6c,0x6c,0x92,0xfe};/*"3",3*/
unsigned char code shuzi_4[8]={0x9e,0xae,0xb6,0xba,0x00,0xbe,0xbe,0xfe};/*"4",4*/
unsigned char code shuzi_5[8]={0xa0,0x6c,0x6c,0x6c,0x6c,0x6c,0x9c,0xfe};/*"5",5*/
unsigned char code shuzi_6[8]={0x82,0x6c,0x6c,0x6c,0x6c,0x6c,0x9a,0xfe};/*"6",6*/
unsigned char code shuzi_7[8]={0xfc,0xfc,0xfc,0x0c,0xf4,0xf8,0xfc,0xfe};/*"7",7*/
unsigned char code shuzi_8[8]={0x92,0x6c,0x6c,0x6c,0x6c,0x6c,0x92,0xfe};/*"8",8*/
unsigned char code shuzi_9[8]={0xb2,0x6c,0x6c,0x6c,0x6c,0x6c,0x82,0xfe};/*"9",9*/
unsigned char code fuhao_A[8]={0xfe,0xfe,0xba,0xba,0xfe,0xfe,0xfe,0xfe};/*":",10*/
/*******************************************************************************************************************************/
unsigned char code hanzi_a[2][16]={0xf7,0x37,0x47,0x70,0x17,0x73,0xb7,0xbd,0xdd,0xdd,0xed,0xe5,0xc9,0xdd,0xbf,0xff,
0xf7,0xe7,0xf7,0xf7,0x00,0xfb,0xbb,0xbd,0xbd,0xbd,0x81,0xbd,0xbc,0x9d,0xbf,0xff};/*轻*/
unsigned char code hanzi_b[2][16]={0xff,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0x03,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xff,0xff,
0xdf,0xdf,0xdf,0xdf,0xdf,0xdf,0xdf,0xc0,0xdf,0xdf,0xdf,0xdf,0xdf,0xdf,0xdf,0xff};/*工*/
unsigned char code hanzi_c[2][16]={0xfb,0xcb,0x3d,0xfb,0x3b,0xc3,0xdf,0xef,0xf0,0x17,0xf7,0xf7,0xd7,0xe7,0xff,0xff,
0xef,0xf7,0xf9,0xfe,0x7d,0x73,0xbf,0xcf,0xf3,0xfc,0xf3,0xef,0x9f,0x3f,0xbf,0xff};/*欢*/
unsigned char code hanzi_d[2][16]={0xbf,0xbd,0xbb,0x37,0xff,0x03,0xfb,0xfd,0x7d,0x03,0xfb,0xfb,0xfb,0x01,0xfb,0xff,
0xff,0xbf,0xdf,0xe0,0xdf,0xb8,0xbd,0xbe,0xbf,0x80,0xbf,0xbd,0xbb,0x9c,0xdf,0xff};/*迎*/
unsigned char code hanzi_e[2][16]={0xbf,0xdf,0xef,0x03,0xdc,0xef,0x73,0x98,0xfb,0x0b,0xfb,0xbb,0x6b,0x73,0xff,0xff,
0xbf,0xcf,0xff,0x88,0x7f,0x7e,0x77,0x6d,0x4b,0x7c,0x7f,0x1f,0xff,0xee,0x9f,0xff};/*您*/

//unsigned char bt=0; //定时器1中断计数
unsigned int Tcz=600,s=0,bt=0;//s表示中断次数 ,Tcz表示定时器TO的初值
unsigned char iDex=0,hiDex; //8列控制,把旋转一周的180个显示位置分成22.5块。一块为一个显示单位
unsigned char Hour=10,Minute=15,Second=45,Hour_Flag=0,buffer=0;
void hanzi_Show(unsigned char m);
void Time_Show(unsigned char m); //数字0-9加:显示函数
void Time_Amend(); //时间逻辑控制函数
void Hour_Display(); //小时显示函数
void Minute_Display(); //分钟显示函数
void Second_Display(); //秒钟显示函数
void A_Display(); //“:”显示函数
void Init(); //初始化函数
int k=0; //校正值
void INT00(void)interrupt 0 //外部中断服务函数,用于定位和定时器0初值校正
{ //k为校正值,当定时中断过快,K 变大,Tcz同时变大,定时器初值变大,中断变慢;
k=s-180;
Tcz=Tcz+k;
iDex=0;
hiDex=0;
s=0; //定时器中断次数清零,显示第二周
}
void kjp_test(void)interrupt 1 //定时器中断0中断服务程序。
{ TH0=(-Tcz)/256;
TL0=(-Tcz)%256;
if(buffer==0) //buffer 用来控制显示模式
{
if(hiDex>=16){hiDex=0;} //显示模式选择,1为数字式,这个我想的是用遥控起来控制显示模式
if(iDex>=8){iDex=0;}
if(s==(Second*3)) //秒钟
{
P0=0X00;P1=0X00;
}
else
{
P0=0XFE;P1=0XFF;
}

if(s==(Minute)*3) //分
{
P0=0XF0;P1=0X00;
}
else
{
P0=0XFE;P1=0XFF;
}

if(s==(Hour*15+Minute/4)) //时
{
P0=0XFF;P1=0X00;
}
else
{
P0=0XFE;P1=0XFF;
}

}
s++;

}

void Time_luoji()interrupt 3
{ TH1=(65535-20000)/256; //定时器1初值定为20毫秒
TL1=(65535-20000)%256;
bt++;
if(bt==50) //就是这里有问题,我定50次应该是秒数自加一,
{ // 但是实际却很快,所以我定的500次
bt=0;
Second++;
Time_Amend();

}
}
void Time_Show(unsigned char m)
{
switch (m)
{
case 0 :P0=0xff; P0=shuzi_0[iDex];iDex++;P2=0xff;break;
case 1 :P0=0xff; P0=shuzi_1[iDex];iDex++;P2=0xff;break;
case 2 :P0=0xff; P0=shuzi_2[iDex];iDex++;P2=0xff;break;
case 3 :P0=0xff; P0=shuzi_3[iDex];iDex++;P2=0xff;break;
case 4 :P0=0xff; P0=shuzi_4[iDex];iDex++;P2=0xff;break;
case 5 :P0=0xff; P0=shuzi_5[iDex];iDex++;P2=0xff;break;
case 6 :P0=0xff; P0=shuzi_6[iDex];iDex++;P2=0xff;break;
case 7 :P0=0xff; P0=shuzi_7[iDex];iDex++;P2=0xff;break;
case 8 :P0=0xff; P0=shuzi_8[iDex];iDex++;P2=0xff;break;
case 9 :P0=0xff; P0=shuzi_9[iDex];iDex++;P2=0xff;break;
case 10 :P0=0xff; P0=fuhao_A[iDex];iDex++;P2=0xff;break;
}
}
void hanzi_Show(unsigned char m)
{
switch (m)
{
case 0 :P0=0xff; P0=hanzi_a[0][hiDex];P2=0xff;P2=hanzi_a[1][hiDex];hiDex++;break; //轻
case 1 :P0=0xff; P0=hanzi_b[0][hiDex];P2=0xff;P2=hanzi_b[1][hiDex];hiDex++;break; //工
case 2 :P0=0xff; P0=hanzi_c[0][hiDex];P2=0xff;P2=hanzi_c[1][hiDex];hiDex++;break; //欢
case 3 :P0=0xff; P0=hanzi_d[0][hiDex];P2=0xff;P2=hanzi_d[1][hiDex];hiDex++;break; //迎
case 4 :P0=0xff; P0=hanzi_e[0][hiDex];P2=0xff;P2=hanzi_e[1][hiDex];hiDex++;break; //您
}
}


void A_Display()
{
Time_Show(10);
}

void Hour_Display()
{ //显示小时
unsigned char m=0,n=0;
m=Hour/10;
n=Hour%10;
if(s<8)
Time_Show(m);
else
Time_Show(n);
}

void Minute_Display()
{
unsigned char m=0,n=0; //显示分
m=Minute/10;
n=Minute%10;
if(s<32)
Time_Show(m);
else
Time_Show(n);
}

void Second_Display()
{
unsigned char m=0,n=0; //显示秒
m=Second/10;
n=Second%10;
if(s<56)
Time_Show(m);
else
Time_Show(n);
}

void Time_Amend()
{
if(Second>=60) //时间逻辑控制
{
Second=0;
Minute++;
if(Minute>=60)
{
Minute=0;
Hour++;
if(Hour>=24)
Hour=0;
}
}
}

void Init()
{
// TMOD|=0x01;
// TMOD&=0xfd; //定时器/计数器的方式控制字。将T0设为方式2
// TMOD|=0x10;
// TMOD&=0xdf; //定时器/计数器的方式控制字。将T1设为方式2
TMOD=0x11;
EA=1; //中断允许控制
ET0=1; //定时器/计数器T0的中断允许位
ET1=1; //定时器/计数器T1的中断允许位
TH0=(65535-600)/256; //定时初值,5MS
TL0=(65535-600)%256;
TH1=(65535-50000)/256; //定时器1初值
TL1=(65535-50000)%256;
TR0=1; //定时器/计数器T0的启动
TR1=1;
EX0=1;
// EX1=1; //INT0中断允许控制位
IT0=1;
IT1=1; //控制寄存器TCON
PT1=1; //设置定时器T1中断先级为高,防止T0中断中出现,不处理T1中断服务程序
// PX1=1;
}

void main()
{
Init();
while(1)
{
;
}
}



[ 此帖被tanghua718在2010-12-10 15:22重新编辑 ]


led选装显示器.doc (3.73 MB, 下载次数: 3)
5_111576_2fc9f82be259d0a.jpg 5_111576_847c98e6126c64d.jpg 5_111576_0049a83f4c7d0d3.jpg 5_111576_c8858602cd70ad9.jpg
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 05:17 , Processed in 0.058515 second(s), 12 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表