数字式开关电源地PID控制.doc

上传人:小** 文档编号:3475981 上传时间:2019-05-31 格式:DOC 页数:18 大小:27.37KB
下载 相关 举报
数字式开关电源地PID控制.doc_第1页
第1页 / 共18页
数字式开关电源地PID控制.doc_第2页
第2页 / 共18页
数字式开关电源地PID控制.doc_第3页
第3页 / 共18页
数字式开关电源地PID控制.doc_第4页
第4页 / 共18页
数字式开关电源地PID控制.doc_第5页
第5页 / 共18页
点击查看更多>>
资源描述

1、-_/*开关电源的数字化控制 */*所用拓扑为 Buck,单片机 msp430*/*PID 算法实现开关电源的恒流、恒压、恒功率功能*/*糖 coffeeuestc*/*Part 1 Main.C*/#include #include “LCD12864.h“#include “table.h“#include “GUI.h“#include “deal.h“#include “IndependentKey.h“#include “init.h“void main( void )WDTCTL = WDTPW + WDTHOLD;init_clk();init_lcd();GUI_CU();in

2、it_ADC12();init_TA();init_TB();initKey();_EINT();while(1)KeyScan();if(Mode=0) /恒压模式DisplaySetU();Delay(100);ADC();Delay(100);else if(Mode=1) /恒流模式DisplaySetI();Delay(100);ADC();Delay(100);-_else /恒功率模式DisplaySetP();Delay(100);ADC();Delay(100);/*Part 2 Headfile*/*Part 2.1 LCD12864 Headfile*/#ifndef _

3、LCD12864#define _LCD12864#define LCD_CS BIT0#define LCD_SID BIT2#define LCD_CLK BIT4#define LCD_EN P3DIR#define LCD_CTRL P3OUT#define LCD_CS_Set_high LCD_CTRL |= LCD_CS#define LCD_CS_Set_low LCD_CTRL void Send_Byte(unsigned char byte);void ClearLCD(void);void Put_Array(unsigned char *data , unsigned

4、 char length ,unsigned char address);/*延时*/-_void Delay(unsigned char time) /主时钟 1 微秒延时unsigned int i;i=0x08*time;for(; i; i-);/*/函数名称 :Initial_LCD(void)/函数功能 :启动初始化*/void Initial_LCD(void) LCD_EN |= LCD_CS + LCD_SID + LCD_CLK;Write_Data (0x30,0); /基本指令集Delay(LCD_delay);Write_Data(0x30,0);Write_Data

5、(0x0C,0);Delay(LCD_delay);Write_Data(0x01,0); /清屏Delay(LCD_delay);Write_Data(0x06,0);Delay(LCD_delay);/*函数名称 : Write_Data(unsigned char byte,unsigned char reffer)*函数功能 :发送指令或数据reffer 数据 1指令 0*输入变量 : unsigned char byte unsigned char byte */void Write_Data(unsigned char byte ,unsigned char reffer)unsi

