是4T平台上面那个单片机模拟赛二,我不知道哪错了,那个评分里面只有led是对的。
单片机源程序如下:
- #include "STC15F2K60S2.H"
- #include "jiben.h"
- #include "onewire.h"
- #include "iic.h"
- #include "intrins.h"
- #define uint unsigned int
- #define uchar unsigned char
-
- uchar ledbuf[]={0,0,0,0,0,0,0,0};
- uchar kdly;
- uint sdly;
- uchar spos;
- uchar smgbuf[]={16,16,16,16,16,16,16,16};
- uchar smgpoint[]={0,0,0,0,0,0,0,0};
- bit jiemian;
- bit mode;
- float temp=30;
- uchar ad;
- uchar da;
- void Delay750ms() //@11.0592MHz
- {
- unsigned char i, j, k;
- _nop_();
- _nop_();
- i = 35;
- j = 51;
- k = 182;
- do
- {
- do
- {
- while (--k);
- } while (--j);
- } while (--i);
- }
- void keydo()
- {
- static kv,ko,kd,ku;
-
- if(kdly)
- return;
- kdly=1;
-
- kv=keydis();
- kd=(kv&(kv^ko));
- ku=~(kv&(kv^ko));
- ko=kv;
-
- if(kd==4 && jiemian==0)
- {
- mode^=1;
- }
- if(kd==5)
- {
- jiemian^=1;
- }
- }
- void smgdo()
- {
- if(sdly)
- return;
- sdly=1;
-
- ad=readad(0x41);
- temp=readtemp();
-
- if(mode==0)
- {
- if(temp>=10 && temp<=40)
- da=(1+((temp-10.0)*2/15))*51;
- else if(temp>40)
- da=255;
- else
- da=51;
- }
- else
- {
- if(ad>=10 && ad<=240)
- da=(1+((ad-10)*1/60))*51;
- else if(ad>240)
- da=255;
- else
- da=51;
- }
-
- if(jiemian==0)
- {
- if(mode==0)
- {
- smgbuf[0]=1;
- smgbuf[5]=(uchar)temp/10;
- smgbuf[6]=(uchar)temp%10;
- smgbuf[7]=(uint)(temp*10)%10;
- smgpoint[6]=1;
- }
- else
- {
- smgbuf[0]=2;
- smgbuf[5]=16;
- smgbuf[6]=(uint)((ad*10)/51)/10;
- smgbuf[7]=(uint)((ad*10)/51)%10;
- smgpoint[6]=0;
- }
- }
- else
- {
- adout(da);
- smgbuf[0]=18;
- smgbuf[5]=16;
- smgbuf[6]=(uint)((da*10)/51)/10;
- smgbuf[7]=(uint)((da*10)/51)%10;
- smgpoint[6]=1;
- }
- }
- void leddo()
- {
- ledbuf[0]=(mode==0);
- ledbuf[1]=(mode==1);
- }
- void Timer0Init(void) //1??@12.000MHz
- {
- AUXR &= 0x7F;
- TMOD &= 0xF0;
- TL0 = 0x18;
- TH0 = 0xFC;
- TF0 = 0;
- TR0 = 1;
- ET0 = 1;
- EA = 1;
- }
- void timer0() interrupt 1
- {
- if(++spos==8)
- spos=0;
- if(++kdly==10)
- kdly=0;
- if(++sdly==500)
- sdly=0;
-
- smgdis(spos,smgbuf[spos],smgpoint[spos]);
- leddis(spos,ledbuf[spos]);
- }
- void main()
- {
- Delay750ms();
- Timer0Init();
- init();
- readtemp();
- while(1)
- {
- keydo();
- smgdo();
- leddo();
- }
- }
复制代码
|