|
楼主 |
发表于 2009-12-1 17:28:19
|
显示全部楼层
改用32.768K晶振,已经通过测试
照片晚些时候贴出来
演示程序:
在原来程序上稍稍修改而已
没有注释不好意思,以后有空时再补上
2009-12-01 修改内容,将原T1定时器初始化、中断程序改为T2的
/**********************************************/
/* LED_Clock_test_1 */
/* ATmaga48V-10AU @ 1MHz */
/* 2009-11-05 */
/* h2feo4 */
/* www.ourdev.cn */
/**********************************************/
//================= include ==================//
// winavr-20081124
#include <avr/io.h>
#include <avr/interrupt.h>
//================== define ==================//
volatile unsigned char sec = 0, min = 0, hou = 12;
const unsigned char oring[62] = {12, 1, 9, 11, 8, 1, 2, 10, 12, 9, 2, 3, 11, 1, 10, 3, 4, 12, 2, 11, 4, 5, 1, 3, 12, 5, 6, 2, 4, 1, 6, 7, 3, 5, 2, 7, 8, 4, 6, 3, 8, 9, 5, 7, 4, 9, 10, 6, 8, 5, 10, 11, 7, 9, 6, 11, 12, 8, 10, 7, 12, 1};
const unsigned char iring[14] = {7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8};
//=================== init ===================//
void t0_init(void)
{
TCCR0B = (1 << CS00);
}
void t2_init(void)
{
ASSR = (1 << AS2);
TCCR2B = (1 << CS22) | (1 << CS20);
TIFR2 = 0xff;
TIMSK2 = (1 << TOIE2);
}
void port_init(void)
{
PORTB &= 0xc0;
PORTC &= 0xc0;
DDRB &= 0xc0;
DDRC &= 0xc0;
}
//================ interrupt =================//
ISR(TIMER2_OVF_vect)
{
sec++;
if (sec >= 60)
{
sec = 0;
min++;
}
if (min >=60)
{
min = 0;
hou++;
}
if (hou >12)
{
hou = 1;
}
}
//=================== sub ====================//
void disp_sec(void)
{
DDRB &= 0xc0;
DDRC &= 0xc0;
PORTB &= 0xc0;
PORTC &= 0xc0;
if (oring[sec] <= 6)
{
PORTB |= (1 << (6 - oring[sec]));
DDRB |= (1 << (6 - oring[sec]));
}
else
{
PORTC |= (1 << (12 - oring[sec]));
DDRC |= (1 << (12 - oring[sec]));
}
if (oring[sec + 1] <= 6)
{
DDRB |= (1 << (6 - oring[sec + 1]));
}
else
{
DDRC |= (1 << (12 - oring[sec + 1]));
}
}
void disp_min(void)
{
DDRB &= 0xc0;
DDRC &= 0xc0;
PORTB &= 0xc0;
PORTC &= 0xc0;
if (oring[min] <= 6)
{
DDRB |= (1 << (6 - oring[min]));
}
else
{
DDRC |= (1 << (12 - oring[min]));
}
if (oring[min + 1] <= 6)
{
PORTB |= (1 << (6 - oring[min + 1]));
DDRB |= (1 << (6 - oring[min + 1]));
}
else
{
PORTC |= (1 << (12 - oring[min + 1]));
DDRC |= (1 << (12 - oring[min + 1]));
}
}
void disp_hou(void)
{
DDRB &= 0xc0;
DDRC &= 0xc0;
PORTB &= 0xc0;
PORTC &= 0xc0;
if (iring[hou] <= 6)
{
PORTC |= (1 << (6 - iring[hou]));
DDRC |= (1 << (6 - iring[hou]));
DDRB |= (1 << (6 - iring[hou]));
}
else
{
PORTB |= (1 << (12 - iring[hou]));
DDRC |= (1 << (12 - iring[hou]));
DDRB |= (1 << (12 - iring[hou]));
}
}
//=================== main ===================//
int main(void)
{
port_init();
t0_init();
t2_init();
sei ();
while(1)
{
disp_sec();
while(TIFR0 == 0);
TIFR0 = 0xff;
disp_min();
while(TIFR0 == 0);
TIFR0 = 0xff;
disp_hou();
while(TIFR0 == 0);
TIFR0 = 0xff;
}
return 0;
} |
|