中期成果總結(jié)(1)(1)_第1頁
中期成果總結(jié)(1)(1)_第2頁
中期成果總結(jié)(1)(1)_第3頁
中期成果總結(jié)(1)(1)_第4頁
中期成果總結(jié)(1)(1)_第5頁
免費預(yù)覽已結(jié)束,剩余9頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、電動汽車電池電量管理系統(tǒng)m4»n»TTiiVi Bit程序#include "stm32f10x.h#include "delay.h"#include "LCD1602.h”#include "adc.h"#include "led.h"#include "key.h"#include "math.h" u16 adcx5;u16 sigl;int temperature;u8 vol1,vol2;int resistance;int current;i

2、nt vol;u8 num;unsigned char disp20;/ 時鐘存儲數(shù)組unsigned char TIM10;unsigned char dat120;unsigned char dat220;unsigned char sen120;unsigned char sen220;/NTC-MF52-3435 10K 溫度對應(yīng)表int Temperature_table60=441, /-10 0421,/-91402,/-82384,/-73367,/-64350,/-55335,/-46320,/-37306,/-28293,/-19280,/010268,/111257,/2

3、12246,/313236,/414227,/515218,/616209,/717201,/818193,/919186,/1020185,/1121181,/1222176,/1323170,/1424163,/1525155,/1626148,/1727141,/1828134,/1929127,/2030121,/2131115,/2232110,/2333105,/2434100,/253596,/263692,/273788,/283885,/293982,/304079,/314176,/324273,/334371,/344468,/354566,/364664,/374761

4、,/384859,/394957,/405055,/415154,/425252,/435350,/445448,/455547,/465645,/475744,/485842/4959;/ 熱敏電阻轉(zhuǎn)換int Get_temperature(int temp_adcx)int i=0;小于最小量程大于最大量程if(Temperature_table0<temp_adcx) /return i;if(Temperature_table59>temp_adcx) / i=59;return i;while(!(Temperature_tablei>temp_adcx)&

5、&(temp_adcx>=Temperature_tab lei+1)i+;return i;int main(void)double distance;double voltage;int MOD;delay_init();NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);LCD_INIT();Adc_Init();/ADC 初始化LED_InIt();KEY_Init();num=0;MOD=0;/自動模式LCD_write_string(0,0,"Starting.");delay_ms(1000);LCD_C

6、lear();while(1)adcx0=Get_Adc_Average(ADC_Channel_0,10); /溫度adcx1=Get_Adc_Average(ADC_Channel_1,10); / 電壓 1adcx2=Get_Adc_Average(ADC_Channel_2,10); /電壓 2adcx3=Get_Adc_Average(ADC_Channel_3,10); /絕緣電阻adcx4=Get_Adc_Average(ADC_Channel_4,10); /電流vol1=adcx2*33/4096;LCD_write_char(6,0,vol1/10%10+'0

7、9;);LCD_write_char(7,0,'.');LCD_write_char(8,0,vol1/1%10+'0');LCD_write_char(9,0,'V');LCD_write_char(10,0,' ');vol2=adcx3*33/4096;vol2=vol2-vol1;LCD_write_char(11,0,vol2/10%10+'0');LCD_write_char(12,0,'.');LCD_write_char(13,0,vol2/1%10+'0');LCD

8、_write_char(14,0,'V');/SOCvol=(vol1+vol2)*100/24;LCD_write_char(6,1,vol/10%10+'0');LCD_write_char(7,1,vol/1%10+'0');LCD_write_char(8,1,'%');LCD_write_char(9,1,' ');/ 電流current=adcx4*330/4096;LCD_write_char(10,1,current/100%10+'0');LCD_write_char(11,1,c

9、urrent/10%10+'0');LCD_write_char(12,1,current/1%10+'0');LCD_write_char(13,1,'m');LCD_write_char(14,1,'A');LCD_write_char(15,1,' ');/ 溫度檢測temperature=(4096*51/adcx0)-51;temperature=Get_temperature(temperature)-10;LCD_write_string(0,0,"T: C ");LCD_writ

10、e_char(2,0,temperature/10%10+'0');LCD_write_char(3,0,temperature/1%10+'0');/ 絕緣電阻檢測resistance=(4096*(vol1+vol2)/33);resistance=(resistance*100)/adcx1-100;LCD_write_char(0,1,resistance/1000%10+'0');LCD_write_char(1,1,resistance/100%10+'0');LCD_write_char(2,1,resistance

11、/10%10+'0');LCD_write_char(3,1,resistance/1%10+'0');LCD_write_char(4,1,'K');LCD_write_char(5,1,' ');if(temperature>30)|(resistance<10) /溫度報警和絕緣報警,溫度大于 30 攝氏度,或絕緣電阻小于10K beep=0;elsebeep=1; if(KEY0=0) / 放電按鍵if(relay2!=0)relay1=0; /預(yù)充 1 秒結(jié)束,開始正式充電delay_ms(1000);rel

12、ay1=1;relay2=0;elserelay1=1;relay2=1;if(KEY1=0) / 均衡按鍵if(vol1>vol2)relay3=0; relay4=1; elseif(vol1<vol2)relay3=1;relay4=0; else relay3=1; relay4=1;elserelay3=1;relay4=1;delay_ms(500);#include "adc.h"#include "delay.h / 初始化 ADCvoid Adc_Init(void)ADC_InitTypeDef ADC_InitStructure;

