STM32单片机源程序如下:- /************************************************************
- **实验名称:
- **功能:
- **注意事项:显示汉字采用了两种方式,一种是代码字库,一种是外FLASH字库.
- **作者:
- *************************************************************/
- #include "STM32Lib\\stm32f10x.h"
- #include "hal.h"
- #include "TFT\\TFTdriver.h"
- //#include "bmp_data.h"
- #include "KeyManage.h"
- #include <math.h>
- u16 temprature=100;//当前温度
- //u8 temprature_wei[]={0,0,1}; //小数--各位--十位
- u16 set_temprature=100;//设定温度。最后一位是小数
- u8 set_wei[]={0,0,1};//小数 --个位-- 十位
- char string1[]="当前温度:10.0毒";
- char string2[]="设定温度:10.0毒";
- char string3[]="请设定温度";
- extern void USART1_Putc(unsigned char c);
- extern void USART2_Putc(unsigned char c);
- extern void PID_temp(void);
- extern void PID_Ctrl(void);//增量式PID
- u16 temp[200]={0};//温度存储共1000s
- u8 flag=0;//超过200s的标志
- u16 temp_geshu=0;
- u8 flag_1s=0;//1s中断
- u8 flag_3s=0;//3s中断
- u8 heat_pwm=0;//加热时长
- u8 state=0;//当前状态 0--请输入数据 ;1--加热中;2--冷却中;//3--稳态
- int main(void)
- {
- // u32 i,j,k;
- ChipHalInit(); //片内硬件初始化
- ChipOutHalInit(); //片外硬件初始化
-
- Lcd_Init(); //初始化
- TFTRect(10,10,230,310,BLACK);
- TFTHLine(10,30,220,BLACK);
- TFTHLine(10,50,220,BLACK);
-
- BG_COLOR=GRAY1;//设置底色
- TFTShowString16(20,12,string1,RED,0);
-
-
-
- TFTShowString16(20,32,string2,BLUE,0);
- // BG_COLOR=RED;
- TFTShowString16(20,72,string3,RED,0);
-
- //TFTShowBmp(120,120,64,64,(COLOR*)Bmp_1);
- // TFTShowASC816(92,12,'0',RED);
- ////////坐标系
- BG_COLOR=GRAY1;//设置底色
- TFTRectFill(11,100,229,300,GRAY1);//清空
- TFTHLine(11,300,219,GREEN); //0度每格0.5度
- TFTShowString16(11,300-8," 0",RED,0);
- TFTHLine(11,280,219,GREEN);
- TFTShowString16(11,280-8,"10",RED,0);
- TFTHLine(11,260,219,GREEN);
- TFTShowString16(11,260-8,"20",RED,0);
- TFTHLine(11,240,219,GREEN);
- TFTShowString16(11,240-8,"30",RED,0);
- TFTHLine(11,220,219,GREEN);
- TFTShowString16(11,220-8,"40",RED,0);
- TFTHLine(11,200,219,GREEN);
- TFTShowString16(11,200-8,"50",RED,0);
- TFTHLine(11,180,219,GREEN);
- TFTShowString16(11,180-8,"60",RED,0);
- TFTHLine(11,160,219,GREEN);
- TFTShowString16(11,160-8,"70",RED,0);
- TFTHLine(11,140,219,GREEN);
- TFTShowString16(11,140-8,"80",RED,0);
- for(;;)
- {
- ManageKey(PollingKey());
- // USART1_Putc('a');
- /* for(j=0;j<200;j++)
- {
- TFTHLine(11,150,230,BLACK);
- for(i=0;i<200;i++)
- {
- TFTPoint(i+11,150-(signed char)(sin(3.14*(i+j)/100)*50),RED);
- }
- for(k=0;k<30000;k++);
- TFTRectFill(11,100,211,200,GRAY1);
- } */
- if(flag_1s)
- {
- flag_1s=0;
-
- USART2_Putc(temprature/100+'0');
- USART2_Putc(temprature%100/10+'0');
- USART2_Putc('.');
- USART2_Putc(temprature%10+'0');
- USART2_Putc(',');
- if(temp_geshu<199&&temp_geshu>0)
- {
- temp[temp_geshu]=temprature; //29-229绘图
- temp_geshu++;
- TFTPoint(29+temp_geshu,300-temprature/5,RED);
- }
- else if(temp_geshu==0)
- {
- temp[temp_geshu]=temprature; //29-229绘图
- temp_geshu++;
- ////////重画坐标系
- TFTRectFill(11,100,229,300,GRAY1);//清空
- TFTHLine(11,300,219,GREEN); //0度每格0.5度
- TFTShowString16(11,300-8," 0",RED,0);
- TFTHLine(11,280,219,GREEN);
- TFTShowString16(11,280-8,"10",RED,0);
- TFTHLine(11,260,219,GREEN);
- TFTShowString16(11,260-8,"20",RED,0);
- TFTHLine(11,240,219,GREEN);
- TFTShowString16(11,240-8,"30",RED,0);
- TFTHLine(11,220,219,GREEN);
- TFTShowString16(11,220-8,"40",RED,0);
- TFTHLine(11,200,219,GREEN);
- TFTShowString16(11,200-8,"50",RED,0);
- TFTHLine(11,180,219,GREEN);
- TFTShowString16(11,180-8,"60",RED,0);
- TFTHLine(11,160,219,GREEN);
- TFTShowString16(11,160-8,"70",RED,0);
- TFTHLine(11,140,219,GREEN);
- TFTShowString16(11,140-8,"80",RED,0);
- TFTPoint(29+temp_geshu,300-temprature/5,RED);
-
- }
- else if(temp_geshu==199)
- {
- temp[temp_geshu]=temprature; //29-229绘图
- temp_geshu=0;//个数回零
- TFTPoint(29+temp_geshu,300-temprature/5,RED);
- }
- }
- if(flag_3s)
- {
- PID_temp();
- PID_Ctrl();
- flag_3s=0;
- // heat_pwm=45;
- }
- }
- }
复制代码
原理图:无
仿真:无
程序:
程序.7z
(167.36 KB, 下载次数: 60)
|