|
楼主 |
发表于 2009-11-5 16:38:14
|
显示全部楼层
最新照片
(原文件名:20091105A.JPG)
焊这些LED比想象中要容易得多
所有LED都是红色,手里只有红色的,懒得出去买了
限流电阻手里没有合适阻值的0603封装的,用0402代替
手里没有m48pa,用m48v代替
32.768K晶振偷懒没有装
程序上也十分偷懒
时钟是从RC振荡器分频出来的
算法也懒得编所以用查表了
没有进行任何优化,部分小错误也懒得修改了
代码:
/**********************************************/
/* 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 int sec = 0, min = 0, hou = 12;
const unsigned int 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 int 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 t1_init(void)
{
TCCR1B |= (1 << WGM12) | (1 << CS11) | (1 << CS10);
TIMSK1 |= (1 << OCIE1A);
OCR1A = 15624;
}
void port_init(void)
{
PORTB &= 0xc0;
PORTC &= 0xc0;
DDRB &= 0xc0;
DDRC &= 0xc0;
}
//================ interrupt =================//
ISR(TIMER1_COMPA_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 ===================//
void main(void)
{
port_init();
t0_init();
t1_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;
}
} |
|