* 目 的:电子时钟的纯软件模仿*
* 功 能:完成时钟的功用
* 时钟频率:内部4M *
* 编译环境:ICC-AVR7 *
*图见上一篇日志*
#include
#include
#define uint unsigned int
#define uchar unsigned char
#define on_138 PORTC|=BIT(PC7) //on or off 138
#define off_138 PORTC&=~BIT(PC7)
#pragma data:code
uchar flash table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //the data for display
uchar flash site[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
uchar time[3];
uchar temp[6];
void delay(uint ms) //延时1ms
{
uint i,j;
for(i=0;i for(j=0;j<564;j++);
}
void display(uchar i, uchar j) //数码管显现时刻
{
if(i==1||i==3)
{
PORTA=site[i];
PORTB=table[j];
PORTB|=0X80;
}
else
{
PORTA=site[i];
PORTB=table[j];
}
delay(1);
}
void time_to_temp() //显现的时刻数据送到temp数组保存
{
uchar i,j=0;
for(i=0;i<3;i++)
{
temp[j++]=time[i];
temp[j++]=time[i]/10;
}
}
void inti() //初始化io口
{
DDRA=0X07;
DDRB=0XFF;
DDRC=0X80;
}
void main()
{
uchar i,time_count=0;
time[0]=0;
time[1]=26;
time[2]=19;
time_to_temp();
inti();
while(1)
{
for(i=0;i<6;i++)
{
on_138;
display(i,temp[5-i]);
off_138;
}
if(++time_count>=166)
{
time_count=0;
if(++time[0]>=60)
{
time[0]=0;
if(++time[1]>=60)
{
time[1]=0;
if(++time[2]>=24)
{
time[2]=0;
}
}
}
time_to_temp();
}
}
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/news/dongtai/264389.html