⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 s12温度控制程序,包括模糊控制和LCD程序
💻 C
字号:
/********************************************************/
//PORTA的低三位做选通控制口,TC0作为输入捕捉口,TC2定时中断
//串口不断发送数据,并接收数据中断允许
/********************************************************/

#include <hidef.h>      /* common defines and macros */
#include "all_head.h"
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

uchar FreqSetValue = 35;
int control_value[NUM];  //用于存放实际给固态继电器的输出值
int fuzzy_value[NUM];    //用于存放模糊控制器输出值
int pulse = 0;
int Freq = 0;
int k = 0;    //看采样脉冲个数时用
int flag = 0;
uchar value = 1;
int E  = 10;              
int EC = 20;
int E1 = 0;
uchar U[8] = {1,1,1,1,1,1,1,1}; //用于暂存八路控制器的实际输出值
char channel = 0;    // be used in fuzzy control
char list = 0;       // be used in display of Sci0

char feedback1[]  = "channel_No";
char feedback2[]  = "_feedback is ";
int DisplayValue[8]={0,0,0,0,0,0,0,0};  //用于保存当前反馈值的数组,给显示函数调用
int SampArray[NUM];                     //用于保存采样数据的数组
int SampNum = 0;                        //用于保存采样数据的数组下标
char NowChannel = 0;                    //全局变量,表示当前通道号,用于实时显示

void main(void) 
{
  /* put your own code here */
  EnableInterrupts;
  IO_Ini();                  //系统I/O口初始化
  PWM_Ini();                 //PWM初始化
  Time_Ini();                //initial the timer interrupt & Pulse Accumulator  
  LCD_Ini();                 //LCD初始化
  Sci0_Ini();
/*********改用LCD显示当前数据*********/
  
 // Sci0_Ini();                //initial the SCI  
 // ChannelChoose(channel);
  //DisplayTab();
  for(;;) 
  {   
    Getkey();               //获取按键信息
    //Sci0Write_string("hello scut!");
  } 
  /* please make sure that you never leave this function */
}



/*********定时中断服务程序*********/
#pragma CODE_SEG NON_BANKED           //定时中断
interrupt 10 void TimerC2I(void) 
{

  if(PORTB_BIT0 == 1)                 //用于调试方便
 	  PORTB_BIT0 = 0;                   //灯亮
 	else  
 	  PORTB_BIT0 = 1;                   //灯灭
 	
 	FreqControl();                      //主控制程序,包括模糊控制,LCD实时显示等
  //DisplayFeedbackValue();
  //Sci0Write_string("hello scut!");
  
  TC2 += 31250;             //赋值TC2,使能下次定时时间仍为0.5s
  TFLG1_C2F = 1;          //清除标志寄存器 
/*
-------------------------------------------------
            time  625    3125   6250    31250
  the set of TC2  10ms   50ms   0.1s    0.5s
-------------------------------------------------
*/
  
}
#pragma CODE_SEG DEFAULT  



/***********串口中断服务程序************/
#pragma CODE_SEG NON_BANKED            //串口中断服务程序
interrupt 20 void SCI0_ISR(void)
{
  FreqSetValue = Sci0Read();
  Sci0Write_string("the setpoint is ");
  Sci0_Sendvalue(FreqSetValue); 
  Sci0_Sendbyte('\n');           
}
#pragma CODE_SEG DEFAULT 





 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -