内含PID控制、AD转换、12864显示、电机测速、控制逻辑程序
仿真原理图如下(proteus仿真工程文件和C源码可到本帖附件中下载)
部分源程序:完整源码下载附件后查看
- #include <reg52.h>
- #include <intrins.h>
- #include <LCD12864.h>
- #include <ADC.h>
- #include <WORDMODEL.h>
- #include <MOTOR.h>
- #define uint unsigned int
- #define uchar unsigned char
- #include <string.h>
- uchar SOC = 0, V = 0, VOLT = 0;
- //SOC
- void display0()
- {
- SOC = vol*100/255;
- temp0 = SOC / 100;
- temp1 = (SOC % 100) / 10;
- temp2 = SOC % 10;
- show_ch1(1, 0, 4 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(1, 0, 5 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(1, 0, 6 * 6, ch1 + (12 * (temp2 + 4)));
- }
- //车速
- void display1()
- {
- V = vol * 192 / 255;
- temp0 = V / 100;
- temp1 = (V % 100) / 10;
- temp2 = V % 10;
- show_ch1(2, 0, 3 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(2, 0, 4 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(2, 0, 5 * 6, ch1 + (12 * (temp2 + 4)));
- }
- //电池电压
- void display2()
- {
- VOLT = vol * 400 / 255;
- temp0 = VOLT / 100;
- temp1 = (VOLT % 100) / 10;
- temp2 = VOLT % 10;
- show_ch1(2, 2, 0 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(2, 2, 1 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(2, 2, 2 * 6, ch1 + (12 * (temp2 + 4)));
- }
- //目标制动力矩
- void display3()
- {
- targetM = vol * 200 / 255;
- D= vol * 100 / 255;
- temp0 = targetM / 100;
- temp1 = (targetM % 100) / 10;
- temp2 = targetM % 10;
- show_ch1(2, 4, 3 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(2, 4, 4 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(2, 4, 5 * 6, ch1 + (12 * (temp2 + 4)));
- }
- //实际制动力矩
- void display4()
- {
- // val=100;
- factM=num1/5 ;
- // val = vol * 192 / 255;
- temp0 = factM / 100;
- temp1 = (factM % 100) / 10;
- temp2 = factM % 10;
- show_ch1(2, 6, 3 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(2, 6, 4 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(2, 6, 5 * 6, ch1 + (12 * (temp2 + 4)));
- }
- void main()
- {
- InitLCD();
- TimeInit();
- ClearScreen(0);
- Set_line(0);
- //SOC显示
- show_ch1(1,0,0*6,ch1+12*1);
- show_ch1(1,0,1*6,ch1+12*2);
- show_ch1(1,0,2*6,ch1+12*3);
- show_ch1(1, 0, 3 * 6, ch1 + 12 * 0);
- show_ch1(1, 0, 7 * 6, ch1 + 12 * 14);
- //车速显示
- show_ch2(1, 0, 52, ch2 + 24 * 6);
- show_ch2(2, 0, 0 * 12, ch2 + 24 * 7);
- show_ch1(2, 0, 1 * 12, ch1 + 12 * 0);
- show_ch1(2, 0, 6*6, ch1 + 12 * 15);
- show_ch1(2, 0, 6 * 7, ch1 + 12 * 16);
- show_ch1(2, 0, 6 * 8, ch1 + 12 * 17);
- show_ch1(2, 0, 6 * 9, ch1 + 12 * 18);
- //电池电压显示
- show_ch2(1, 2, 0 * 14, ch2 + 24 * 12);
- show_ch2(1, 2, 1 * 14, ch2 + 24 * 13);
- show_ch2(1, 2, 2 * 14, ch2 + 24 * 14);
- show_ch2(1, 2, 3 * 14, ch2 + 24 * 15);
- show_ch1(1, 2, 4 * 14, ch1 + 12 * 0);
- show_ch1(2, 2, 6 * 3, ch1 + 12 * 21);
- //目标制动力矩显示
- show_ch2(1, 4, 0, ch2 + 24 * 0);
- show_ch2(1, 4, 13, ch2 + 24 * 1);
- show_ch2(1, 4, 26, ch2 + 24 * 2);
- show_ch2(1, 4, 39, ch2 + 24 * 3);
- show_ch2(1, 4, 52, ch2 + 24 * 4);
- show_ch2(2, 4, 0 * 12, ch2 + 24 * 5);
- show_ch1(2, 4, 1 * 12, ch1 + 12 * 0);
- show_ch1(2, 4, 6 * 6, ch1 + 12 * 19);
- show_ch1(2, 4, 7 * 6, ch1 + 12 * 20);
- //实际制动力矩显示
- show_ch2(1, 6, 0 , ch2 + 24 * 16);
- show_ch2(1, 6, 13, ch2 + 24 * 17);
- show_ch2(1, 6, 26, ch2 + 24 * 2);
- show_ch2(1, 6, 39, ch2 + 24 * 3);
- show_ch2(1, 6, 52, ch2 + 24 * 4);
- show_ch2(2, 6, 0 * 12, ch2 + 24 * 5);
- show_ch1(2, 6, 1 * 12, ch1 + 12 * 0);
- show_ch1(2, 6, 6 * 6, ch1 + 12 * 19);
- show_ch1(2, 6, 7 * 6, ch1 + 12 * 20);
-
- while(1)
- {
- ADDA=0;
- ADDB=0;
- ADDC=0;
- adc();
- display0();
-
- ADDA=1;
- adc();
- display1();
-
- ADDA=0;
- ADDB=1;
- adc();
- display2();
-
- ADDA=1;
- adc();
- display3();
- if (SOC>95)
- {
- targetM = 0;
- }
- if (V <20)
- {
- targetM = 0;
- }
- if (VOLT > 390)
- {
- targetM = 0;
- }
- if (targetM > 150)
- {
- targetM = 0;
- }
- else if(targetM > 100)
- {
- targetM = targetM*0.5;
- }
-
- if (time1 > 100)
- {
- time1 = 0;
- num1 = Inpluse*103/27 ;
- Inpluse = 0;
- PIDControl();
- PWM =D;
- }
- display4();
-
- }
- }
- //-------------------------------
- //定时器0
- //-------------------------------
- void Timer0(void) interrupt 1
- {
-
- // TH0 = 0XFF; //重装初值
- // TL0 = 0X9c; //标准值
- // TL0 = 0Xb8; //包含误差
- TH0=0XFF;
- TL0=0X37;
- time++;
- if (time >= 100) //PWM周期为100*0.1ms
- time = 0;
- if (time < PWM)
- IN01 = 1;
- else
- IN01 = 0;
- time1++; //转速测量周期
- }
- 完整代码见附件
复制代码
完整仿真文件和C源码程序:
51单片机程序和电路仿真.zip
(120.2 KB, 售价: 10 E币)
【必读】版权免责声明
1、本主题所有言论和内容纯属会员个人意见,与本论坛立场无关。2、本站对所发内容真实性、客观性、可用性不做任何保证也不负任何责任,网友之间仅出于学习目的进行交流。3、对提供的数字内容不拥有任何权利,其版权归原著者拥有。请勿将该数字内容进行商业交易、转载等行为,该内容只为学习所提供,使用后发生的一切问题与本站无关。 4、本网站不保证本站提供的下载资源的准确性、安全性和完整性;同时本网站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。 5、本网站所有软件和资料均为网友推荐收集整理而来,仅供学习用途使用,请务必下载后两小时内删除,禁止商用。6、如有侵犯你版权的,请及时联系我们(电子邮箱1370723259@qq.com)指出,本站将立即改正。
|
|