6、gned char temp,stemp;temp = byte;LCD_CS_Set_high; LCD_CLK_Set_low; if(reffer=1)-_Send_Byte(0xFA);else Send_Byte(0xF8); /发送第一个字节stemp = (temp Send_Byte(stemp);stemp = temp 4;Send_Byte(stemp);LCD_CS_Set_low;/*函数名称 : Send_Byte(unsigned char byte)*函数功能 :发送一字节数据*输入变量 : unsigned char byte */void Send_Byte

7、(unsigned char byte)unsigned char temp,i;temp = byte;for(i=0;i8;i+) /send 8 timesif (temp elseLCD_SID_Set_low;temp = (temp1); LCD_CLK_Set_low;LCD_CLK_Set_high; Delay(LCD_delay);/*函数名称: Put_Array ( unsigned char data, unsigned char length,unsigned char address )*函数功能: 在 LCD 上显示一个数组*输入变量: unsigned cha

8、r data unsigned char length unsigned char address */void Put_Array(unsigned char *data , unsigned char length ,unsigned char address)-_if(address!=0)Write_Data(address,0);for (unsigned char i=0;ilength;i+)Write_Data(datai,1);/*函数名称 : ClearLCD(void)*函数功能 :清屏*/void ClearLCD(void)Write_Data(0x01,0);/*函

9、数名称: Set_cursor*功能描述: 设置光标的位置为 CurY 行,CurX 列*输 入 : CurX=position(0:7) CurY=line(0:3)*/void Set_cursor(unsigned char CurY, unsigned char CurX)switch(CurY)case 0: Write_Data(0x80+CurX,0);break; / 写入第一行 CurX 列的地址case 1: Write_Data(0x90+CurX,0);break; / 写入第二行 CurX 列的地址case 2: Write_Data(0x88+CurX,0);bre

10、ak; / 写入第三行 CurX 列的地址case 3: Write_Data(0x98+CurX,0);break; / 写入第四行 CurX 列的地址default: break;/*函数名称 : PutInt(unsigned int num)*函数功能 :显示十进制数*/-_void PutInt(unsigned int num)unsigned int snum;unsigned char temp12=0, temp112 =0;unsigned char i = 0,n = 0 ;snum = num;if(snum =0 )temp0 = 0;i+ ; while(num!=

11、0)tempi = num%10+0x30;num = num/10;i+ ;n = i;for(i=0;in; i+)temp1i = tempn-1-i;Put_Array(temp1,n,0);void PutDig(unsigned char num)unsigned char snum;snum = num + 0x30;Write_Data(snum,1);/* 函数名称: PutcLCD()* 功能描述: LCD 写 char* 输 入 : LCD_Char*/void PutcLCD( unsigned char LCD_Char )Write_Data(LCD_Char,1)

12、;/* 函数名称: PutsLCD()* 功能描述: LCD 写入 RAM 字符串-_* 输 入: 字符指针 Str*/void PutsLCD(const char *Str)int Str_Temp;Str_Temp=*Str; / Str_Temp 所赋的值是 Str 所指向的字符 while(Str_Temp!=0x00) / 字符串还没有结束Write_Data(Str_Temp,1);Str+;Str_Temp=*Str;/*函数名:ClrRam(void)函数功能:清整个 GDRAM 空间*/void ClrRam()unsigned char x,y ;for(y=0;y64;

13、y+)for(x=0;x16;x+)Write_Data(0x34,0);Write_Data(y+0x80,0);/行地址Write_Data(x+0x80,0);/列地址Write_Data(0x30,0);Write_Data(0x00,1);Write_Data(0x00,1);/*函数名: ShowAll函数说明:显示一幅 128*64 的图画传入参数:图形指针*img*/void ShowAll(unsigned char *pPicture)unsigned char i,j,k;Write_Data(0x36,0);-_for(i=0;i2;i+) /分上下两屏写for(j=0

14、;j32;j+) /行Write_Data(0x80+j,0); /写 X 坐标(第几行上写)if(i=0) /写 Y 坐标,判断哪一屏Write_Data(0x80,0);elseWrite_Data(0x88,0);for(k=0;k16;k+) /写一整行数据(16 个字节,合八个字符)Write_Data(*pPicture+,1);/Write_Data(0x36,0);#endif/*Part 2.2 Table Headfile*/extern unsigned char img=0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,

15、0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFE,

16、0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFE,0x7F,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0x7F,0xFE,0xDF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,

17、0xFF,0x7F,0xFF,0xBF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFB,0xFF,0xF9,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFB,0xFF,0xFF,0x3F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xBF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

18、0x00,0x00,0x01,0xFF,0xFF,0xC0,0x03,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFE,0x00,0x00,0x7F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xF8,0x00,0x00,0x1F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xF0,0x00,0x00,0x07,0xFF,0xE0,0x00,0x00,

19、0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x7F,0xC0,0x00,0x00,0x03,0xFE,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF7,0x80,0x00,0x00,0x01,0xF5,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,-_0x1F,0xFB,0x00,0x00,0x00,0x00,0xE3,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0x03,0xF8,0x07,0xF

20、8,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFE,0x0F,0xFE,0x1F,0xFC,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFC,0x1C,0x0F,0x7C,0x0C,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFC,0x1C,0x03,0xF0,0x06,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF

21、8,0x08,0x01,0xE0,0x0E,0x1F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF8,0x08,0x07,0xF0,0x0E,0x1F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF0,0x08,0x0F,0x38,0x0C,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF0,0x0C,0x1E,0x1E,0x0C,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x0

22、0,0x00,0x00,0xFF,0xF0,0x04,0x7C,0x0E,0x1C,0x0F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xF0,0x05,0xF8,0x00,0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xE3,0xBF,0x9C,0xFF,0xEF,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xE3,0xBB,0x6D,0xFF,0xFF,0x87,0xDF,0x00,0x0

23、0,0x00,0x00,0x00,0x00,0x00,0x00,0xEF,0xE3,0xBE,0x6F,0xF3,0xBB,0x87,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xE3,0xBE,0xFF,0xFB,0xB8,0x07,0xCF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xE3,0xFB,0xFC,0x7B,0x9F,0x87,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xE1,0xF3,0x1D,0xF3,0x9

24、F,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xE0,0x07,0xF8,0x07,0x0C,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xF0,0x06,0xF8,0x0F,0x18,0x0F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF0,0x0C,0x1C,0x1E,0x0C,0x0F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF

25、0,0x0C,0x0E,0x3C,0x0C,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF8,0x0C,0x07,0x78,0x0C,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF8,0x18,0x03,0xF0,0x04,0x1F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,0x18,0x03,0xE0,0x04,0x1F,0xFE,0x00,0x00,0x00,0x00,0x00,0x0

26、0,0x00,0x00,0x3F,0xFC,0x08,0x0F,0xF8,0x04,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFE,0x0C,0x3F,0x3E,0x08,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFE,0x07,0xFC,0x07,0xF0,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0x03,0xE0,0x00,0xA0,0xFF,0xF8,0x00,0x0

27、0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0x80,0x00,0x00,0x01,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xC0,0x00,0x00,0x03,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xE0,0x00,0x00,0x07,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xF8,0x00,0x00,0x0

28、F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFC,0x00,0x00,0x3F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xE0,0x07,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF

29、F,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xDD,0xC6,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x0

30、0,0x00,0x00,0x00,0x07,0xFF,0xD6,0xDC,0x7F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xB9,0xBD,0xBF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x7B,0xCD,0xBF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF7,0xEE,0x7C,0x00,0x00,0x00,0x0

31、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0x1F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,-_0x00,0x00,0x03,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00;/*Part 2.3 GUI Headfile*/#

32、ifndef _GUI#define _GUI/*开机界面*/void init_lcd()Initial_LCD();Set_cursor(0,4);PutsLCD(“SwPower“);Set_cursor(1,4);PutsLCD(“糖 coffee“);Set_cursor(2,4);PutsLCD(“糖 coffee“);Set_cursor(3,4);PutsLCD(“糖 coffee“);ShowAll(img);while(P1IN/*Initial_LCD();Set_cursor(0,0);PutsLCD(“Set I:01.00 A“);Set_cursor(1,0);PutsLCD(“Out U: V“);Set_cursor(2,0);PutsLCD(“Out I: A“);Set_cursor(3,0);PutsLCD(“Out P: W“);*/*恒流源界面*/void GUI_CC()Initial_LCD();Set_cursor(0,0);PutsLCD(“Set I:01.00 A“);Set_cursor(1,0);PutsLCD(“Out U: V“);Set_cursor(2,0);PutsLCD(“Out I: A“);Set_cursor(3,0);PutsLCD(“Out P: W“);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 复习参考

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。