* 目 的:電子時(shí)鐘的純軟件模擬** 功 能:實(shí)現(xiàn)時(shí)鐘的功能
* 時(shí)鐘頻率:內(nèi)部4M *
* 編譯環(huán)境:ICC-AVR7 *
本文引用地址:http://m.butianyuan.cn/article/201611/318912.htm*圖見上一篇日志*
#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) //延時(shí)1ms
{
uint i,j;
for(i=0;i for(j=0;j<564;j++);
}
void display(uchar i, uchar j) //數(shù)碼管顯示時(shí)間
{
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() //顯示的時(shí)間數(shù)據(jù)送到temp數(shù)組保存
{
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();
}
}
}
評(píng)論