码迷,mamicode.com
首页 > 其他好文 > 详细

TI MSP430工程配置及2019年电赛A题编程示例(使用430 F5529)

时间:2019-08-11 14:55:13      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:检查   图片   brief   stop   cti   sel   one   gen   src   

 

 

 配置

第一步:右击工程,选择Options

技术图片

 

第二步:在General Options的Target选项卡里选择对应的器件Device,这里是MSP430G2231

技术图片

 

 第三步:在Debugger里选择FET Debugger:

 技术图片

 

第四步: 检查FET Debugger里的设置是否正确,这里是Texas Instrument USB-IF采用Automatic方式

这里选择Automatic与Automatic selection,当用串口会自动连接上串口。

 技术图片

 

 第五步:编译程序,下载验证

 

 

电赛A题源码

小车代码

技术图片
/*!
 *     COPYRIGHT NOTICE
 *     Copyright (c) 2016,CTGU-GB
 *     All rights reserved.
 *
 *
 * @file       main.c
* @brief      MSP430F5529 平台主程序

 * @author     CTGU-GB
 * @version    v2.7
 * @date       2016-11-26
 */
#include "include.h"
#include "KEY.h"


int key1,key2,stop_flag=0;

int key_flag = 0;

//定时器中断处理函数
uint16_t Motor1,Motor2;
__interrupt void TIMER_TB0_A0_IRQ_Handler()
{

   GPIO_TurnBit  (P4, 7);

}




//ADC 中断处理函数
float ad; 
uint16_t ADC_MCH1,ADC_MCH2,Motor1,Motor2;
__interrupt void ADC_IRQ_Handler()
{
   if(ADC_GetITStatus(ADC_CH2) == TRUE)
   {
      ad = ADC_ReadChanelValue (ADC_CH2)*3.3/1023;   //读取后会自动清除标志位
      ADC_ClearITPendingBit(ADC_CH2);
   }
   if(ADC_GetITStatus(ADC_CH1) == TRUE)
   {
      ad = ADC_ReadChanelValue (ADC_CH1)*3.3/1023;   //读取后会自动清除标志位
      ADC_ClearITPendingBit(ADC_CH1);
   }
   
}



uint8_t key_data()
{
    static _Bool glag=0;
    uint8_t key_value=0;
    if((KEY_isPressed(KEY1)==1||KEY_isPressed(KEY2)==1)&&glag==0)
    {
        DELAY_MS(100);
        if((KEY_isPressed(KEY1)==1||KEY_isPressed(KEY2)==1)&&glag==0)
        {
            glag=1;
            if(KEY_isPressed(KEY1)==1)   key_value=1;
            if(KEY_isPressed(KEY2)==1)   key_value=2;
        }
    }
    else if(KEY_isPressed(KEY1)==0||KEY_isPressed(KEY2)==0)  glag=0;
    
    return key_value;
}