13、GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_ADC1,ENABLE ); /使能ADC11道時鐘RCC_ADCCLKConfig(RCC_PCLK2_Div6); / 設(shè) 置 ADC 分 頻 因 子 672M/6=12,ADCR大時間不能超金14M/PA1 作為模擬通道輸入引腳GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4; / 增加

14、通道,加個引腳定義,再把引腳數(shù)目改一下GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; / 模擬輸入引腳 GPIO_Init(GPIOA, &GPIO_InitStructure);ADC_DeInit(ADC1); / 復(fù)位 ADC1ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; /ADC 工 作 模式:ADC1和ADC2r作在獨立模式ADC_InitStructure.ADC_ScanConvMode = ENABLE; / 多通道循環(huán)掃描ADC_InitStructure.ADC_Sc

15、anConvMode = DISABLE; / 模數(shù)轉(zhuǎn)換工作在單通道模式ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; / 模數(shù) 轉(zhuǎn)換工 作在單次轉(zhuǎn)換模式ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;/ 轉(zhuǎn)換由軟件而不是外部觸發(fā)啟動ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; /ADC 數(shù)據(jù) 右對齊ADC_InitStructure.ADC_NbrOfChannel = 5;/ 順序進(jìn)行規(guī)

16、則轉(zhuǎn)換的ADC通道的數(shù)目ADC_Init(ADC1, &ADC_InitStructure); / 根據(jù) ADC_InitStruct 中指定 的參數(shù)初M化外設(shè)ADCX勺寄存器ADC_Cmd(ADC1, ENABLE); / 使能指定的ADC1ADC_ResetCalibration(ADC1); / 使能復(fù)位校準(zhǔn)while(ADC_GetResetCalibrationStatus(ADC1); / 等待復(fù)位校準(zhǔn)結(jié)束ADC_StartCalibration(ADC1); 開啟 AD校準(zhǔn) while(ADC_GetCalibrationStatus(ADC1); / 等待校準(zhǔn)結(jié)束/獲得

17、ADCfiu16 Get_Adc(u8 ch)/設(shè)置指定ADC的規(guī)則組通道,一個序列,采樣時間ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5 );/ADC1,ADC通道,采樣時間為239.5周期ADC_SoftwareStartConvCmd(ADC1, ENABLE); / 使能指定的 ADC1 的 軟件轉(zhuǎn)換啟動功能while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC );/ 等待轉(zhuǎn)換結(jié)束return ADC_GetConversionValue(ADC1); / 返回最近一次

18、ADC1 規(guī)則組的轉(zhuǎn)換結(jié)果u16 Get_Adc_Average(u8 ch,u8 times)u32 temp_val=0;u8 t;for(t=0;t<times;t+)temp_val+=Get_Adc(ch);delay_ms(5);return temp_val/times;#include "led.h void LED_InIt(void)GPIO_InitTypeDef GPIO_InitStruct;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);GPIO_InitStruct.GPIO_Pin=GPI

19、O_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOB,&GPIO_InitStruct);GPIO_SetBits(GPIOB,GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GP IO_Pin_15);#include "key.h"#includ

20、e "delay.h"void KEY_Init(void)GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);/ 使 能PORTA,PORTC 鐘GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);/ 關(guān) 閉 jtag ,使能SWD可以用SWD(麻I試GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;GPIO_InitStructure.

21、GPIO_Mode = GPIO_Mode_IPU; / 設(shè)置成上拉輸入GPIO_Init(GPIOB, &GPIO_InitStructure);#include "LCD1602.h"#include "sys.h"/LCD 引腳初始化void GPIO_LCD1602(void)GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_ APB2Periph_AFIO,ENABLE);GPI

22、O_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_6|GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pi

23、n_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;GPIO_Init(GPIOB, &GPIO_InitStructure);u8 LCD_check_busy() / 忙檢測GPIO_Write(GPIOB,(0x00ff)|(GPIOB->ODR&0xff00);RS_CLR;delay_

24、us(1);RW_SET;delay_us(1);doEN_CLR;delay_us(200);EN_SET;delay_us(200);while(GPIOB->IDR&0X80);return (u8)0;/ 初始化數(shù)據(jù)配置void LCD_initwrite_com(unsigned char com)/while(LCD_check_busy();EN_CLR;delay_us(1);RS_CLR;delay_us(1);RW_CLR;delay_us(10);GPIO_Write(GPIOB,(com&0x00ff)|(GPIOB->ODR&0xf

25、f00);delay_us(300);EN_SET;delay_us(300);EN_CLR;delay_us(300);/ 寫命令void LCD_write_com(unsigned char com)/while(LCD_check_busy();EN_CLR;delay_us(1);RS_CLR;delay_us(1);RW_CLR;delay_us(1);GPIO_Write(GPIOB,(com&0x00ff)|(GPIOB->ODR&0xff00);delay_us(500);EN_SET;delay_ms(1);EN_CLR;delay_us(100);/ 寫數(shù)據(jù)void LCD_write_data(unsigned char Data)/while(LCD_check_busy();EN_CLR;delay_us(1);RS_SET;delay_us(1);RW_CLR;delay_us(1);GPIO_Write(GPIOB,(Da

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論