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

📄 main.c

📁 使用MSP430f247芯片内的ADC12模块实现单通道动态采集外部电压
💻 C
字号:
//****************************************************
//----------------------------------------------------
//------------长江大学创新实验室----------------------
//本程序主要实现msp430f247片内ADC12模块通过A0通道采集
//电压值,
//                ----------
//           XIN-|          |->p4
//          XOUT-|          |->p5.0(RS)
//               |          |->p5.1(RW)
//               |          |->p5.2(E)
///              |          |<-p6.0
//               |          |
//               |          |
//               |          |

//***************2008.8.20********杨懿*****************
//*****************************************************
#include "AD12.h"


float Voltager,SUM_Voltage,Voltage_ave;
unsigned int Ad_Mem[16];
unsigned int Ad_result;
int  Voltage_l,Voltage_ln,Voltage_hn,Voltage_h,Voltage_s;
//****************************
//主函数     实现单通道多次转换
//****************************
int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  P1DIR=0X00;
  P1OUT=0XFF;
  int T;  
  while(1){
    T=10;
    SUM_Voltage=0;
    while(T--)
    { 
          Init_Sys();
          LCD_Init();
          AD_MOD(0,2);//首地址0  单通道多次转换
          S_INCH(0,0,0,1,1);
          ADopen(1);
          AD_start();
          ADopen(0);
          Voltager=(2.5*Ad_result)/4095;
          SUM_Voltage+=Voltager; 
       
     }
  Voltage_ave=SUM_Voltage/10;//取10次平均值
  Voltage_s=(int)(Voltage_ave*1000);
  Voltage_l=(int)Voltage_s%10;
  Voltage_ln=(int)((Voltage_s-Voltage_l)/10)%10;
  Voltage_hn=(int)(((Voltage_s-Voltage_l)/10-Voltage_ln)/10)%10;
  Voltage_h=(((Voltage_s-Voltage_l)/10-Voltage_ln)/10-Voltage_hn)/10;
  LCD_display(0x84,Voltage_h+48);// 电压值显示
  LCD_display(0x85,'.');
  LCD_display(0x86,Voltage_hn+48);
  LCD_display(0x87,Voltage_ln+48);
  LCD_display(0x88,Voltage_l+48);
  LCD_display(0x8A,'V');
  delay(50000);
  }
  
}


//***********************

//初始化

//**********************
void Init_Sys()
{
  
  P6SEL|=0X01;
  AD12Init();
  _EINT();
  unsigned int i;
 int *mem=ADC12MEM;
  for(i=0;i<16;i++)
  {
    Ad_Mem[i]=0xff;
    *mem=0xff;
    mem++;
  }
}



⌨️ 快捷键说明

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