void main()
{
  uint8_t key_val = 0;
  uint8_t Data[1];  
  int a,b,c = 0;
  DisableInterrupts();          //禁止总中断  
  
  LED_Init(LED_ALL);              //LED灯初始化
  KEY_Init(KEY1,NULL);
  KEY_Init(KEY2,NULL);
  //LED_On (LED1);
  OLED_Init();                    //Oled初始化
  GPIO_Init(P3,0,GPI|PULL_UP);
  GPIO_Init(P3,1,GPI|PULL_UP);
  GPIO_Init(P2,1,GPI|PULL_UP);
  GPIO_Init(P1,1,GPI|PULL_UP);
  GPIO_Init(P7,0,GPI|PULL_UP);
   //GPIO_ReadBit(P2,1) == 0  读取按键按下为0
  
  
  //ADC配置///
  ADC_Init(ADC_CH1,ADC_VREF_3_3V,ADC_10bit);       //初始化通道,P6.1
  
  
//  定时器配置
    Set_Vector_Handler(VECTOR_TIMER0_B0,TIMER_TB0_A0_IRQ_Handler);   //设置定时器TA1的中断服务程序为:TIMER1_A0_IRQ_Handler
    
    TIMER_Interval_Ms(TIMER_B0, 500);    //设置TA1为定时中断,中断时间为500Ms
    TIMER_ITConfig (TIMER_B0, TIMER_CCR0_IRQn, ENABLE);            //使能TIMER的某一个中断
    ///////////////////////////////////////////////////////////////////////////////////////////// 
  
    
    
//  pwm配置
//   定时器PWM输出初始化
    TIMER_PWM_MultiChannel_Init(TIMER_A2, 1000, 2, TIMER_CH1, TIMER_CH2);
    //GPIO_ResetBits(PORT2, GPIO_Pin_4|GPIO_Pin_5);
  //TIMER_CH1\TIMER_CH2:{P2,4},{P2,5}
    //PWM输出占空比设置
    //999为满占空比与设置频率无关
    TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,50);  
    TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,50);
  ////////////////////////////////////////////////////////////////////////////////////////////////
    
    /*
   ///usrt配置//// 
   //配置串口1:TX={P4,4},.RX={P4,5}
  UART_Init        (UART1,9600);                      //初始化UART1模块,波特率115200,波特率高时最好把主时钟 设高些
  Set_Vector_Handler(VECTOR_UART1,UART_RX_IRQ_Handler);    //设置接收中断向量
  UART_ITConfig  (UART1,UART_RX_IRQn,TRUE);                //开串口接收中断
   //////////////////////////// 
   */
    
  EnableInterrupts();
  OLED_PrintfAt(FONT_ASCII_6X8,1,0,"function:");
  OLED_PrintfAt(FONT_ASCII_6X8,2,0,"ADC1:");//显示一个字符
  OLED_PrintfAt(FONT_ASCII_6X8,3,0,"key_count1:");//显示一个字符
  OLED_PrintfAt(FONT_ASCII_6X8,4,0,"key_count2:");//显示一个字符
  OLED_PrintfAt(FONT_ASCII_6X8,5,0,"recvie1:");//显示一个字符
  OLED_PrintfAt(FONT_ASCII_6X8,6,0,"recvie2:");//显示一个字符
  OLED_PrintfAt(FONT_ASCII_6X8,7,0,"Stop_flag:");//显示一个字符
  while(1)
  {
      
      /////////////////////要求2////////////////

         Data[0] = Flash_Read(MAX_SEGMENT,0,uint8_t); 
         OLED_PrintfAt(FONT_ASCII_6X8,1,70,"%d",Data[0]); 
         if(Data[0] == 2)
         {
            while(1){    
         float ad = ADC_ReadChanelOnce  (ADC_CH1)*3.3/1023;
         OLED_PrintfAt(FONT_ASCII_6X8,2,30,"%0.2f",ad);
        if(ad<0.5)
        {    
           

                      TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,500);   //
                      TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,500);   //
                      
                      while(1)
                      {
                          
                      if(KEY_isPressed(KEY2))
                      {
                          
                          key_flag =1;
                          break;
                      
                      }
                       //运行中检测是否在充电标志,中心
                      if(GPIO_ReadBit(P7,0) == 0 )
                       {    
                           TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,0);

                            TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,0);  
                            OLED_PrintfAt(FONT_ASCII_6X8,7,70,"%d",0);
                            stop_flag =1;
                            break;
                       }
                       else
                           OLED_PrintfAt(FONT_ASCII_6X8,7,70,"%d",1);    
                          
                          
                      a=GPIO_ReadBit(P3,0);
                      
                      b=GPIO_ReadBit(P3,1);
                      

                //////////        //检测左边是否到达
                       if(a)
                       {
                        TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,1000);

                        TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,300);  
                        OLED_PrintfAt(FONT_ASCII_6X8,5,50,"%d",1);
                       }
                        else{
                        OLED_PrintfAt(FONT_ASCII_6X8,5,50,"%d",0); //
                       }
                   
                 //////////        //检测右边是否到达     
                     if(b)
                       {
                       TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,300);  
                        TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,1000); 
                        
                       OLED_PrintfAt(FONT_ASCII_6X8,6,50,"%d",1); //
                     }
                     else{
                       OLED_PrintfAt(FONT_ASCII_6X8,6,50,"%d",0); //
                        
                       }
                     if(a == 0&b == 0) 
                     {
                         
                          TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,550);   //
                          TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,1000);   //
                         
                     }
                   
                    }  
                    if(stop_flag == 1)
                    {
                    stop_flag = 0;
                    break;
                    
                    }
                    
                     if(key_flag == 1)
                    {
                    key_flag = 0;
                    break;
                    
                    }
                    
                    
                }
         }
       }
       
      
      
       
 
   
       /////////////////////要求3////////////////////////////////

         Data[0] = Flash_Read(MAX_SEGMENT,0,uint8_t); 
         OLED_PrintfAt(FONT_ASCII_6X8,1,70,"%d",Data[0]); 
         if(Data[0] == 3)
         {
            while(1){    
         float ad = ADC_ReadChanelOnce  (ADC_CH1)*3.3/1023;
         OLED_PrintfAt(FONT_ASCII_6X8,2,30,"%0.2f",ad);
        if(ad<0.5)
        {    
           

                      TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,500);   //
                      TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,500);   //
                      
                      while(1)
                      {
                          
                        if(KEY_isPressed(KEY2))
                      {
                          
                          key_flag =1;
                          break;
                      
                      }   
                          
                          
                       //运行中检测是否在充电标志,中心
                      if(GPIO_ReadBit(P7,0) == 0 )
                       {    
                           
                            OLED_PrintfAt(FONT_ASCII_6X8,7,70,"%d",0);
                           
                       }
                       else
                           OLED_PrintfAt(FONT_ASCII_6X8,7,70,"%d",1);    
                          
                          
                      a=GPIO_ReadBit(P3,0);
                      
                      b=GPIO_ReadBit(P3,1);
                      

                //////////        //检测左边是否到达
                       if(a)
                       {
                        TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,1000);

                        TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,300);  
                        OLED_PrintfAt(FONT_ASCII_6X8,5,50,"%d",1);
                       }
                        else{
                        OLED_PrintfAt(FONT_ASCII_6X8,5,50,"%d",0); //
                       }
                   
                 //////////        //检测右边是否到达     
                     if(b)
                       {
                       TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,300);  
                        TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,1000); 
                        
                       OLED_PrintfAt(FONT_ASCII_6X8,6,50,"%d",1); //
                     }
                     else{
                       OLED_PrintfAt(FONT_ASCII_6X8,6,50,"%d",0); //
                        
                       }
                     if(a == 0&b == 0) 
                     {
                         
                          TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,550);   //
                          TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,1000);   //
                         
                     }
                   
                    }
                    
                    if(key_flag == 1)
                    {
                    key_flag = 0;
                    break;
                    
                    }
                   
         }
       }
 } 
  
  
 
 
 
 
 
 
 
 
 
 
 
 
 
       /////////////////////要求4/////////////////////////

         Data[0] = Flash_Read(MAX_SEGMENT,0,uint8_t); 
         OLED_PrintfAt(FONT_ASCII_6X8,1,70,"%d",Data[0]); 
         if(Data[0] == 4)
         {
            DELAY_MS(59000);
          while(1){    
         //float ad = ADC_ReadChanelOnce  (ADC_CH1)*3.3/1023;
         //OLED_PrintfAt(FONT_ASCII_6X8,2,30,"%0.2f",ad);
        
           

                      TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,500);   //
                      TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,500);   //
                      
                      while(1)
                      {
                          
                        if(KEY_isPressed(KEY2))
                      {
                          
                          key_flag =1;
                          break;
                      
                      }   
                          
                          
                       //运行中检测是否在充电标志,中心
                      if(GPIO_ReadBit(P7,0) == 0 )
                       {    
                           
                            OLED_PrintfAt(FONT_ASCII_6X8,7,70,"%d",0);
                           
                       }
                       else
                           OLED_PrintfAt(FONT_ASCII_6X8,7,70,"%d",1);    
                          
                          
                      a=GPIO_ReadBit(P3,0);
                      
                      b=GPIO_ReadBit(P3,1);
                      

                //////////        //检测左边是否到达
                       if(a)
                       {
                        TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,1000);

                        TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,300);  
                        OLED_PrintfAt(FONT_ASCII_6X8,5,50,"%d",1);
                       }
                        else{
                        OLED_PrintfAt(FONT_ASCII_6X8,5,50,"%d",0); //
                       }
                   
                 //////////        //检测右边是否到达     
                     if(b)
                       {
                       TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,300);  
                        TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,1000); 
                        
                       OLED_PrintfAt(FONT_ASCII_6X8,6,50,"%d",1); //
                     }
                     else{
                       OLED_PrintfAt(FONT_ASCII_6X8,6,50,"%d",0); //
                        
                       }
                     if(a == 0&b == 0) 
                     {
                         
                          TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH1,550);   //
                          TIMER_PWM_SetChannelDuty(TIMER_A2,TIMER_CH2,1000);   //
                         
                     }
                   
                    }
                    
                    if(key_flag == 1)
                    {
                    key_flag = 0;
                    break;
                    
                    }
                   
       
       }
 } 
  
       
 
 
       

      ///////////////////////////设置////////////////////
        //key1-p2.1
        //key2-p1.1

      //p2.1设置,p1.1确定
      while(1)
      {
               for(int i=0;i<1;i++)
          {
                Data[i] = Flash_Read(MAX_SEGMENT,i,uint8_t); 
                OLED_PrintfAt(FONT_ASCII_6X8,1,70,"%d",Data[i]); 
          }
                key_val = key_data();
                if(key_val)
                {
                    if(key_val == 1)
                    {
                        key2 ++;
                        OLED_PrintfAt(FONT_ASCII_6X8,4,70,"%d",key2); 
                    }
                    else
                    {       
                        //赋值
                        Data[0]=key2;
                        
                      //先清除flash,再存
                      Flash_Erase_Segment(MAX_SEGMENT); 
                      Flash_Write_buf (MAX_SEGMENT,0,1,Data);
                        
                      //数据清零
                      Data[0]=0;
                      
                        key1 ++;
                        OLED_PrintfAt(FONT_ASCII_6X8,3,70,"%d",key1); 
                        //再读取
                               for(int i=0;i<1;i++)
                      {
                            Data[i] = Flash_Read(MAX_SEGMENT,i,uint8_t); 
                            OLED_PrintfAt(FONT_ASCII_6X8,1,70,"%d",Data[i]); 
                            
                      }
                        if(Data[0] !=0) break;
                        
                    }
                }
                else 
                {
                    
                    //sOLED_PrintfAt(FONT_ASCII_6X8,3,70,"%d",0); 
                }
                
      }
      /////////////////////////////////////////////////////////////
      
      
  
  }
}
      
  
View Code

