用AVR纯软件模拟电子时钟
时间:11-20
来源:互联网
点击:
* 目 的:电子时钟的纯软件模拟*
#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();
}
}
}
* 功
* 时钟频率:内部4M *
* 编译环境:ICC-AVR7 *
*图见上一篇日志*
#include
#include
#define uchar unsigned char
#define on_138
#define off_138 PORTC&=~BIT(PC7)
#pragma data:code
uchar
uchar
uchar time[3];
uchar temp[6];
void delay(uint ms)
{
}
void display(uchar i, uchar j)
{
}
void time_to_temp()
{
}
void inti()
{
}
void main()
{
}
AVR纯软件模拟电子时 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)