阅读背景:

第十一测试 蓝桥杯

来源:互联网 
#include <STC15F2K60S2.H> #include "Led.h" #include "Seg.h" #include "Key.h" #include "HC573.h" #include "init.h" #include "iic.h" //µçѹΪ 0-5V£¬ËùÒÔ¾ÍÒª³ý 51.0 /* ²ÎÊýÉùÃ÷ÇøÓò */ unsigned char Key_old,Key_down,Key_up,Key_val; unsigned char Key_slow_down; unsigned char Seg_Buf[8]={10,10,10,10,10,10,10,10}; unsigned char Seg_Point[8]={0,0,0,0,0,0,0,0}; unsigned char Seg_Pos; unsigned char Seg_slow_down; unsigned char Seg_Mode; unsigned char ucLed[8]={0,0,0,0,0,0,0,0}; float V_dat = 0; //Êä³öµçѹֵ unsigned int V_Disp =300; //²ÎÊýÉèÖà unsigned char count =0; //µçѹ¼ÆÊýģʽ unsigned int V_Control; // ²ÎÊýÉèÖð´Å¥ unsigned int V_Con1; // ²ÎÊýдÈëý½é unsigned char V_Write=0; // ²ÎÊýдÈ뺯Êý unsigned char flag =0; //±ê־λº¯Êý unsigned char Err = 0; /* °´¼ü´¦ÀíÇøÓò */ void Key_Proc() { if(Key_slow_down) return; Key_slow_down = 1; Key_val = Key_Read(); Key_down = Key_val & (Key_old ^ Key_val); Key_up = ~Key_val & (Key_old ^ Key_val); Key_old = Key_val; switch(Key_down) { case 12: if(++Seg_Mode==3) Seg_Mode=0; if(Seg_Mode ==1) //Í˳ö²ÎÊýģʽ,´Ó1µ½2 { //µçѹ²ÎÊý¿ªÊ¼Îª 300 £¬ÏÔʾΪ 3.00 ·Å´ó10Ò²¾ÍÊÇÎÒÃÇÖµËõС10 V_Write = V_Con1; // ²ÎÊýдÈ븳ֵ char EEPROM_Write(&V_Write,0,1); //дÈë²ÎÊý ×Ö½ÚΪ1 } break; case 13: if(Seg_Mode == 2) count=0; break; case 16: if(Seg_Mode ==1) { V_Disp = V_Disp+50; if(V_Disp == 500) V_Disp =0; V_Con1 = V_Disp/10; V_Write = V_Con1; } break; case 17: if(Seg_Mode == 1) { V_Disp = V_Disp-50; if(V_Disp == 0) V_Disp =500; V_Con1 = V_Disp/10; V_Write = V_Con1; } break; default: Err++; if(Err == 3) ucLed[2]=1; break; } } /* ÊýÂë¹ÜÏÔʾº¯Êý */ void Seg_Proc() { if(Seg_slow_down) return; Seg_slow_down = 1; /* Êý¾Ý¶ÁÈ¡ÇøÓò */ V_dat = Ad_Read(0x03)/51.0; //±ÈÀý¼ÆËã 0-5V V_Control = V_dat*100; if(V_Control>V_Disp) flag=1; if(flag==1 && V_Control<V_Disp) {count++;flag=0;} /* Êý¾ÝÏÔÊ¾ÇøÓò */ switch(Seg_Mode) { case 0: //³õʼÏÔʾ½çÃæ£¬²É¼¯µçѹ Seg_Buf[0]= 11; Seg_Buf[5]= (unsigned char)V_dat;// Seg_Buf[6]= (unsigned char)(V_dat*10)%10; Seg_Buf[7]= (unsigned char)(V_dat*100)%10; Seg_Point[5]=1; break; case 1: //²ÎÊýÏÔʾ½çÃæ Seg_Buf[0]= 12; Seg_Buf[5]= V_Disp / 100; Seg_Buf[6]= V_Disp / 10 % 10; Seg_Buf[7]= V_Disp %10; Seg_Point[5]=1; break; case 2: if(count <10) { Seg_Point[5]=0; Seg_Buf[0]= 10; Seg_Buf[5]= 10; Seg_Buf[6]= 10; Seg_Buf[7]= count; } if(count>=10) { Seg_Point[5]=0; Seg_Buf[0]= 10; Seg_Buf[5]= 10; Seg_Buf[6]= count/10; Seg_Buf[7]= count%10; } break; } } void Led_Proc() { if(V_Disp < V_Control) {ucLed[0]=1;} else {ucLed[0]=0;} if(count%2 != 0) ucLed[1]=1; else ucLed[1]=0; } void Timer0Init(void) //@12.000MHz { AUXR &= 0x7F; TMOD &= 0xF0; TL0 = 0x18; TH0 = 0xFC; TF0 = 0; TR0 = 1; ET0 = 1; EA = 1; } void Timer0Service() interrupt 1 { if(++Key_slow_down==10) Key_slow_down=0; if(++Seg_slow_down==500) Seg_slow_down=0; if(++Seg_Pos==8) Seg_Pos=0; Seg_Disp(Seg_Pos,Seg_Buf[Seg_Pos],Seg_Point[Seg_Pos]); Led_Disp(Seg_Pos,ucLed[Seg_Pos]); } void main() { EEPROM_Read(&V_Write,0,1); //¶ÁÈ¡º¯Êý V_Con1 = V_Write; // °ÑдÈëµÄ²ÎÊý¸³Öµ V_Control = V_Con1*10; Timer0Init(); System_init(); while(1) { Key_Proc(); Seg_Proc(); Led_Proc(); } } #include <STC15F2K60S2.H> #include "Led.h" #inclu



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: