#include"reg52.h"
#include"iic.h"
#include"math.h"
#include"intrins.h"
//#define unsigend char uchar
sbit pwm=P2^7; // 定义pwm脉冲
sbit P01=P0^1; // 定义pwm脉冲
sbit CS = P1^2; //使能。
sbit CLK = P1^3;//时钟
sbit DIO = P1^4;
sbit button1=P3^0;
sbit button2=P3^1;
sbit button3=P3^2;
sbit button4=P3^3;
sbit button5=P3^4;
int pwm_add=0; //pwm增量
int PWM_control=0; //pwm占空比调节
float voltage_get=0; //获取电压值
float voltage_set=0; //设定电压值 这个地方就是你要设定的电压 修改这个值就可以获得想要的电压值 现在是36V
float voltage_kp=0.01; //PID KP比例系数
float voltage_ki=0.1; //PID KI积分系数
float voltage_output=0; //PID输出
float voltage_error=0; //实际值与给定的误差
float voltage_error_last=0; //记录上次的误差
void timer_init();
unsigned char Get_ADC(bit ch);
static void Delay_ms(unsigned int ms)
{
unsigned int i, j;
for(i = 0; i < ms; i++)
for(j = 0; j < 990; j++);
}
void main()
{
timer_init(); //初始化定时器
pwm=0;
voltage_set=12;
while(1)
{
if(!button1)
voltage_set=0;
else if(!button2) voltage_set=3;
else if(!button3) voltage_set=6;
else if(!button4) voltage_set=9;
else if(!button5) voltage_set=12;
// voltage_set=9;
// Delay_ms(3);
//PWM_control=20;
}
}
//定时器0 用于产生PWM波
void timer_irq() interrupt 1
{
pwm_add++;
if (pwm_add==PWM_control)
{pwm=0;}
else if (pwm_add==50)
{
pwm=1;
pwm_add=0;
}
}
void timer1_irq() interrupt 3
{
TH1=(65536-50000)>>8;
TL1= 65536-50000;
voltage_get=(Get_ADC(0)/10.2);//获取当前电压
//voltage_get=(Get_ADC(0));//获取当前电压
// voltage_get=17;
//voltage_set= voltage_set*10;
voltage_error=voltage_set-voltage_get;//当前差值=设置的减去获取的。
voltage_output+=voltage_kp*(voltage_error-voltage_error_last)
+voltage_ki*voltage_error;
voltage_error_last=voltage_error;
if (voltage_output>49)
voltage_output=49;
else if(voltage_output<1)
voltage_output=1;
PWM_control=(int)voltage_output;
}
//定时器初始化 具体的下面的代码已经配置好了 不用太关注
void timer_init()
{
TMOD=0X12;
TH0=TL0=256-200;
TH1=(65536-50000)>>8;
TL1= 65536-50000;
EA=1;ET0=1;ET1=1;TR0=1;TR1=1;
}
unsigned char Get_ADC(bit ch)
{
unsigned char i,dat1 = 0,dat2 = 0;
//启动AD转换
CS = 0; CLK = 0;
DIO = 1; _nop_(); _nop_();
CLK = 1; _nop_(); _nop_();
CLK = 0; DIO = 1; _nop_(); _nop_();
CLK = 1; _nop_(); _nop_();
CLK = 0; DIO = ch; _nop_(); _nop_();
CLK = 1; _nop_(); _nop_();
CLK = 0; DIO = 1; _nop_(); _nop_();
//从高位开始读
for(i = 0; i < 8; i++)
{
CLK = 1; _nop_(); _nop_();
CLK = 0; _nop_(); _nop_();
dat1 = (dat1 << 1)|DIO;
}
//从低位开始读
for(i = 0; i < 8; i++)
{
dat2 = dat2|((unsigned char)DIO<<i);
CLK = 1; _nop_(); _nop_();
CLK = 0; _nop_(); _nop_();
}
CS = 1;
//返回读取结果
return dat1;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
DCDC 51单片机PWM PID电源仿真程序是一种用于模拟和控制电源的程序。这个程序使用51单片机作为其核心,通过PWM(脉宽调制)和PID(比例-积分-微分)控制器来实现精确的电源控制。DCDC转换器是一种电源电路,可以将输入电压转换为不同的输出电压。通过使用51单片机和PWM PID控制器,我们可以实现对输出电压的精确控制,从而满足各种应用需求。这个仿真程序可以帮助我们理解和优化这个过程,提高电源的性能和效率。DCDC 51单片机PWM PID电源仿真程序是一个强大的工具,对于那些需要精确控制电源的人来说,这是一个非常有价值的资源。
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 26 条
- 1
![avatar](https://profile-avatar.csdnimg.cn/5fa2c54e34e740aa992571b908cb3f9c_u010973053.jpg!1)
风和技术资料库
- 粉丝: 40
- 资源: 924
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
- 1
- 2
前往页