赞
踩
15届省赛结束,本人也是侥幸进入国赛,在学习国赛试题的过程中总结了一些小的心得体会,给大家分享出来,希望能对大家有帮助,这次是14届的国赛试题,因为本人之前从来没有写过国赛试题,感觉难度确实增大了许多,功能,用到的模块都变多了,还有许多小细节要注意,让编写代码的时间变得很紧凑,在加入了超声波之后,原先在主进程刷新数码管的方式收到超声波的影响,让显示效果变得很差,并且超声波也占用了一个定时器,让串口和ne555模块的编写变得有困难,本人也是在网上总结了许多大家的经验,附加一些个人的理解,希望能够帮到大家。
在国赛试题中,超声波一直是一个热门考点,在实际的编写后我发现常规的超声波写法(定时器0)会占用一个固定的定时器(因为要一直开关并且不可以有定时器中断程序)这可能会影响别的功能的实现,所以我们使用了STC15系列单片机中的一个外设PCA,关于这个外设的具体原理以及寄存器配置可以参考手册或者上网查找资料,这里只讲代码,我们需要知道这个外设大致和51单片机中的定时器差不多就足够了。(PCA外设的使用需要使用头文件<STC15F2K60S2.H>,reg52.h是不支持的,并且在芯片选择上也要选择STC15F2K60)。
- void SendWave()//超声波 产生40KHx启动信号
- {
- uchar i;
- EA = 0;
- for(i=0;i<8;i++)
- {
- Tx = 1;
- Delay12us();
- Tx = 0;
- Delay12us();
- }
- EA = 1;
- }
- uint csb()//获取间隔时间的函数
- {
- uint dis,time;
- CMOD &= 0x00;//需要配置CMOD为0x0,这里CMOD类似于定时器中的TMOD
- CH = 0;//初值为0
- CL = 0;
-
- SendWave();//发超声波
- CR = 1;//开外设计时
- while((Rx==1)&&(CF==0));//如果接收端收到了,或者定时器超时,则跳出循环
- CR = 0;//关外设计时
- if(CF==0)//if没超时,就是接收端接收到了
- {
- time = (CH<<8)|CL;//整合计时的高低八位
- if(fuFlag==0)//这里我们需要判断校准值是正或者是负,若是这正就加上校准值,反之减去,后面还会说
- dis = ((time/10)*sudu/2)/100+3+jiaozhun;//sudu是我们定义的传播速度参数,对他/2后计算距离,公式s=t*v/2
- else
- dis = ((time/10)*sudu/2)/100+3-jiaozhun1;//减去校准值
- }
- else//超时了
- {
- CF=0;//清除标志位
- dis = 999;//距离等于999
- }
- return dis;//返回
- }
- void Showcsb()//温度和超声波显示
- {
- seg_loop[0] = temp/100;//温度的部分
- seg_loop[1] = temp%100/10;
- seg_loop[2] = temp%10;
- seg_loop[3] = 18;
- if(distance!=999)//如果不为999(不超时情况)
- {
- if(distance/1000!=0)//判断有无过千,有就显示,反之不显示
- {
- seg_loop[4] = distance/1000;
- }
- else
- {
- seg_loop[4] = 16;
- }
- if((CountS5==1)||(distance/100!=0))//判断是否过百或者为以m为单位
- {
- seg_loop[5] = distance%1000/100;
- }
- else
- {
- seg_loop[5] = 16;
- }
- if((CountS5==1)||(distance/10!=0))//判断是否过十或者为以m为单位
- seg_loop[6] = distance%100/10;
- else
- seg_loop[6] = 16;
- if(distance>=0)判断是否大于0
- seg_loop[7] = distance%10;
- else
- seg_loop[7] = 16;
- }
- else seg_loop[7] = seg_loop[6] = seg_loop[5] = seg_loop[4] = 16;//超时不显示
-
- }
数码管显示是和省赛最大差别的地方,在省赛中我们可以在主进程中刷新片选和段选的方式来实现数码管显示,但是在加入了超声波模块之后,由于超声波代码的编写会频繁阻塞主进程,这导致数码管的显示效果不佳,所以使用定时器0显示数码管(1ms刷新一次)
- code unsigned char Seg_Table[] = //段码表,新增了不显示,字母p等
- {
- 0xc0, //0
- 0xf9, //1
- 0xa4, //2
- 0xb0, //3
- 0x99, //4
- 0x92, //5
- 0x82, //6
- 0xf8, //7
- 0x80, //8
- 0x90, //9
- 0x88, //A
- 0x83, //b
- 0xc6, //C
- 0xa1, //d
- 0x86, //E
- 0x8e,//F
- 0xff,
- 0x7f,
- 0xbf,
- 0x8c
- };
- uchar seg_loop[] = {16,16,16,16,16,16,16,16};//数码管显示的八个位,数字对应上面的断码表,如16是0xff意思是上电默认不显示
- void Display()//所有界面的显示
- {
- switch(CountS4)//用switch的嵌套实现各个界面的切换,不详细解释了
- {
- case 0:Showcsb();break;
- case 1:
- switch(CountS5)
- {
- case 0:ShowjuliCS();break;
- case 1:ShowtempCS();break;
- }
- break;
- case 2:
- switch(CountS5)
- {
- case 0:Showjiaozhun();break;
- case 1:Showsudu();break;
- case 2:ShowDA();break;
- }
- break;
- }
- }
- void InitTime()//只用到了一个定时器0,一毫秒刷新一次数码管
- {
- TMOD = 0x10;
- TH1 = (65535-1000)/256;
- TL1 = (65535-1000)%256;
- EA = 1;
- ET1 = 1;
- TR1 = 1;
- }
- void ServiceT1() interrupt 3
- {
- TH1 = (65535-1000)/256;
- TL1 = (65535-1000)%256;
- // SeleHC573(0,0xff);
- SeleHC573(6,0x01<<j);//片选
- if(CountS4==0||CountS4==2)//这里是需要显示小数点的位,需要把每个要用到小数点的地方写出来,减去0x80
- {
- if(((CountS4==0)&&(CountS5==1)&&(j==5)&&(distance != 999))||((CountS4==0)&&(j==1))||((CountS4==2)&&(CountS5==2)&&(j==6)))
- SeleHC573(7,Seg_Table[seg_loop[j]]-0x80);
- else
- {
- SeleHC573(7,Seg_Table[seg_loop[j]]);
- }
- }
- else
- {
- SeleHC573(7,Seg_Table[seg_loop[j]]);
- }
- // SeleHC573(0,0xff);
- CtrlJDQ();//下面与数码管无关
- j++;if(j>7)j=0;
- counttemp++;
- countcsb++;
- countkey++;
- countled++;
- countchangan++;
- if(countjilu<=6000) countjilu++;
- CtrlLED();
- }
按键中只有两个难点,一个是正负数,还有一个是检测到S8和S9同时按下时程序复位,正负数是通过一个标志位实现的,当正变量减到0,标志位置一,然后负变量继续加,负数加到0也是同理,标志位置零,正变量置零,检测两个键是否同时按下就在每个按键的while循环内加一个判断另一个键是否按下,按下就计时,到两秒就复位,复位使用的是手册中的方法,想了解原理的可以查询手册,直接搜索软件复位就可以了,有例程参考,在这里不多赘述。
- sfr ISP_CONTR = 0xc7;
- sbit R1 = P3^0;
- sbit R2 = P3^1;
- sbit R3 = P3^2;
- sbit R4 = P3^3;
- sbit C1 = P3^4;
- sbit C2 = P3^5;
- sbit C3 = P4^2;
- sbit C4 = P4^4;
- void KeyScanf()
- {
- R3=0;
- R1 = R2 = R4 = 1;
- C1 = C2 = C3 =C4= 1;
- if(C4==0)//S5
- {
- countkey=0;while(countkey<=10);//延时
- if(C4==0)
- {
- while(C4==0);
- CountS5++;
- if(CountS4!=2)//界面2有三个子界面
- {
- if(CountS5==2)CountS5=0;//切子页面
- }
- else
- {
- if(CountS5==3)CountS5=0;
- }
- }
- }
- if(C3==0)//S9
- {
- countkey=0;while(countkey<=10);
- if(C3==0)
- {
- while(C3==0)//while中判断S8是否按下
- {
- R4=0;
- R1 = R2 = R3 = 1;
- C1 = C2 = C3 =C4= 1;
- // countkey=0;while(countkey<=50);
- if(C3==0)
- {
- countchangan=0;//计时变量
- while(C3==0)if(countchangan>=2000)ISP_CONTR = 0x20;//复位命令
- }
- R3=0;
- R1 = R2 = R4 = 1;
- C1 = C2 = C3 =C4= 1;//记得切回来S9这一行,不然就不满足while中的C3==0了
- }
- if(CountS5==0&&CountS4==2)//下面就是界面中的一些数值的加减,不多赘述
- {
- if(jiaozhun==0)
- {
- if(jiaozhun1!=90)
- jiaozhun1+=5;
- fuFlag=1;
- }
- else
- {
- fuFlag=0;
- jiaozhun-=5;
- }
- }
- if(CountS5==1&&CountS4==2)
- {
- if(sudu!=1)sudu--;
- }
- if(CountS5==2&&CountS4==2)
- {
- if(DA!=1)DA--;
- }
- if(CountS4==0&&JLflag==1)
- {
- DAdistance=distance;
- DAflag=1;
- }
- if(CountS5==1&&CountS4==1)if(tempCS!=0)tempCS-=10;
- if(CountS5==0&&CountS4==1)if(juliCS!=10)juliCS-=10;
- }
- }
-
- R4=0;
- R1 = R2 = R3 = 1;
- C1 = C2 = C3 =C4= 1;
- if(C4==0)//S4
- {
- countkey=0;while(countkey<=10);
- if(C4==0)
- {
- while(C4==0);
- CountS4++;//主界面切换
- CountS5=0;
- if(CountS4==3)CountS4=0;
- }
- }
- if(C3==0)//S8
- {
- countkey=0;while(countkey<=10);
- if(C3==0)//S8同理S9
- {
- while(C3==0)
- {
- R3=0;
- R1 = R2 = R4 = 1;
- C1 = C2 = C3 =C4= 1;
- countkey=0;while(countkey<=50);
- if(C3==0)
- {
- countchangan=0;
- while(C3==0)if(countchangan>=2000)ISP_CONTR = 0x20;
- }
- R4=0;
- R1 = R2 = R3 = 1;
- C1 = C2 = C3 =C4= 1;
- }
- if(CountS5==0&&CountS4==2)
- {
- if(fuFlag==1)
- {
- if(jiaozhun1==0)
- {
- fuFlag==0;
- jiaozhun+=5;
- }
- else
- {
- jiaozhun1-=5;
- if(jiaozhun1==0)fuFlag=0;
- }
- }
- else
- {
- if(jiaozhun!=90)
- jiaozhun+=5;
- }
-
- }
- if(CountS5==1&&CountS4==2)
- {
- if(sudu!=999)sudu++;
- }
- if(CountS5==2&&CountS4==2)
- {
- if(DA!=20)DA++;
- }
- if(CountS4==0)countjilu=0;
- if(CountS5==1&&CountS4==1)if(tempCS!=800)tempCS+=10;
- if(CountS5==0&&CountS4==1)if(juliCS!=90)juliCS+=10;
- }
- }
- }
DA输出的计算和省赛区别不大,记录过程中要屏蔽按键,只需要设置一个标志位就可以做到,在设置一个计时变量,等待时间到了,赋值输出变量即可。
- void CtrlDA()
- {
- if(DAdistance<=10)DAshuchu=DA;
- if(DAdistance>=90)DAshuchu=50;
- if(DAdistance<90&&distance>10)
- {
- DAshuchu=((50-DA)/80.00)*(DAdistance-10)+DA;
- }
- DAtransport(DAshuchu*5.1);
- }
-
-
- //下面的代码在main中
- if(countjilu>6000)//如果计时变量大于6秒才可以使用按键
- KeyScanf();
- if(countjilu==6001)//到了六秒,记录标志位置一,计时变量置9999(不再自增)
- {
- JLflag=1;
- countjilu=9999;
- }
- if(DAflag==1)CtrlDA();
- //下面代码在按键中
- //S8
- if(CountS4==0)countjilu=0;//S8记录开启
- //S9
- if(CountS4==0&&JLflag==1)//如果在界面一且记录完成
- {
- DAdistance=distance;//赋值
- DAflag=1;//输出变量
- }
这是本代码中最容易的考点,只需要判断距离的值,在0到256中直接将P0 等于距离值取反就行了,继电器就更简单了,判断在区间内,执行就行了,比较简单就不写注释了(累了)
- void CtrlJDQ()
- {
- if((distance>=juliCS-5)&&(distance<=juliCS+5)&&temp>=tempCS)
- {
- SeleHC573(0,0x00);
- SeleHC573(5,0x10);
- SeleHC573(0,0x00);
- }
- else
- {
- SeleHC573(0,0x00);
- SeleHC573(5,0x00);
- SeleHC573(0,0x00);
- }
- }
- void CtrlLED()
- {
- uchar LED=0xff;
- switch(CountS4)
- {
- case 0:
- if(distance>=255)LED=0x00;
- if(distance<255&&distance>=0)LED=~distance;
- if(distance<0)LED=0xff;
- break;
- case 1:
- LED = 0x7f;
- break;
- case 2:
- if(countled<=100)LED=0xfe;
- else
- {
- if(countled>=200)countled=0;
- LED=0xff;
- }
- }
- SeleHC573(4,LED);
-
- }
- #include <STC15F2K60S2.H>
- #include "intrins.h"
- #include "onewire.h"
- #include "iic.h"
- #define uchar unsigned char
- #define uint unsigned int
-
-
- sbit Tx = P1^0;
- sbit Rx = P1^1;
- sfr ISP_CONTR = 0xc7;
- sbit R1 = P3^0;
- sbit R2 = P3^1;
- sbit R3 = P3^2;
- sbit R4 = P3^3;
- sbit C1 = P3^4;
- sbit C2 = P3^5;
- sbit C3 = P4^2;
- sbit C4 = P4^4;
- code unsigned char Seg_Table[] =
- {
- 0xc0, //0
- 0xf9, //1
- 0xa4, //2
- 0xb0, //3
- 0x99, //4
- 0x92, //5
- 0x82, //6
- 0xf8, //7
- 0x80, //8
- 0x90, //9
- 0x88, //A
- 0x83, //b
- 0xc6, //C
- 0xa1, //d
- 0x86, //E
- 0x8e,//F
- 0xff,
- 0x7f,
- 0xbf,
- 0x8c
- };
- uchar seg_loop[] = {16,16,16,16,16,16,16,16};
- uchar j;
- uchar DAflag,JLflag;
- uint countcsb,countkey,counttemp,countjilu=9999 ,countled;
- uint countchangan;
- uint distance,DAdistance;
- uint temp;
- uchar CountS5,CountS4;
- uchar juliCS=40;
- uint tempCS=300;
- uchar jiaozhun,jiaozhun1;
- uint sudu=34;
- uchar fuFlag;
- uchar DA=10,DAshuchu;
- void CtrlJDQ();void CtrlLED();
- void Delay12us(void) //@12.000MHz
- {
- unsigned char data i;
-
- _nop_();
- _nop_();
- i = 33;
- while (--i);
- }
- void SeleHC573(uchar n,dat)
- {
- P0 = dat;
- switch(n)
- {
- case 0:P2 = (P2&0x1f)|0x00;break;
- 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;
- }
- P2 = (P2&0x1f)|0x00;
- }
- void InitTime()
- {
- TMOD = 0x10;
- TH1 = (65535-1000)/256;
- TL1 = (65535-1000)%256;
- EA = 1;
- ET1 = 1;
- TR1 = 1;
- }
-
- void ServiceT1() interrupt 3
- {
- TH1 = (65535-1000)/256;
- TL1 = (65535-1000)%256;
- // SeleHC573(0,0xff);
- SeleHC573(6,0x01<<j);
- if(CountS4==0||CountS4==2)
- {
- if(((CountS4==0)&&(CountS5==1)&&(j==5)&&(distance != 999))||((CountS4==0)&&(j==1))||((CountS4==2)&&(CountS5==2)&&(j==6)))
- SeleHC573(7,Seg_Table[seg_loop[j]]-0x80);
- else
- {
- SeleHC573(7,Seg_Table[seg_loop[j]]);
- }
- }
- else
- {
- SeleHC573(7,Seg_Table[seg_loop[j]]);
- }
- // SeleHC573(0,0xff);
- CtrlJDQ();
- j++;if(j>7)j=0;
- counttemp++;
- countcsb++;
- countkey++;
- countled++;
- countchangan++;
- if(countjilu<=6000) countjilu++;
- CtrlLED();
- }
- void SendWave()
- {
- uchar i;
- EA = 0;
- for(i=0;i<8;i++)
- {
- Tx = 1;
- Delay12us();
- Tx = 0;
- Delay12us();
- }
- EA = 1;
- }
- uint csb()
- {
- uint dis,time;
- CMOD &= 0x00;
- CH = 0;
- CL = 0;
-
- SendWave();
- CR = 1;
- while((Rx==1)&&(CF==0));
- CR = 0;
- if(CF==0)
- {
- time = (CH<<8)|CL;
- if(fuFlag==0)
- dis = ((time/10)*sudu/2)/100+3+jiaozhun;
- else
- dis = ((time/10)*sudu/2)/100+3-jiaozhun1;
- }
- else
- {
- CF=0;
- dis = 999;
- }
- return dis;
- }
- void Init_sys()
- {
- SeleHC573(4,0xff);
- SeleHC573(5,0x00);
- }
- void ReadTemp()
- {
- uchar MSB,LSB;
- init_ds18b20();
- Write_DS18B20(0xcc);
- Write_DS18B20(0x44);
- init_ds18b20();
- Write_DS18B20(0xcc);
- Write_DS18B20(0xbe);
- LSB = Read_DS18B20();
- MSB = Read_DS18B20();
- // temp = MSB;
- temp = ((MSB<<8)|LSB)*0.625;
- // temp = temp*0.625;
- }
- void DAtransport(uchar x)
- {
- I2CStart();
- I2CSendByte(0x90);
- I2CWaitAck();
- I2CSendByte(0x40);
- I2CWaitAck();
- I2CSendByte(x);
- I2CWaitAck();
- I2CStop();
- }
- void Showcsb()
- {
- seg_loop[0] = temp/100;
- seg_loop[1] = temp%100/10;
- seg_loop[2] = temp%10;
- seg_loop[3] = 18;
- if(distance!=999)
- {
- if(distance/1000!=0)
- {
- seg_loop[4] = distance/1000;
- }
- else
- {
- seg_loop[4] = 16;
- }
- if((CountS5==1)||(distance/100!=0))
- {
- seg_loop[5] = distance%1000/100;
- }
- else
- {
- seg_loop[5] = 16;
- }
- if((CountS5==1)||(distance/10!=0))
- seg_loop[6] = distance%100/10;
- else
- seg_loop[6] = 16;
- if(distance>=0)
- seg_loop[7] = distance%10;
- else
- seg_loop[7] = 16;
- }
- else seg_loop[7] = seg_loop[6] = seg_loop[5] = seg_loop[4] = 16;
-
- }
- void ShowtempCS()
- {
- seg_loop[0] = 19;
- seg_loop[1] = 2;
- seg_loop[2] = seg_loop[3] = seg_loop[4] = seg_loop[5] = 16;
- seg_loop[6] = tempCS/100;
- seg_loop[7] = tempCS%100/10;
- }
- void ShowjuliCS()
- {
- seg_loop[0] = 19;
- seg_loop[1] = 1;
- seg_loop[2] = seg_loop[3] = seg_loop[4] = seg_loop[5] = 16;
- seg_loop[6] = juliCS/10;
- seg_loop[7] = juliCS%10;
- }
- void Showjiaozhun()
- {
- seg_loop[0] = 15;
- seg_loop[1] = 1;
- seg_loop[2] = seg_loop[3] = seg_loop[4] =16;
- if(fuFlag==0)
- {
- seg_loop[5] = 16;
- if(jiaozhun>=10)seg_loop[6] = jiaozhun/10;
- else seg_loop[6] = 16;
- seg_loop[7] = jiaozhun%10;
- }
- else
- {
- if(jiaozhun1>=10)
- {
- seg_loop[6] = jiaozhun1/10;
- seg_loop[5] = 18;
- }
- else
- {
- seg_loop[6] = 18;
- seg_loop[5] = 16;
- }
-
- seg_loop[7] = jiaozhun1%10;
- }
- }
- void Showsudu()
- {
- seg_loop[0] = 15;
- seg_loop[1] = 2;
- seg_loop[2] = seg_loop[3] = 16;
- if(sudu/100!=0)
- seg_loop[4] = sudu/100;
- else
- seg_loop[4] = 16;
- if(sudu/10!=0)
- seg_loop[5] = sudu%100/10;
- else
- seg_loop[5] = 16;
- seg_loop[6] = sudu%10;
- seg_loop[7] = 0;
- }
- void ShowDA()
- {
- seg_loop[0] = 15;
- seg_loop[1] = 3;
- seg_loop[2] = seg_loop[3] = seg_loop[4] = seg_loop[5] = 16;
- seg_loop[6] = DA/10;
- seg_loop[7] = DA%10;
- }
- void Display()
- {
- switch(CountS4)
- {
- case 0:Showcsb();break;
- case 1:
- switch(CountS5)
- {
- case 0:ShowjuliCS();break;
- case 1:ShowtempCS();break;
- }
- break;
- case 2:
- switch(CountS5)
- {
- case 0:Showjiaozhun();break;
- case 1:Showsudu();break;
- case 2:ShowDA();break;
- }
- break;
- }
- }
- void CtrlDA()
- {
- if(DAdistance<=10)DAshuchu=DA;
- if(DAdistance>=90)DAshuchu=50;
- if(DAdistance<90&&distance>10)
- {
- DAshuchu=((50-DA)/80.00)*(DAdistance-10)+DA;
- }
- DAtransport(DAshuchu*5.1);
- }
- void CtrlJDQ()
- {
- if((distance>=juliCS-5)&&(distance<=juliCS+5)&&temp>=tempCS)
- {
- SeleHC573(0,0x00);
- SeleHC573(5,0x10);
- SeleHC573(0,0x00);
- }
- else
- {
- SeleHC573(0,0x00);
- SeleHC573(5,0x00);
- SeleHC573(0,0x00);
- }
- }
- void CtrlLED()
- {
- uchar LED=0xff;
- switch(CountS4)
- {
- case 0:
- if(distance>=255)LED=0x00;
- if(distance<255&&distance>=0)LED=~distance;
- if(distance<0)LED=0xff;
- break;
- case 1:
- LED = 0x7f;
- break;
- case 2:
- if(countled<=100)LED=0xfe;
- else
- {
- if(countled>=200)countled=0;
- LED=0xff;
- }
- }
- SeleHC573(4,LED);
-
- }
- void KeyScanf()
- {
- R3=0;
- R1 = R2 = R4 = 1;
- C1 = C2 = C3 =C4= 1;
- if(C4==0)//S5
- {
- countkey=0;while(countkey<=10);
- if(C4==0)
- {
- while(C4==0);
- CountS5++;
- if(CountS4!=2)
- {
- if(CountS5==2)CountS5=0;
- }
- else
- {
- if(CountS5==3)CountS5=0;
- }
- }
- }
- if(C3==0)//S9
- {
- countkey=0;while(countkey<=10);
- //
- // R4=0;
- // R1 = R2 = R3 = 1;
- // C1 = C2 = C3 =C4= 1;
- // countkey=0;while(countkey<=50);
- // if(C3==0)
- // {
- // countchangan=0;
- // while(C3==0)if(countchangan>=2000)ISP_CONTR = 0x20;
- // }
- // else
- // {
- // R3=0;
- // R1 = R2 = R4 = 1;
- // C1 = C2 = C3 =C4= 1;
- if(C3==0)
- {
- while(C3==0)
- {
- R4=0;
- R1 = R2 = R3 = 1;
- C1 = C2 = C3 =C4= 1;
- // countkey=0;while(countkey<=50);
- if(C3==0)
- {
- countchangan=0;
- while(C3==0)if(countchangan>=2000)ISP_CONTR = 0x20;
- }
- R3=0;
- R1 = R2 = R4 = 1;
- C1 = C2 = C3 =C4= 1;
- }
- if(CountS5==0&&CountS4==2)
- {
- if(jiaozhun==0)
- {
- if(jiaozhun1!=90)
- jiaozhun1+=5;
- fuFlag=1;
- }
- else
- {
- fuFlag=0;
- jiaozhun-=5;
- }
- }
- if(CountS5==1&&CountS4==2)
- {
- if(sudu!=1)sudu--;
- }
- if(CountS5==2&&CountS4==2)
- {
- if(DA!=1)DA--;
- }
- if(CountS4==0&&JLflag==1)
- {
- DAdistance=distance;
- DAflag=1;
- }
- if(CountS5==1&&CountS4==1)if(tempCS!=0)tempCS-=10;
- if(CountS5==0&&CountS4==1)if(juliCS!=10)juliCS-=10;
- }
- }
-
- R4=0;
- R1 = R2 = R3 = 1;
- C1 = C2 = C3 =C4= 1;
- if(C4==0)//S4
- {
- countkey=0;while(countkey<=10);
- if(C4==0)
- {
- while(C4==0);
- CountS4++;
- CountS5=0;
- if(CountS4==3)CountS4=0;
- }
- }
- if(C3==0)//S8
- {
- countkey=0;while(countkey<=10);
- // R3=0;
- // R1 = R2 = R4 = 1;
- // C1 = C2 = C3 =C4= 1;
- // countkey=0;while(countkey<=50);
- // if(C3==0)
- // {
- // countchangan=0;
- // while(C3==0)if(countchangan>=2000)ISP_CONTR = 0x20;
- // }
- // else
- // {
- // R4=0;
- // R1 = R2 = R3 = 1;
- // C1 = C2 = C3 =C4= 1;
- if(C3==0)
- {
- while(C3==0)
- {
- R3=0;
- R1 = R2 = R4 = 1;
- C1 = C2 = C3 =C4= 1;
- countkey=0;while(countkey<=50);
- if(C3==0)
- {
- countchangan=0;
- while(C3==0)if(countchangan>=2000)ISP_CONTR = 0x20;
- }
- R4=0;
- R1 = R2 = R3 = 1;
- C1 = C2 = C3 =C4= 1;
- }
- if(CountS5==0&&CountS4==2)
- {
- if(fuFlag==1)
- {
- if(jiaozhun1==0)
- {
- fuFlag==0;
- jiaozhun+=5;
- }
- else
- {
- jiaozhun1-=5;
- if(jiaozhun1==0)fuFlag=0;
- }
- }
- else
- {
- if(jiaozhun!=90)
- jiaozhun+=5;
- }
-
- }
- if(CountS5==1&&CountS4==2)
- {
- if(sudu!=999)sudu++;
- }
- if(CountS5==2&&CountS4==2)
- {
- if(DA!=20)DA++;
- }
- if(CountS4==0)countjilu=0;
- if(CountS5==1&&CountS4==1)if(tempCS!=800)tempCS+=10;
- if(CountS5==0&&CountS4==1)if(juliCS!=90)juliCS+=10;
- }
- }
- }
-
-
- void main()
- {
- Init_sys();
- InitTime();
- while(1)
- {
- if(countjilu>6000)
- KeyScanf();
- if(countjilu==6001)
- {
- JLflag=1;
- countjilu=9999;
- }
- if(counttemp>=150)
- {
- counttemp=0;
- ReadTemp();
- }
- if(countcsb>=500)
- {
- countcsb=0;
- distance = csb();
- }
- if(DAflag==1)CtrlDA();
- // CtrlLED();
- // CtrlJDQ();
- Display();
- }
- }
写完国赛题之后,个人认为好的代码不是越短或者是使用的语法越高级越好,在看了许多例程和高手的代码后,才知道好的代码需要有很高的可读性。希望在国赛可以取得好成绩。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。