A题-报告2-程序清单 | ||||
| ||||
A题-报告2-程序清单 #include "sys.h" #include "led.h" #include "delay.h" #include "key.h" #include "oled.h" #include "usart.h" //#include "usmart.h" #include "timer.h" #include "beep.h" #include "dac.h" #include "adc.h" //#include "remote.h" //#include "spi.h" #include "math.h" u8 count=0; u16 adci=0, adcus=0, adcu2=0,adcovp=0; float tempi=0, tempus=0, tempu2=0,temp30=0,adcival=0,tempovp=0; unsigned int temp=0,tempvar=0; unsigned int dacvals=0,dacvaltemp=0; float dacvalss=0; unsigned int addend =0; unsigned char backup[4][4] = { //按键值备份,保存前一次的值 {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1} }; unsigned char KeySta[4][4] = { //全部矩阵按键的当前状态 {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1} }; const unsigned char KeyCodeMap[4][4] = { { '1', '2', '3', 0x26 }, //数字键1、数字键2、数字键3、向上键 { '4', '5', '6', 0x25 }, //数字键4、数字键5、数字键6、向左键 { '7', '8', '9', 0x28 }, //数字键7、数字键8、数字键9、向下键 { 0x1B, '0', 0x0D, 0x27 } //数字键0、ESC 键、回车键、向右键 }; #define adcstand 3.3 void buckon() { ENboost=0; delay_ms(100); ENbuck=1; } void buckoff() { ENbuck=0; delay_ms(100); ENboost=1; } int main(void) { u8 stand=0,stand1=0,chuangxin=0,standcc=0,standcccv=0; unsigned int p=0,count=0,count2=0; NVIC_Configuration(); delay_init(); uart_init(9600); LED_Init(); BEEP_Init(); KEY_Init(); OLED_Init(); TIM3_Int_Init(30-1,2400-1); Dac1_Init(); Adc_Init(); Dac1_Set_Vol(20); OLED_ShowString(0,16," CC / CC CV "); OLED_ShowString(0,32," 1 / 2 "); OLED_Refresh_Gram(); while((standcc|standcccv)==0) { if(addend==1) {standcc=1;addend=0;} else if(addend==2) { standcccv=1; addend=0;} }
OLED_ShowString(0,0,"SET: "); OLED_ShowString(0,16,"I : "); OLED_ShowString(0,32,"Us: "); OLED_ShowString(0,48,"U2: "); OLED_Refresh_Gram(); while(1) { adci=Get_Adc_Average(1,100); tempi=(adci*adcstand/4096/1.0625-0.0078)/1.0029*1.0075-0.003;
adcus=Get_Adc_Average(2,30); tempus=(float)(adcus*adcstand/4096*14-0.0791)/0.9762*0.9954+0.1209; adcu2=Get_Adc_Average(3,30); tempu2=(float)(adcu2*adcstand/4096*14-0.1059)/0.98*0.995+0.1462; adcovp=Get_Adc_Average(5,250); tempovp=(float)((adcovp*adcstand/4096*10.1)+1.5); dacvalss=0.2; if(stand==0) { oled_show(tempi,32,16); oled_show(tempus,32,32); oled_show(tempovp,32,48); OLED_Refresh_Gram(); } if(tempu2<1.0&&stand==0) { buckon();
if(standcccv==1) { if(tempovp>21) { dacvaltemp-=10; {Dac1_Set_Vol(dacvaltemp);} if(tempi<dacvalss) { OLED_ShowString(0,0," "); OLED_ShowString(0,16," FULLCHARGE "); OLED_ShowString(0,32," "); OLED_ShowString(0,48," "); ENbuck=0;stand=1; }} if(tempovp<21) {dacvaltemp+=10; Dac1_Set_Vol(dacvaltemp);} } if(tempovp>24) { stand=1; ENbuck=0; OLED_ShowString(0,0," "); OLED_ShowString(0,16," OVERVOLTAGE "); OLED_ShowString(0,32," "); OLED_ShowString(0,48," "); OLED_Refresh_Gram(); } if(standcccv==0) {if(dacvals>15) { if(tempi*1000>(float)(dacvals)+1) Dac1_Set_Vol(dacvaltemp--); else if (tempi*1000<(float)(dacvals)-1) Dac1_Set_Vol(dacvaltemp++); }} } else if(fabs(tempu2-tempus)<0.5&&stand==0) { buckoff(); } else if(tempus>35.0) {
buckon(); temp=((tempus-30)*200)-1000+10; tempvar=temp*1.35; Dac1_Set_Vol(tempvar);
} else {buckoff(); Dac1_Set_Vol(20);} (Get_Adc_Average(1,200)*adcstand/4096/1.0626*1000<(float)(dacvals)-2) Dac1_Set_Vol(+ +dacvaltemp);} } } |