本人大二菜鸡一枚,今年参加蓝桥杯,感觉陪跑,这是我参考写的第七届代码,请大家指教。
单片机源程序如下:
- #include<reg52.h>
- #include<onewire.h>
- #include<intrins.h>
- sfr AUXR=0X8e;
- sbit pwm_out=P3^4;
- code unsigned char t_display[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x40,0x00};
- code unsigned char t_com[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- unsigned char work1[8]={0xbf,0xff,0xbf,0xff,0xff,0xff,0xff,0xff};
- unsigned char cont,count,work_mode,timing,T_dat,trg,temp;
- unsigned char start_flag=1,PWM_count=20,temp_flag=0,work_mode=0,timing_flag,dismode;
- void KEY()
- {
- unsigned char readdata=P3^0xff;
- trg=readdata&(readdata^cont);
- cont=readdata;
- }
- void delay(unsigned int i)
- {
- while(i--);
- }
- void smg()
- { int i;
- P2=0xc0;P0=0;P2=0;//二极管全灭
- P2=0xe0;P0=work1[i];P2=0;//数码管选择
- P2=0xc0;P0=t_com[i];P2=0;//二极管点亮
- i++;if(i==8)i=0;
- }
- void Timer0Init(void) //100??@11.0592MHz
- {
- AUXR |= 0x80; //?????1T??
- TMOD &= 0xF0; //???????
- TL0 = (65535-100)/255; //??????
- TH0 = (65535-100)%255; //??????
- TF0 = 0; //??TF0??
- TR0 = 1; //???0????
- ET0 = 1;
- EA = 1;
- }
- void InterruptTimer0() interrupt 1
- {
- unsigned char count1,count2;
- if(start_flag==1)
- {
- count++;
- if((count==PWM_count/10)&&(timing!=0))
- {
- if(work_mode==1){P2=0x80;P0=0xfe;P2=0;}
- else if(work_mode==2){P2=0x80;P0=0xfd;P2=0;}
- else if(work_mode==3){P2=0x80;P0=0xfb;P2=0;}//二极管工作模式点亮
- }
- if(count==10)
- {
- count=0;
- P2=0x80;P0=0xff;P2=0;
- }
- }
- if(count2>300)
- {
- count2=0;
- temp_flag=1;
- }
- if(count1>=1000)
- {
-
- count1=0;
- if(timing!=0)
- timing--;
- }
-
- }
-
- void keyaction()
- {
- switch(trg)
- {
- /*S4*/ case 0x80:
- if(work_mode==0)
- {work_mode=1;PWM_count=30;}
- else if(work_mode==2){work_mode=3;PWM_count=70;}
- else if(work_mode==3){work_mode=1;PWM_count=20;}
- break;
- /*S5*/case 0x40:
- start_flag=1;if(timing_flag==3)timing_flag=1;
- else if(timing_flag==4)timing_flag=2;
- else if(timing_flag==5)timing_flag=0;
- /*S8*/case 0x08: timing=0;start_flag=0; break;
- /*S9*/ case 0x04:if(dismode==0)dismode=1;else dismode=0; break;
-
-
- }
-
-
- }
- void main()
- {
- P2=0xa0;P0=0;P2=0;
- P2=0x80;P0=0xff;P2=0;
- temp=rd_temperature();
- Timer0Init();
- while(1)
- {
- KEY();
- keyaction();
-
- if(timing==0)
- {
- P2=0x80;P0=0xff;P2=0;
- }
-
- if((dismode==1)&&(temp_flag==1))
- {
- temp_flag=0;
- // ET0=0;
- temp=rd_temperature();
- // ET0=1;
- }
-
- if(dismode==0)
- {
- work1[0]=0xbf;work1[1]=~t_display[work_mode];work1[2]=0xbf;work1[3]=0xff;
- work1[4]=~t_display[timing/1000%10];work1[5]=~t_display[timing/100%10];work1[6]=~t_display[timing/10%10];work1[7]=~t_display[timing%10];
- }
- else if(dismode==1)
- {
- work1[0]=0xbf;work1[1]=~t_display[4];work1[2]=0xbf;work1[3]=0xff;
- work1[4]=0xff;work1[5]=0xff;work1[6]=~t_display[temp/10%10];work1[7]=~t_display[temp%10];
- }
-
- if(timing_flag==0){timing=timing_flag*60;timing_flag=3;}
- else if(timing_flag==1){timing=timing_flag*60;timing_flag=4;}
- else if(timing_flag==2){timing=timing_flag*60;timing_flag=5;}
-
-
- }
- }
复制代码
hex文件:
蓝桥杯第七届.zip
(5.88 KB, 下载次数: 4)
|