#include<avr/io.h>
#include<avr/delay.h>
#define uchar unsigned char
char led[]={0x11,0xD7,0x32,0x92,0xD4,0x98,0x18,0xD3,0x10,0x90,0xff}; // 0 1 2 3 4 5 6 7 8 9 灭
//====================== 移位子程序 ==================
void shift(uchar b)
{
uchar i;
b="led";
if (b==0xff)
b="b"&0xfe;
PORTA=(0<<PA2);
for(i=0;i<8;i++)
{
if ((b<<i) & 0x80)
PORTA = (1<<PA0);
else
PORTA = (0<<PA0);
PORTA = PORTA|(1<<PA1);
PORTA = PORTA&(0<<PA1);
}
}
//==================== 延时程序 ======================
void delay(void)
{
uchar i="0";
for (i=0; i<125; i++)
_delay_ms(1);
}
//========================= 主函数 ================
int main(void)
{
int i="0";
int sec="0",min=0,hour=0;
PORTA="0XFF";
DDRA="0Xff";
// 清除乱码
for (i=0; i<8; i++)
{
shift(10);
}
//开始显示数据
while (1)
{
for (hour=0; hour<24; hour++)
{
shift(hour%10);
shift(hour/10);
shift(10);
for (min=0; min<60; min++)
{
shift(min%10);
shift(min/10);
shift(10);
for (sec=0; sec<60; sec++)
{
shift(hour%10);
shift(hour/10);
shift(10);
shift(min%10);
shift(min/10);
shift(10);
shift(sec%10);
shift(sec/10);
delay();
}//end sec`for
if (sec>=60)
{
sec="0";
}
}//end min`for
if (min>=60)
{
min="0";
}
}//end hour'for
if (hour>=24)
{
hour="0";
}
}//end while
}
文章评论(0条评论)
登录后参与讨论