旋转led时钟程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include "STC15F104E.H"
#include "intrins.h"
#include
#include "1302.h"
#define uchar unsigned char
#define uint unsigned int
#include "IR_NEC.h"

sbit S1=P3^3;
sbit S2=P3^4;
sbit S3=P3^5;
sbit S4=P3^6;
sbit S5=P3^7;
sbit S6=P1^2;
sbit S7=P1^3;
sbit S8=P1^4;
sbit S9=P1^5;
sbit S10=P1^6;
sbit S11=P1^7;
sbit S12=P0^0;
sbit bell=P3^0;

//sbit IR=P1^1;
uchar code jiaoshidat[]={5,0x10,0x15,0x20,0x25,0x30,0x35,0x40,0x45,0x50,0x55};
uchar code leddata1[]= {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00,0x39,0x49,0x40};//12+13-
//uchar code leddata2[]= {0xbF,0x86,0xdB,0xcF,0xe6,0xeD,0xfD,0x87,0xfF,0xeF,0x00}; //有小数点
uchar dat3[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,0xff};//
uchar dat4[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};//
uchar t_led[8];//= {0};
uchar LED1,LED2,LED3,LED4;
uchar xg;
uchar tim1;
uchar tim2;
bit shan,flag2,ds;
uint temp[2];
uchar miao;
uchar fen;
uchar shi;
uchar nfen;
uchar nshi;
uchar menu;

void IRkey();
void leddisplay();
void init();
void Delayms(uint t)
{uchar i;
while(t--)
for(i=0; i<100; i++);
}
void init()
{
//TMOD=0x0;
TH0 = t0>>8;
TL0 = t0;
ET0=TR0=1;
EA=1;
/* T2L = 0xb0; //初始化计时值
T2H = 0x3c;
AUXR |= 0x10; //定时器2开始计时
IE2 |= 0x04; */ //开定时器2中断
}
void IRkey()//视宝333
{
if(IR_ok)
{ds=1;tim2=0;
/*if(OKCode==0xbf01)
{shi=0x23;fen=0x59;miao=0x58;
write_time();}
if(OKCode==0xbf02)
{shi=0;fen=0;miao=0x58;
write_time();}
*/
if(OKCode==0xbf16){uchar i;if(++xg>3)xg=0;

if(xg==0)for(i=0; i<8; i++)dat4[i]=0xff;
if(xg==1)
{dat4[0]=0xef;dat4[1]=0xbd;dat4[2]=0xf7;dat4[3]=0xde;dat4[4]=0x7b;dat4[5]=0xef;dat4[6]=0xbd;dat4[7]=0xf7;}
if(xg==2)
{dat4[0]=0xff;dat4[1]=~0x40;dat4[2]=0xff;dat4[3]=~0x20;dat4[4]=0xff;dat4[5]=~0x10;dat4[6]=0xff;dat4[7]=0xf7;}
if(xg==3)
for(i=0; i<8; i++)dat4[i]=0xff;

}


if(OKCode==0xbf5b)menu=!menu;
if(OKCode==0xbf47)if(menu)if(++menu>6)menu=1;
if(OKCode==0xbf46)if(menu)if(--menu==0)menu=6;
if(OKCode==0xbf19)
{
if(menu==1)
{
if(++shi >0x23)shi = 0;
if((shi & 0x0f) > 9) shi+=6;
}
if(menu==2)
{
if(++fen > 0x59)fen = 0;
if((fen & 0x0f) >9)fen+=6;
}
if(menu==3)
{
if(++miao > 0x59)miao = 0;
if((miao & 0x0f) >9)miao+=6;
}
if(menu==4)
{
if(++yue > 0x12)yue = 0x1;
if((yue & 0x0f) >9)yue+=6;
}

if(menu==5)
{
if(++ri > 0x31)ri = 0x1;
if((ri & 0x0f) >9)ri+=6;
}
if(menu==6)if (++jiaoshi>21)jiaoshi=11;
write_time();
}
if(OKCode==0xbf1d)
{


if(menu==1)
{
if(--shi >0x23)shi =0x23;
if((shi & 0x0f) > 9) shi-=6;
}
if(menu==2)
{
if(--fen > 0x59)fen =0x59;
if((fen & 0x0f) >9)fen-=6;
}
if(menu==3)
{
if(--miao > 0x59)miao = 0x59;
if((miao & 0x0f) >9)miao-=6;
}
if(menu==4)
{
if(--yue == 0)yue = 0x12;
if((yue & 0x0f) >9)yue-=6;
}

if(menu==5)
{
if(--ri > 0x31)ri = 0x31;
if((ri & 0x0f) >9)ri-=6;
}



if(menu==6)if (--jiaoshi>21)jiaoshi=11;
write_time();
}
IR_ok=0;
}
}


