一份大一新生的小作业
ATMEGA48时钟程序源码:
- #include<iom48v.h>
- //共阳数码管键码
- const unsigned char disp_table_ca[]=
- { 0xC0,0xF9,0xA4,0xB0,0x99,
- 0x92,0x82,0xF8,0x80,0x90 };
- char a_second=0;
- char b_second=0;
- int count=0,flag;
- void delay(unsigned int x)
- { int i,j; for(i=0;i<x;i++) for(j=0;j<1141;j++); }
- void main()
- { DDRD=0xff;
- DDRB=0XFF;
- PORTC=0XFF;
-
- while(1)
- {
- PORTB=0B00000001;
- PORTD=disp_table_ca[a_second];
- delay(1);
-
- PORTB=0B00000010;
- PORTD=disp_table_ca[b_second];
- delay(1);
-
- if((PINC&0B00000001)==0)
- {
- delay(20);
- if((PINC&0B00000001)==0)
- flag=1;
- while((PINC&0B00000001)==0);
- }
-
- if((PINC&0B00000010)==0)
- {
- delay(20);
- if((PINC&0B00000010)==0)
- flag=2;
- while((PINC&0B00000010)==0);
- }
-
- if((PINC&0B00000100)==0)
- {
- delay(20);
- if((PINC&0B00000100)==0)
- flag=3;
- while((PINC&0B00000100)==0);
- }
-
- if(flag==1)
- {
- count++;
- if(count%49==0)
- b_second++;
-
- if(b_second==10)
- {
- b_second=0;
- a_second++;
- if(a_second==6)
- a_second=0;
- }
- }
-
- if(flag==2)
- {
- count++;
- if(count%49==0)
- b_second--;
-
- if(b_second==-1)
- {
- b_second=9;
- a_second--;
- if(a_second==-1)
- a_second=5;
- }
- }
-
- if(flag==3)
- {
- a_second=0;
- b_second=0;
- }
-
- }
-
- }
复制代码
下载:
电气164-张洪栩.zip
(54.42 KB, 下载次数: 37)
|