本帖最后由 迷你强 于 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[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};
- 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[seconds] <= 6)
- {
- PORTD |= (1 << (6 - ORING[seconds]));
- DDRD |= (1 << (6 - ORING[seconds]));
- }
- else
- {
- PORTC |= (1 << (12 - ORING[seconds]));
- DDRC |= (1 << (12 - ORING[seconds]));
- }
- if (ORING[seconds+ 1] <= 6)
- {
- DDRD |= (1 << (6 - ORING[seconds+ 1]));
- }
- else
- {
- DDRC |= (1 << (12 - ORING[seconds+ 1]));
- }
- }
- void disp_minutes(void)
- {
- DDRD &= 0xc0;
- DDRC &= 0xc0;
- PORTD &= 0xc0;
- PORTC &= 0xc0;
- if (ORING[minutes] <= 6)
- {
- DDRD |= (1 << (6 - ORING[minutes]));
- }
- else
- {
- DDRC |= (1 << (12 - ORING[minutes]));
- }
- if (ORING[minutes + 1] <= 6)
- {
- PORTD |= (1 << (6 - ORING[minutes + 1]));
- DDRD |= (1 << (6 - ORING[minutes + 1]));
- }
- else
- {
- PORTC |= (1 << (12 - ORING[minutes + 1]));
- DDRC |= (1 << (12 - ORING[minutes + 1]));
- }
- }
- void disp_hour(void)
- {
- DDRD &= 0xc0;
- DDRC &= 0xc0;
- PORTD &= 0xc0;
- PORTC &= 0xc0;
- if (IRING[hour] <= 6)
- {
- PORTC |= (1 << (6 - IRING[hour]));
- DDRC |= (1 << (6 - IRING[hour]));
- DDRD |= (1 << (6 - IRING[hour]));
- }
- else
- {
- PORTD |= (1 << (12 - IRING[hour]));
- DDRC |= (1 << (12 - IRING[hour]));
- DDRD |= (1 << (12 - IRING[hour]));
- }
- }
- 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)
- {
-
- }
- }
- }
- }
复制代码 |