蓝桥杯单片机第七届
Posted 一心向月
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了蓝桥杯单片机第七届相关的知识,希望对你有一定的参考价值。
全部文件:提取码:azxy
直接看题目吧,这一届主要的考点应该是用定时器控制PWM输出。
#include "STC15F2K60S2.h"
#include "intrins.h"
#include "onewire.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit S4=P3^3;
sbit S5=P3^2;
sbit S6=P3^1;
sbit S7=P3^0;
// 0 1 2 3 4 5 6 7 8 9 ?? — //
u8 code duan[12]=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf;
u8 model=1;
u8 work_time=0;
u8 temp=0;
u8 temp_flag=0;
u8 count=0;
u16 count1=0;
u8 pwm=0;
void delay(u16 i)
while(i--);
void Timer0Init(void) //100us 12.000MHz
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0x50;
TH0 = 0xFB;
TF0 = 0;
ET0 = 1;
EA = 1;
void Service_T0() interrupt 1
count++;
count1++;
if(count==pwm)
P34=0;
else if(count==10)
P34=1;
count=0;
if(count1==10000)
work_time--;
count1=0;
void Chan_hc573(chose)
switch(chose)
case 4:
P2 = (P2 & 0x1f) | 0x80; break;
case 5:
P2 = (P2 & 0x1f) | 0xa0; break;
case 6:
P2 = (P2 & 0x1f) | 0xc0; break;
case 7:
P2 = (P2 & 0x1f) | 0xe0; break;
void Init_system()
Chan_hc573(5);
P0=0x00;
Chan_hc573(4);
P0=0xff;
void Smg_display(u8 com,u8 dat)
Chan_hc573(7);
P0=0xff;
Chan_hc573(6);
P0=0x01<<com;
Chan_hc573(7);
P0=dat;
void Close_smg()
Chan_hc573(6);
P0=0x00;
Chan_hc573(7);
P0=0xff;
void Model_display()
if(temp_flag==0)
Smg_display(0,duan[11]); delay(1000);
Smg_display(1,duan[model]); delay(1000);
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[work_time/1000]); delay(1000);
Smg_display(5,duan[(work_time/100)%10]); delay(1000);
Smg_display(6,duan[(work_time/10)%10]); delay(1000);
Smg_display(7,duan[work_time%10]); delay(1000);
Close_smg();
else if(temp_flag==1)
Smg_display(0,duan[11]); delay(1000);
Smg_display(1,duan[4]); delay(1000);
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[10]); delay(1000);
Smg_display(5,duan[temp/10]); delay(1000);
Smg_display(6,duan[temp%10]); delay(1000);
Smg_display(7,0xc6); delay(1000);
Close_smg();
void Key_down()
if(S4==0)
delay(100);
if(S4==0)
while(S4==0)
model++; work_time=0; TR0=0; count1=0;
if(model==4) model=1;
if(S5==0)
delay(100);
if(S5==0)
while(S5==0)
if(work_time==0) work_time=60;TR0=1;
else if(work_time<=60) work_time=120;
else if(work_time<=120) work_time=0;TR0=0;
if(S6==0)
delay(100);
if(S6==0)
while(S6==0)
work_time=0;TR0=0;
if(S7==0)
delay(100);
if(S7==0)
while(S7==0)
if(temp_flag==0) temp_flag=1;
else if(temp_flag==1) temp_flag=0;
void Rank()
Chan_hc573(4);
if(work_time!=0)
if(model==1) pwm=2; P00=0;
else if(model==2) pwm=3; P01=0;
else if(model==3) pwm=7; P02=0;
else P34=0;
void main()
Init_system();
Timer0Init();
while(1)
Rank();
Key_down();
Model_display();
temp=DS18B20_Read();
以上是关于蓝桥杯单片机第七届的主要内容,如果未能解决你的问题,请参考以下文章