void InitTimer1() interrupt 1
{ static uint t;
NEC();
if(++t>=5000)
{
t=0;
shan=!shan;
if(++tim1>22)tim1=0;
if(tim1>15)flag2=1;
else flag2=0;
if(++tim2>60)ds=0;
}
}


void leddisplay()
{ uchar i;
if(menu==0)
{

if(flag2==1)
{if(yue/16)
LED1=yue/16;
else LED1=10;
LED2=yue%16;
LED3=ri/16;
LED4=ri%16;
}
if(flag2==0)
{ if(shi/16)
LED1=shi/16;else LED1=10;
LED2=shi%16;
LED3=fen/16;
LED4=fen%16;
}

}
if(menu==1)
{
if(shan)
{
LED1=shi/16;
LED2=shi%16;
}
else
{
LED1=10;//不显示
LED2=10;//不显示
}
LED3=fen/16;
LED4=fen%16;
}
if(menu==2)
{
if(shan)
{
LED3=fen/16;
LED4=fen%16;
}
else
{
LED3=10;
LED4=10;
}
LED1=shi/16;
LED2=shi%16;
}
if(menu==3)
{
if(shan)
{
LED1=shi/16;
LED2=shi%16;
LED3=fen/16;
LED4=fen%16;
}
else
{
LED1=10;
LED2=10;
LED3=10;
LED4=10;
}
}
if(menu==4)
{
if(shan)
{if(yue/16)
LED1=yue/16;
else LED1=10;
LED2=yue%16;
}
else
{
LED1=10;//不显示
LED2=10;//不显示
}
LED3=ri/16;
LED4=ri%16;
}
if(menu==5)
{
if(shan)
{

LED3=ri/16;
LED4=ri%16;
}
else
{
LED3=10;
LED4=10;
}
if(yue/16)
LED1=yue/16;
else LED1=10;
LED2=yue%16;
}



if(menu==6)
{
if(jiaoshi>11)
{LED1=12;
LED2=10;
LED3=(jiaoshidat[jiaoshi-12])/16;
LED4=(jiaoshidat[jiaoshi-12])%16;
}
if(jiaoshi<11)
{LED1=13;
LED2=10;
LED3=(jiaoshidat[10-jiaoshi])/16;
LED4=(jiaoshidat[10-jiaoshi])%16;

}
if(jiaoshi==11)
{LED1=LED2=10;LED3=LED4=0;}

}

if(xg==0)
{
dat3[0]=0xFE;dat3[1]=0xFC;dat3[2]=0xF8;dat3[3]=0xF0;dat3[4]=0xE0;dat3[5]=0xC0;dat3[6]=0x80;dat3[7]=0x00;dat3[8]=0xFF;

if(miao>0x56){for(i=0; i<7; i++)t_led[i]=7;t_led[7]=(miao/16*10+miao%16-1)%8;}
if(miao>0x48&&miao<=0x56){for(i=0; i<6; i++)t_led[i]=7;t_led[6]=(miao/16*10+miao%16-1)%8;}
if(miao>0x40&&miao<=0x48){for(i=0; i<5; i++)t_led[i]=7;t_led[5]=(miao/16*10+miao%16-1)%8;}
if(miao>0x32&&miao<=0x40){for(i=0; i<4; i++)t_led[i]=7;t_led[4]=(miao/16*10+miao%16-1)%8;}
if(miao>0x24&&miao<=0x32){for(i=0; i<3; i++)t_led[i]=7;t_led[3]=(miao/16*10+miao%16-1)%8;}
if(miao>0x16&&miao<=0x24){for(i=0; i<2; i++)t_led[i]=7;t_led[2]=(miao/16*10+miao%16-1)%8;}
if(miao>0x08&&miao<=0x16){t_led[0]=7;t_led[1]=(miao/16*10+miao%16-1)%8;}
if(miao>0x00&&miao<=0x08){for(i=1; i<8; i++)t_led[i]=8;t_led[0]=(miao/16*10+miao%16-1)%8;}
if(miao==0x00)for(i=0; i<8; i++)t_led[i]=7;
}


else
{
dat3[0]=0xFE; dat3[1]=0xFD; dat3[2]=0xFB; dat3[3]=0xF7; dat3[4]=0xEF; dat3[5]=0xDF; dat3[6]=0xBF; dat3[7]=0x7F; dat3[8]=0xFF;

for(i=0; i<8; i++) t_led[i]=8;
if(miao>0x56 ){t_led[7]=(miao/16*10+miao%16-1)%8;}
if(miao>0x48&&miao<=0x56){t_led[6]=(miao/16*10+miao%16-1)%8;}
if(miao>0x40&&miao<=0x48){t_led[5]=(miao/16*10+miao%16-1)%8;}
if(miao>0x32&&miao<=0x40){t_led[4]=(miao/16*10+miao%16-1)%8;}
if(miao>0x24&&miao<=0x32){t_led[3]=(miao/16*10+miao%16-1)%8;}
if(miao>0x16&&miao<=0x24){t_led[2]=(miao/16*10+miao%16-1)%8;}
if(miao>0x08&&miao<=0x16){t_led[1]=(miao/16*10+miao%16-1)%8;}
if(miao>0x00&&miao<=0x08){t_led[0]=(miao/16*10+miao%16-1)%8;}
if(miao==0x00)t_led[7]=3;
}
P2=leddata1[LED1];
S1=0;
Delayms(2);
S1=1;

if(shan|flag2)P2=leddata1[LED2];
else P2=leddata1[LED2]|0x80;
S2=0;
Delayms(2);
S2=1;

P2=leddata1[LED3];
S3=0;
Delayms(2);
S3=1;

P2=leddata1[LED4];
S4=0;
Delayms(2);
S4=1;

//////////////////////////////////////////////////////
P2=dat3[t_led[0]]&dat4[0]; S5=1;
Delayms(2);
S5=0;

P2=dat3[t_led[1]]&dat4[1]; S6=1;
Delayms(2);
S6=0;

P2=dat3[t_led[2]]&dat4[2]; S7=1;
Delayms(2);
S7=0;

P2=dat3[t_led[3]]&dat4[3]; S8=1;
Delayms(2);
S8=0;

P2=dat3[t_led[4]]&dat4[4]; S9=1;
Del

ayms(2);
S9=0;

P2=dat3[t_led[5]]&dat4[5]; S10=1;
Delayms(2);
S10=0;

P2=dat3[t_led[6]]&dat4[6]; S11=1;
Delayms(2);
S11=0;

P2=dat3[t_led[7]]&dat4[7]; S12=1;
Delayms(2);
S12=0;

}
void main()
{
init();
read_nao();
P3M0=0xf8;
P3M1=0x00;
P2M0=0xff;
P2M1=0x00;
P1M0=0xfd;
P1M1=0x00;
P0M0=0x01;
P0M1=0x00;
IR=1;ri_tmp=0xff;
while(1)
{
IRkey();
read_time();
if(ri_tmp!=ri&&shi==0&&(fen==1))
{
if(jiaoshi>11)
{miao=jiaoshidat[jiaoshi-12];
write_time();}
else if(jiaoshi<11)
{miao=jiaoshidat[jiaoshi];
fen=0;write_time();}
ri_tmp=ri;
}
if(~ds)menu=0;
leddisplay();
}
}

相关文档
最新文档