自己做的蓝桥杯十三届模拟题,师从小蜜蜂,做一些自己的记录吧。
第一次发文章,后面会补上省赛所有的。
选择题答案不确定就不发了,有人做了可以一起对一下,或者告诉我一下
main
#include "reg52.h"
#include "iic.h"
sbit s7 = P3 ^ 0; //*
sbit s6 = P3 ^ 1;
sbit s5 = P3 ^ 2;
sbit s4 = P3 ^ 3;
unsigned char code duanma[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //*
unsigned char code duanma1[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
void display_choose(); //*
void pcf_adc_01();
void pcf_adc_03();
void delay(unsigned char t)
{
while(t--);
}
void delay1(unsigned char t)
{
while(t--);display_choose();pcf_adc_01();//*anjianshi
pcf_adc_03();
}
void hc573(unsigned char n)
{
switch(n) //*
{
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)|0x00;break;
}
}
void first()
{
P0=0xff;
hc573(4);
P0=0xff;
hc573(5);
P0=0x00;
hc573(6);
P0=0x00;
hc573(7);
P0=0xff;
hc573(0);
}
void timer()
{
TMOD=0X16;
TH0=0XFF;
TL0=0XFF;
TH1=(65536-10000)/256;//10ms***65536 256
TL1=(65536-10000)%256;
ET1=1;
ET0=1;
EA=1;
TR1=1;
TR0=1;
}
unsigned int cnt_f=0;//**int
unsigned char cnt_02s=0;
unsigned int cnt_1s=0;
unsigned int count=0;//int
unsigned char led_stat=1;
void servicetimer0() interrupt 1 //*
{
cnt_f++;
}
unsigned char ss7=0;
void servicetimer1() interrupt 3 //*
{
TH1=(65536-10000)/255;
TL1=(65536-10000)%255;
cnt_02s++;
if(s7==0){cnt_1s++;}
else{cnt_1s=0;}
if(cnt_1s==100)
{
led_stat=~led_stat;
cnt_1s=0;
}
if(cnt_02s==20)
{
count=cnt_f*5;
cnt_02s=0;
cnt_f=0;
}
}
unsigned int ain1=0;
unsigned int ain3=0;
void pcf_adc_01()
{
IIC_Start();
IIC_SendByte(0x90);
IIC_WaitAck();
IIC_SendByte(0x01);
IIC_WaitAck();
IIC_Stop();
IIC_Start();
IIC_SendByte(0x91);
IIC_WaitAck();
ain1=IIC_RecByte();
IIC_SendAck(1);
IIC_Stop();
ain1=ain1*1.961;
//ain1=100*ain1;
}
void pcf_adc_03()
{
IIC_Start();
IIC_SendByte(0x90);
IIC_WaitAck();
IIC_SendByte(0x03);
IIC_WaitAck();
IIC_Stop();
IIC_Start();
IIC_SendByte(0x91);
IIC_WaitAck();
ain3=IIC_RecByte();
IIC_SendAck(1);
IIC_Stop();
ain3=ain3*1.961;
// ain3=100*ain3;
}
void display(unsigned char pos,unsigned char dat)
{
hc573(7);
P0=0xff;
hc573(6);
P0=0x01<<pos;//*
hc573(7);
P0=dat;
}
void displayoff()
{
hc573(6);
P0=0x00;
hc573(7);
P0=0xff;
}
void display1()//******0-7
{
display(7,duanma[count%10]);
delay(500);
if(count>9)
{
display(6,duanma[(count%100)/10]) ;
}
else{display(6,0xff) ;}
delay(500);
if(count>99)
{
display(5,duanma[(count%1000)/100]) ;
}
else{display(5,0xff) ;}
delay(500);
if(count>999)
{
display(4,duanma[(count%10000)/1000]);
}
else{display(4,0xff) ;}
delay(500);
if(count>9999)
{
display(3,duanma[(count%100000)/10000]);
}
else{display(3,0xff) ;}
delay(500);
display(2,0xff);
delay(500);
display(1,0xff) ;
delay(500);
display(0,0x8d) ;
delay(500);
displayoff();
}
unsigned int zhouqi=0;
//zhouqi=1000000/count;//?
void display2()
{ zhouqi=1000000/count;//*
display(7,duanma[zhouqi%10]);
delay(500);
if(zhouqi>9)
{
display(6,duanma[(zhouqi%100)/10]);
}
else{display(6,0xff) ;}
delay(500);
if(zhouqi>99)
{
display(5,duanma[(zhouqi%1000)/100]) ;
}
else{display(5,0xff) ;}
delay(500);
if(zhouqi>999)
{
display(4,duanma[(zhouqi%10000)/1000]);
}
else{display(4,0xff) ;}
delay(500);
if(zhouqi>9999)
{
display(3,duanma[(zhouqi%100000)/10000]);
}
else{display(3,0xff) ;}
delay(500);
display(2,0xff);
delay(500);
display(1,0xff) ;
delay(500);
display(0,0xc8) ;
delay(500);
displayoff();
}
unsigned char smg3=1;
void display3()
{
if(smg3==1){
display(7,duanma[ain1%10]);
delay(500);
display(6,duanma[(ain1%100)/10]);
delay(500);
display(5,duanma1[(ain1%1000)/100]) ;
delay(500);
display(4,0xff);
delay(500);
display(3,0xff) ;
delay(500);
display(2,duanma[1]) ;
delay(500);
display(1,0xbf);
delay(500);
display(0,0xc1) ;
delay(500);
displayoff();
}
else{
display(7,duanma[ain3%10]);
delay(500);
display(6,duanma[(ain3%100)/10]) ;
delay(500);
display(5,duanma1[(ain3%1000)/100]) ;
delay(500);
display(4,0xff);
delay(500);
display(3,0xff);
delay(500);
display(2,duanma[3]) ;
delay(500);
display(1,0xbf);
delay(500);
display(0,0xc1) ;
delay(500);
displayoff();
}
}
//void display4()//?
unsigned int ain3_set=0;
unsigned int count_set=0;
unsigned char p0_stat=0xff;
unsigned char smg_stat=1;
void led()
{
P0=0xff;
hc573(4);
if(led_stat==1){
if(ain3>ain3_set){p0_stat=p0_stat & 0xfe;}
else{p0_stat=p0_stat | 0x01;}
if(count>count_set){p0_stat=p0_stat & 0xfd;}
else{p0_stat=p0_stat | 0x02;}
if(smg_stat==1){p0_stat=p0_stat & 0xfb;}
else{p0_stat=p0_stat | 0x04;}
if(smg_stat==2){p0_stat=p0_stat & 0xf7;}
else{p0_stat=p0_stat | 0x08;}
if(smg_stat==3){p0_stat=p0_stat & 0xef;}
else{p0_stat=p0_stat | 0x10;}
P0=p0_stat;
}
else{P0=0xff;}
}
void display_choose()
{
if(smg_stat==1){display1();}
else if(smg_stat==2){display2();}
else if(smg_stat==3){display3();}
//else if(smg_stat==4){display4();}
led();
}
void scan()
{
if(s5==0)
{
delay(100);
if(s5==0)
{
smg3=~smg3;
while(s5==0)
{
delay1(50);//?
}
}
}
if(s4==0)
{
delay(100);
if(s4==0)
{
smg3=1;
smg_stat=smg_stat+1;
if(smg_stat>3){smg_stat=1;}
while(s4==0)
{
delay1(50);//?
}
}
}
if(s6==0)
{
delay(100);
if(s6==0)
{
ain3_set=ain3;
while(s6==0)
{
delay1(50);//?
}
}
}
if(s7==0)
{
delay(100);
if(s7==0)
{
count_set=count;
while(s7==0)
{
delay1(5);//?
}
}
}
}
void main()
{
first();
timer();
while(1)
{
pcf_adc_01();//*anjianshi
pcf_adc_01();
pcf_adc_03();//防止读取效果交换
pcf_adc_03();
display_choose();
scan();
}
}
iic.c
#include "iic.h"
#define DELAY_TIME 5
//I2C总线内部延时函数
void IIC_Delay(unsigned char i)
{
do{_nop_();}
while(i--);
}
//I2C总线启动信号
void IIC_Start(void)
{
SDA = 1;
SCL = 1;
IIC_Delay(DELAY_TIME);
SDA = 0;
IIC_Delay(DELAY_TIME);
SCL = 0;
}
//I2C总线停止信号
void IIC_Stop(void)
{
SDA = 0;
SCL = 1;
IIC_Delay(DELAY_TIME);
SDA = 1;
IIC_Delay(DELAY_TIME);
}
//发送应答或非应答信号
void IIC_SendAck(bit ackbit)
{
SCL = 0;
SDA = ackbit;
IIC_Delay(DELAY_TIME);
SCL = 1;
IIC_Delay(DELAY_TIME);
SCL = 0;
SDA = 1;
IIC_Delay(DELAY_TIME);
}
//等待应答
bit IIC_WaitAck(void)
{
bit ackbit;
SCL = 1;
IIC_Delay(DELAY_TIME);
ackbit = SDA;
SCL = 0;
IIC_Delay(DELAY_TIME);
return ackbit;
}
//I2C总线发送一个字节数据
void IIC_SendByte(unsigned char byt)
{
unsigned char i;
for(i=0; i<8; i++)
{
SCL = 0;
IIC_Delay(DELAY_TIME);
if(byt & 0x80) SDA = 1;
else SDA = 0;
IIC_Delay(DELAY_TIME);
SCL = 1;
byt <<= 1;
IIC_Delay(DELAY_TIME);
}
SCL = 0;
}
//I2C总线接收一个字节数据
unsigned char IIC_RecByte(void)
{
unsigned char i, da;
for(i=0; i<8; i++)
{
SCL = 1;
IIC_Delay(DELAY_TIME);
da <<= 1;
if(SDA) da |= 1;
SCL = 0;
IIC_Delay(DELAY_TIME);
}
return da;
}