/**************************************************************************************
* ½»í¨μÆêμÑé *
êμÏÖÏÖÏó£oÏÂÔØ3ìDòo󣬰′ÕÕêóÆμ2ù×÷Õyè·½óÏߣ¬3êÏÖ½»í¨μÆÏÖÏó
×¢òaêÂÏî£o
***************************************************************************************/
#include "stc15.h" //′ËÎļtÖD¶¨òåáËμ¥Ƭ»úμÄò»D©ìØêa1|Äü¼Ä′æÆ÷
typedef unsigned int u16; //¶Ôêy¾YààDí½øDDéùÃ÷¶¨òå
typedef unsigned char u8;
u8 code DuanMa[10]={
// 0 1 2 3 4 5 6 7 8 9
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
u8 Second;
/*******************************************************************************
* oˉ êy Ãû : Delay5ms()
* oˉêy1|Äü : Ñóê±oˉêy£¬′óÔ¼Ñóê±5Ms
*******************************************************************************/
void Delay5ms() //@11.0592MHz
{
unsigned char i, j;
i = 54;
j = 199;
do
{
while (--j);
} while (--i);
}
/*******************************************************************************
* oˉ êy Ãû : Timer0Init
* oˉêy1|Äü : ¶¨ê±Æ÷03õê¼»ˉ
* êä èë : ÎT
* êä 3ö : ÎT
*******************************************************************************/
void Timer0Init()
{
TMOD|=0X01;//Ñ¡ÔñÎa¶¨ê±Æ÷0ģ꽣¬1¤×÷·½ê½1£¬½öóÃTR0′ò¿aÆô¶ˉ¡£
TH0=0XFC; //¸ø¶¨ê±Æ÷¸33õÖ죬¶¨ê±1ms
TL0=0X18;
ET0=1;//′ò¿a¶¨ê±Æ÷0ÖD¶ÏÔêDí
EA=1;//′ò¿a×üÖD¶Ï
TR0=1;//′ò¿a¶¨ê±Æ÷
}
void GPIO_Init() //3õê¼»ˉI/O¿ú
{
P0M1=0;
P0M0=0;
P1M1=0;
P1M0=0;
P2M1=0;
P2M0=0;
P3M1=0;
P3M0=0;
P4M1=0;
P4M0=0;
P5M1=0;
P5M0=0;
}
/*******************************************************************************
* oˉ êy Ãû : main
* oˉêy1|Äü : Ö÷oˉêy
* êä èë : ÎT
* êä 3ö : ÎT
*******************************************************************************/
void main()
{
GPIO_Init();
// Second = 1;
Timer0Init();
// if(67<Second&&Second)
// { Second=1;
// }
while(1)
{
if(1<Second&&Second<=30)
{
P20=0;P21=1;P22=1;P23=1;
P0=DuanMa[(30-Second)/10];
Delay5ms();
P20=1;P21=0;P22=1;P23=1;
P0=DuanMa[(30-Second)%10];
Delay5ms();
P20=1;P21=1;P22=0;P23=1;
P0=DuanMa[(34-Second)/10];
Delay5ms();
P20=1;P21=1;P22=1;P23=0;
P0=DuanMa[(34-Second)%10];
Delay5ms();
P25=0;P41=0;P43=1;P24=1;
}
if(30<Second&&Second<=34)
{
P20=0;P21=1;P22=1;P23=1;
P0=DuanMa[(34-Second)/10];
Delay5ms();
P20=1;P21=0;P22=1;P23=1;
P0=DuanMa[(34-Second)%10];
Delay5ms();
P20=1;P21=1;P22=0;P23=1;
P0=DuanMa[(34-Second)/10];
Delay5ms();
P20=1;P21=1;P22=1;P23=0;
P0=DuanMa[(34-Second)%10];
Delay5ms();
P25=1;P26=0;P41=0;P24=1;
}
if(34<Second&&Second<=63)
{
P20=1;P21=1;P22=0;P23=1;
P0=DuanMa[(63-Second)/10];
Delay5ms();
P20=1;P21=1;P22=1;P23=0;
P0=DuanMa[(63-Second)%10];
Delay5ms();
P20=0;P21=1;P22=1;P23=1;
P0=DuanMa[(67-Second)/10];
Delay5ms();
P20=1;P21=0;P22=1;P23=1;
P0=DuanMa[(67-Second)%10];
Delay5ms();
P26=1;P41=1;P42=0;P24=0;
}
if(63<Second&&Second<=67)
{
P20=0;P21=1;P22=1;P23=1;
P0=DuanMa[(67-Second)/10];
Delay5ms();
P20=1;P21=0;P22=1;P23=1;
P0=DuanMa[(67-Second)%10];
Delay5ms();
P20=1;P21=1;P22=0;P23=1;
P0=DuanMa[(67-Second)/10];
Delay5ms();
P20=1;P21=1;P22=1;P23=0;
P0=DuanMa[(67-Second)%10];
Delay5ms();
P42=1;P43=0;P24=0;
}
if(67<Second)
{ Second=1;
}
}
}
/*******************************************************************************
* oˉ êy Ãû : void Timer0() interrupt 1
* oˉêy1|Äü : ¶¨ê±Æ÷0ÖD¶Ïoˉêy
* êä èë : ÎT
* êä 3ö : ÎT
*******************************************************************************/
void Timer0() interrupt 1
{
static u16 i;
TH0=0XFC; //¸ø¶¨ê±Æ÷¸33õÖ죬¶¨ê±1ms
TL0=0X18;
i++;
if(i==1000)
{
i=0;
Second ++;
}
}
|