底板控制

技术图片
/*!
 *     COPYRIGHT NOTICE
 *     Copyright (c) 2016,CTGU-GB
 *     All rights reserved.
 *
 *
 * @file       main.c
* @brief      MSP430F5529 平台主程序

 * @author     CTGU-GB
 * @version    v2.7
 * @date       2016-11-26
 */
#include "include.h"



//定时器中断处理函数
uint16_t Motor1,Motor2;
__interrupt void TIMER_TB0_A0_IRQ_Handler()
{

   //GPIO_TurnBit  (P4, 7);

}


void main()
{
  
  int Kal = 0;
  DisableInterrupts();          //禁止总中断
  
  LED_Init(LED_ALL);              //LED灯初始化
  OLED_Init();                    //Oled初始化
  LED_Off(LED1);
  LED_Off(LED2);
  GPIO_Init(P6,0,GPI|PULL_UP);
  GPIO_Init(P6,1,GPI|PULL_UP);
  GPIO_Init(P6,2,GPI|PULL_UP);
  GPIO_Init(P6,3,GPI|PULL_UP); 
  
  GPIO_Init(P1,2,GPI|PULL_UP);
  GPIO_Init(P1,3,GPI|PULL_UP);
  GPIO_Init(P1,4,GPI|PULL_UP);
  GPIO_Init(P1,5,GPI|PULL_UP);
  
//  定时器配置
    Set_Vector_Handler(VECTOR_TIMER0_B0,TIMER_TB0_A0_IRQ_Handler);   //设置定时器TA1的中断服务程序为:TIMER1_A0_IRQ_Handler
    TIMER_Interval_Ms(TIMER_B0, 500);    //设置TA1为定时中断,中断时间为500Ms
    TIMER_ITConfig (TIMER_B0, TIMER_CCR0_IRQn, ENABLE);            //使能TIMER的某一个中断
    ///////////////////////////////////////////////////////////////////////////////////////////// 
    GPIO_ResetBits(PORT6, GPIO_Pin_1 |GPIO_Pin_2|GPIO_Pin_3);
    
  EnableInterrupts();
 
  while(1)
  {   
     
      /*
       //开发射圈1
       GPIO_SetBits(PORT6, GPIO_Pin_0);
        //关其他发射圈
       GPIO_ResetBits(PORT6, GPIO_Pin_1 |GPIO_Pin_2|GPIO_Pin_3);
      while(1)
      {
          
         while(GPIO_ReadBit(P1,2) ==1) 
              {
                  
              }
                LED_Off(LED1);
         while(GPIO_ReadBit(P1,2) ==0)

            {
                
            
            }
           LED_On(LED1);  
         while(GPIO_ReadBit(P1,2) ==1)

            {
                
            
            }
           LED_Off(LED1);
         GPIO_SetBits(PORT6, GPIO_Pin_0);  
              break;
       
      
      }
      */
      
      
      while(1)
      {
      
     

      if(GPIO_ReadBit(P1,3) == 0)
        {
            
           LED_On(LED1);
            //开发射圈1
            GPIO_SetBits(PORT6, GPIO_Pin_1);
            //关其他发射圈
            GPIO_ResetBits(PORT6, GPIO_Pin_2 |GPIO_Pin_3);
            
          while(GPIO_ReadBit(P1,3) ==0) 
              {
                  
              }
                LED_Off(LED1);
            while(GPIO_ReadBit(P1,3) ==1)

            {
                
            
            }
                LED_On(LED2);            
                
            while(GPIO_ReadBit(P1,3) ==0) 
              {
                  

              }
            LED_Off(LED2);        
            GPIO_ResetBits(PORT6, GPIO_Pin_1);
      }  
      
      
      
      
      else if(GPIO_ReadBit(P1,4) == 0)
         {
              LED_On(LED1);
            //开发射圈1
            GPIO_SetBits(PORT6, GPIO_Pin_2);
            //关其他发射圈
            GPIO_ResetBits(PORT6, GPIO_Pin_1 |GPIO_Pin_3);
            
          while(GPIO_ReadBit(P1,4) ==0) 
              {
                  
              }
                LED_Off(LED1);
            while(GPIO_ReadBit(P1,4) ==1)

            {
                
            
            }
                LED_On(LED2);            
                
            while(GPIO_ReadBit(P1,4) ==0) 
              {
                  

              }
            LED_Off(LED2);        
            GPIO_ResetBits(PORT6, GPIO_Pin_2);
      }  
      
      
      
      else if(GPIO_ReadBit(P1,5) == 0)
        {
             LED_On(LED1);
            //开发射圈1
            GPIO_SetBits(PORT6, GPIO_Pin_3);
            //关其他发射圈
            GPIO_ResetBits(PORT6, GPIO_Pin_1 |GPIO_Pin_2);
            
          while(GPIO_ReadBit(P1,5) ==0) 
              {
                  
              }
                LED_Off(LED1);
            while(GPIO_ReadBit(P1,5) ==1)

            {
                
            
            }
                LED_On(LED2);            
                
            while(GPIO_ReadBit(P1,5) ==0) 
              {
                  

              }
            LED_Off(LED2);        
            GPIO_ResetBits(PORT6, GPIO_Pin_3);
        }
      
     
      //GPIO_SetBits  (PORT1, GPIO_Pin_0|GPIO_Pin_1); //P1.0,P1.1输出高电平
      //GPIO_SetBits() ; 
          
      
        //////////////////延时////////////////////
        //DELAY_MS(500);

      
    }
  }
}
View Code

 

8.15号后会对代码思路及硬件做个记录。这几天会稍微休息一会。

 

TI MSP430工程配置及2019年电赛A题编程示例(使用430 F5529)

标签:检查   图片   brief   stop   cti   sel   one   gen   src   

原文地址:https://www.cnblogs.com/-wenli/p/11334865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!