代码:
/*******************************************************
This program was created by the
CodeWizardAVR V3.12 Advanced
Automatic Program Generator
?Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 2024/6/7
Author :
Company :
Comments:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*******************************************************/
#include <mega16.h>
// Declare your global variables here
typedef unsigned char uchar;
typedef unsigned int uint;
flash uchar led_7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f};
flash uchar position[6]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
uchar time[3];
uchar dis_buff[6];
uint time_counter;
uchar posit;
bit point_on,time_1s_ok;
void display(void)
{
PORTD=0xff;
PORTC=led_7[dis_buff[posit]];
if(point_on && (posit==2 || posit==4))
PORTC|=0X80;
PORTD=position[posit];
if(++posit>=6) posit=0;
}
interrupt [TIM0_COMP] void timer0_comp_isr(void)
{
display();
if(++time_counter>=500)
{
time_counter=0;
time_1s_ok=1;
}
}
void time_to_disbuffer(void)
{
uchar i,j=0;
for(i=0;i<=2;i++)
{
dis_buff[j++]=time[i]%10;
dis_buff[j++]=time[i]/10;
}
}
void main(void)
{
PORTC=0;
DDRC=0XFF;
PORTD=0X3F;
DDRD=0X3F;
TCCR0=0X0B;
TCNT0=0;
OCR0=0X7C;
TIMSK=2;
time[2]=23;time[1]=58;time[0]=55;
posit=0;
time_to_disbuffer();
#asm("sei");
while(1)
{
if(time_1s_ok)
{
time_1s_ok=0;
point_on=~point_on;
if(++time[0]>=60)
{
time[0]=0;
if(++time[1]>=60)
{
time[1]=0;
if(++time[2]>=24)time[2]=0;
}
}
time_to_disbuffer();
}
}
}
仿真效果图:


1772

被折叠的 条评论
为什么被折叠?



