蓝桥杯单片机第九届

Posted 一心向月

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了蓝桥杯单片机第九届相关的知识,希望对你有一定的参考价值。

陪女朋友玩了三天,收心继续干。
全部文件:提取码:azxy


#include "STC15F2K60S2.h"
#include "intrins.h"
#include "iic.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 code led_1_2[10]=0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff;
u8 code led_3_4[6]=0xff,0x7e,0xbd,0xdb,0xe7,0xff;
u8 cc_addr[4]=0x10,0x20,0x40,0x80;
u16 yc_time[4];
u8 model=1;
u8 mode=1;
u8 stat=0;
u8 rank=0;
u8 Ms_800=0;
u8 led_flag=0;
u16 count=0;
u8 count1=0;
u16 count2=0;
u16 count3=0;
u8 count4=0;
u8 dat=0;
u8 pwm=0;
u16 rb2_v=0;

void delay(u16 i)

	while(i--);


void Delay5ms()		

	unsigned char i, j;
	i = 59;
	j = 90;
	do
	
		while (--j);
	 while (--i);


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;
		case 0:
			P2 = (P2 & 0x1f); 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 Display_model_time()

	if(stat==1)
	
		if(Ms_800==0)
		
			Smg_display(0,duan[11]); delay(100);
			Smg_display(1,duan[model]); delay(100);
			Smg_display(2,duan[11]); delay(100);
		
		else
		
			Smg_display(0,duan[10]); delay(100);
			Smg_display(1,duan[10]); delay(100);
			Smg_display(2,duan[10]); delay(100);
		
		Smg_display(3,duan[10]); delay(100);
		if(yc_time[model-1]>999)
		
			Smg_display(4,duan[yc_time[model-1]/1000]); delay(100);
		
		Smg_display(5,duan[(yc_time[model-1]/100)%10]); delay(100);
		Smg_display(6,duan[(yc_time[model-1]/10)%10]); delay(100);
		Smg_display(7,duan[yc_time[model-1]%10]); delay(100);
		Close_smg();
	
	else if(stat==2)
	
		
		Smg_display(0,duan[11]); delay(100);
		Smg_display(1,duan[model]); delay(100);
		Smg_display(2,duan[11]); delay(100);
		Smg_display(3,duan[10]); delay(100);
		if(Ms_800==0)
		
			if(yc_time[model-1]>999)
			
				Smg_display(4,duan[yc_time[model-1]/1000]); delay(100);
			
			Smg_display(5,duan[(yc_time[model-1]/100)%10]); delay(100);
			Smg_display(6,duan[(yc_time[model-1]/10)%10]); delay(100);
			Smg_display(7,duan[yc_time[model-1]%10]); delay(100);
			Close_smg();
		
		else
		
			Smg_display(4,duan[10]); delay(100);
			Smg_display(5,duan[10]); delay(100);
			Smg_display(6,duan[10]); delay(100);
			Smg_display(7,duan[10]); delay(100);
			Close_smg();
		
	
	else if(stat==0&&S4==0)
	
		Close_smg();
		Smg_display(0,duan[10]); delay(100);
		Smg_display(1,duan[10]); delay(100);
		Smg_display(2,duan[10]); delay(100);
		Smg_display(3,duan[10]); delay(100);
		Smg_display(4,duan[10]); delay(100);
		Smg_display(5,duan[10]); delay(100);
		Smg_display(6,duan[11]); delay(100);
		Smg_display(7,duan[rank%10]); delay(100);
		Close_smg();
	
 

void Key_Down()

	if(S7==0)
	
		delay(1000);
		if(S7==0)
		
			while(S7==0) 
			if(led_flag==0) led_flag=1;
			else if(led_flag==1) led_flag=0;
		
	
	else if(S6==0)
	
		delay(1000);
		if(S6==0)
		
			while(S6==0) 
			stat++;
			if(stat==3)
				
				wire_eeprom(cc_addr[model-1],yc_time[model-1]/10); Delay5ms();
				stat=0;
			
		
	
	else if(S5==0)
	
		delay(1000);
		if(S5==0)
		
			while(S5==0) 
			if(stat==1) 
			 
				model++;
				if(model>=4) model=4;
			
			else if(stat==2) 
			 
				yc_time[model-1] += 100;
				if(yc_time[model-1]>=1200) yc_time[model-1]=1200;
			
		
	
	else if(S4==0)
	
		delay(1000);
		if(S4==0)
		
			while(S4==0) 
			if(stat==1) 
			 
				model--;
				if(model<=1) model=1;
			
			else if(stat==2) 
			 
				yc_time[model-1] -= 100;
				if(yc_time[model-1]<=400) yc_time[model-1]=400;
			
		
	


void PCF8591()

	rb2_v=pcf8591_read(3)/0.51;
	if(rb2_v<125)
	
		rank=1; pwm=5;
	
	else if(rb2_v>=125&&rb2_v<250)
	
		rank=2; pwm=10;
	
	else if(rb2_v>=250&&rb2_v<375)
	
		rank=3; pwm=15;
	
	else if(rb2_v>=375)
	
		rank=4; pwm=20;
	


void Timer0Init(void);
void main()

	u8 i=0;
	Init_system();
	Timer0Init();
	for(i=0;i<4;i++)
	
		yc_time[i]=eeprom_read(cc_addr[i])*10;
		if(yc_time[i]<=400||yc_time[i]>=1200)
		
			yc_time[i]=400;
		
	
	while(1)
	
		PCF8591();
		Key_Down();
	


void Timer0Init(void)

	TMOD=0x01;
	TH0= (65535-1000) /256;
	TL0= (65535-1000) %256;
	ET0=1; 
	TR0=1;
	EA=1;


void Service_T0() interrupt 1

	TH0= (65535-1000)/256;
	TL0= (65535-1000)%256;
	count++;
	count1++;
	count2++;
	count3++;
	if(count==800)
	
		Ms_800=~Ms_800;
		count=0;
	
	if(count1==2)
	
		count1=0;
		Display_model_time();
	
	if(count2==yc_time[mode-1])
	
		count2=0;
		if(led_flag==1)
		
			if(mode==1)count4++;if(count4>=9)count4=0;mode=2;
			else if(mode==2)count4++;if(count4>=9)count4=0;mode=3;
			else if(mode==3)count4++;if(count4>=5)count4=0;mode=4;
			else if(mode==4)count4++;if(count4>=5)以上是关于蓝桥杯单片机第九届的主要内容,如果未能解决你的问题,请参考以下文章

蓝桥杯单片机第九届国赛程序设计题--多功能测量仪表国赛

蓝桥杯单片机第九届国赛题目-多功能测量仪表

蓝桥杯单片机第九届国赛题目-多功能测量仪表

蓝桥杯单片机第九届省赛客观题(深夜学习——单片机)

蓝桥杯单片机第九届国赛程序设计题--多功能测量仪表国赛

蓝桥杯单片机第九届国赛程序设计题--多功能测量仪表国赛