//******************************************************************************
// MSP-FET430P140 Demo - ADC12, Using the Internal Reference
//
// Description:
//
//
// MSP430F149
// ---------------
// | |
// Vin -->|P6.0/A0 |
// | |
//
//
// ZhenHua Liu
// NWSUAF.
// 2017,12,05
// Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************
#include
#include"adc.h"
void DelayXms(unsigned int i); //delay about x ms
void uartInit(); //Init the usart0
void sendChar(char c); //send a char
void sendString(unsigned char *p); //send a string,input must be pointer
void int2charssend(int value); //convert the adc value to string and send it
void main(void)
{
int adcValue1,adcValue2;
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
uartInit(); //init the uart
while (1)
{
adcValue1 = GetAdcValue1();
// adcValue2 = GetAdcValue2();
int2charssend(adcValue1);
DelayXms(2000);
}
}
/****************************************************************************
*函数名: DelayXms() /
*作用 :800KHz下大约1ms /
*返回值:无 /
*参数 :一个字符 /
*作者 :Zhenhua Liu /
*时间 :2017.12.07 /
*****************************************************************************/
void DelayXms(unsigned int i){
unsigned int j;
for( ; i>0; i--){
for(j=0;j<200;j++);
}
}
/****************************************************************************
*函数名: int2charssend() /
*作用 :启动ADC转化之后,将P6.0口的模拟信号转化为数字量(0-4096)并通过串口发送 /
*返回值:无 /
*参数 :整数 /
*作者 :Zhenhua Liu /
*时间 :2017.12.07 /
*****************************************************************************/
void int2charssend(int value){
unsigned char s[] = "0000";
unsigned char *p;
int bits=0,ten = 0,hundred = 0,thousand = 0;
thousand = value/1000;
hundred = value%1000/100;
ten = value%100/10;
bits = value%10;
s[0]=thousand+'0';
s[1]=hundred+'0';
s[2]=ten+'0';
s[3]=bits+'0';
p = s;
sendString(p);
}
/****************************************************************************
*函数名: sendChar() /
*作用 :USART0发送一个字符 /
*返回值:无 /
*参数 :一个字符 /
*作者 :Zhenhua Liu /
*时间 :2017.12.07 /
*****************************************************************************/
void sendChar(char c){
TXBUF0=c;
while((UTCTL0&0X01)==0);//等待数据发送完毕
}
/****************************************************************************
*函数名: sendString() /
*作用 :USART0发送字符串 /
*返回值:无 /
*参数 :char型指针 /
*作者 :Zhenhua Liu /
*时间 :2017.12.07 /
*****************************************************************************/
void sendString(unsigned char *p){
while(*p!=''){
TXBUF0=*p++;
while((UTCTL0&0X01)==0);//等待数据发送完毕
}
}
/****************************************************************************
*函数名: uartInit() /
*作用 :USART0的初始化配置,使用P3.4和P3.5,不使用中断 /
*返回值:无 /
*参数 :无 /
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』