模拟指针式时钟
本帖最后由 迷你强 于 2013-1-31 22:43 编辑由132个双LED(围成三个圆圈,外面两圈分别是60个,最里面一圈是12个,从内到外分别表示时针、分针、秒针 )
当年提供给女友的毕业设计,后经过几次翻转思索查询下制作完成。
嘻嘻,具体不介绍了,看附件把。
重新整理原理图附近
程序在此。。。出自他人。
#include <avr/io.h>
#include <avr/interrupt.h>
volatile unsigned char seconds= 0, minutes = 0, hour = 12;
const unsigned char ORING = {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 = {7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8};
unsigned char MODE_D;
unsigned char we_D;
/* 微秒级延时程序 */
void delay_us(int time)//245*time 微秒
{
do
{
time--;
}
while (time>1);
}
void t1_init(void)
{
TCCR1B|=(1<<CS10)|(1<<WGM12);
TIMSK|=(1<< OCIE1A);
OCR1A = 32768;
}
void port_init(void)
{
PORTB |=~0xc7;
PORTC &= 0xc0;
PORTD &= 0xc0;
DDRB&= 0xc7;
DDRC&= 0xc0;
DDRD&= 0xc0;
}
//=================== sub ====================//
void disp_seconds(void)
{
DDRD&= 0xc0;
DDRC&= 0xc0;
PORTD &= 0xc0;
PORTC &= 0xc0;
if (ORING <= 6)
{
PORTD |= (1 << (6 - ORING));
DDRD|= (1 << (6 - ORING));
}
else
{
PORTC |= (1 << (12 - ORING));
DDRC|= (1 << (12 - ORING));
}
if (ORING <= 6)
{
DDRD|= (1 << (6 - ORING));
}
else
{
DDRC|= (1 << (12 - ORING));
}
}
void disp_minutes(void)
{
DDRD&= 0xc0;
DDRC&= 0xc0;
PORTD &= 0xc0;
PORTC &= 0xc0;
if (ORING <= 6)
{
DDRD|= (1 << (6 - ORING));
}
else
{
DDRC|= (1 << (12 - ORING));
}
if (ORING <= 6)
{
PORTD |= (1 << (6 - ORING));
DDRD|= (1 << (6 - ORING));
}
else
{
PORTC |= (1 << (12 - ORING));
DDRC|= (1 << (12 - ORING));
}
}
void disp_hour(void)
{
DDRD&= 0xc0;
DDRC&= 0xc0;
PORTD &= 0xc0;
PORTC &= 0xc0;
if (IRING <= 6)
{
PORTC |= (1 << (6 - IRING));
DDRC|= (1 << (6 - IRING));
DDRD|= (1 << (6 - IRING));
}
else
{
PORTD |= (1 << (12 - IRING));
DDRC|= (1 << (12 - IRING));
DDRD|= (1 << (12 - IRING));
}
}
void display(void)
{
we_D++;
if((we_D>15)&&(MODE_D==1))
{
if(we_D>30)
we_D=0;
}
else
{
disp_seconds();
}
delay_us(5);
if((we_D>15)&&(MODE_D==2))
{
if(we_D>30)
we_D=0;
}
else
{
disp_minutes();
}
delay_us(5);
if((we_D>15)&&(MODE_D==3))
{
if(we_D>30)
we_D=0;
}
else
{
disp_hour();
}
delay_us(5);
}
//定时器1中断
SIGNAL(SIG_OUTPUT_COMPARE1A)
{
seconds++;
if (seconds>= 60)
{
seconds= 0;
minutes++;
}
if (minutes >=60)
{
minutes = 0;
hour++;
}
if (hour >12)
{
hour = 1;
}
}
int main(void)
{
port_init();
t1_init();
sei ();
while(1)
{
display();
if((PINB&0x08)!=0x08)
{
display();
if((PINB&0x08)!=0x08)
{
while((PINB&0x08)!=0x08) display();
MODE_D++;
if(MODE_D>3)
MODE_D=0;
}
}
if((PINB&0x10)!=0x10)//+
{
display();
if((PINB&0x10)!=0x10)
{
while((PINB&0x10)!=0x10) display();
switch(MODE_D)
{
case 1:
{
hour++;
if (hour >12)
{
hour = 1;
}
}
break;
case 2:
{
minutes++;
if (minutes >=60)
{
minutes = 0;
}
}
break;
case 3:
{
seconds++;
if (seconds>=60)
{
seconds= 0;
}
}
break;
}
}
}
if((PINB&0x20)!=0x20)//-
{
display();
if((PINB&0x20)!=0x20)
{
}
}
}
}
呵呵,很帅
不过电路图没怎么看明白,求高手解释一下 嗯,不错嗯,不错 看的有点恐怖,132个LED{:soso_e127:},,能焊个5*5*5的光立方了 是在看不懂原理图,mcu是啥也看不出来:'( 挺像八卦阵的 :'(最害怕的就是画图~\(≧▽≦)/~啦啦啦 这个电路是什么原理,,看不懂? :Q楼主这个电路图好像不行,我模拟了一下,不行,是不是图发错了还是没画完整? 而且你这个图不管怎样解释都不对,不会是在逗我们吧!!!!! 还请楼主给个正确的原理图 chizhouwlb2008 发表于 2013-1-16 15:17 static/image/common/back.gif
而且你这个图不管怎样解释都不对,不会是在逗我们吧!!!!!
没有错的,网络标号是否对,重新上传了,自己对下。 chizhouwlb2008 发表于 2013-1-16 15:17 static/image/common/back.gif
而且你这个图不管怎样解释都不对,不会是在逗我们吧!!!!!
原理图没有错误,食物已经正常运行了。。 很强也很创意啊 好东西,顶一个。
页:
[1]
2