/******************************************************************
**
** File : ADC.c | Analog to Digital converter |
** Version : 1.0
** Description : led 7 segment display Analog to Digital converter
** Author : LightWu
** Date : 2013-4-9
**
*******************************************************************/
#include "MSP430x24x.h"
#define uint unsigned int
#define uchar unsigned char
/***设置数码管显示****/
#define L1_OFF P4OUT|=BIT0 //关L1
#define L1_NO P4OUT&=~BIT0 //点亮L1
#define L2_OFF P4OUT|=BIT1 //关L2
#define L2_NO P4OUT&=~BIT1 //点亮L2
#define L3_OFF P4OUT|=BIT2 //关L3
#define L3_NO P4OUT&=~BIT2 //点亮L3
uchar const Segment1[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; //不带小数点编码
uchar const Segment2[]={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; //带小数点编码
uchar AdcFlag = 0;
uchar TempNum1;
uchar TempNum2;
uchar TempNum3;
void Display( uchar num1, uchar num2, uchar num3 );
void Delay(void)
{
uint m;
for(m=1000;m>0;m--);
}
void main(void)
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD; //关狗
P4DIR = 0XFF; //P4设置为输出,位码控制
P4SEL = 0;
P5DIR = 0XFF; //P5设置为输出,断码控制
P5SEL = 0;
P4OUT = 0XFF; //关闭数码管,共阳极数码管
ADC12CTL0 = SHT0_2 + ADC12ON; // Set sampling time, turn on ADC12
ADC12CTL1 = SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ENC; // Conversion enabled
P6DIR &= ~0x01; // P6.0, i/p
P6SEL |= 0x01; // P6.0-ADC option select
ADC12CTL0 |= ADC12SC; // 软件启动转换
_BIS_SR(GIE); //打开中断,需要注意,不打开不进入中断。
while(1)
{
if( 1 == AdcFlag )
{
AdcFlag = 0;
ADC12CTL0 |= ADC12SC; // Start convn, software controlledc,软件启动转换
Display(TempNum1,TempNum2,TempNum3); //显示转换值
}
}
}
//中断服务子程序
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
ADC12MEM0 = ADC12MEM0/16;
TempNum1 = ADC12MEM0/100; //百位
TempNum2 = ADC12MEM0/10%10; //十位
TempNum3 = ADC12MEM0%10; //个位
AdcFlag=1;
}
void Display( uchar num1, uchar num2, uchar num3 )
{
P5OUT = Segment1[ num1 ];//
L1_NO;
Delay();
L1_OFF;
P5OUT = Segment1[ num2 ];//
L2_NO;
Delay();
L2_OFF;
P5OUT = Segment1[ num3 ];//
L3_NO;
Delay();
L3_OFF;
//P4OUT = 0XF8; //关闭其余数码管
}
**
** File : ADC.c | Analog to Digital converter |
** Version : 1.0
** Description : led 7 segment display Analog to Digital converter
** Author : LightWu
** Date : 2013-4-9
**
*******************************************************************/
#include "MSP430x24x.h"
#define uint unsigned int
#define uchar unsigned char
/***设置数码管显示****/
#define L1_OFF P4OUT|=BIT0 //关L1
#define L1_NO P4OUT&=~BIT0 //点亮L1
#define L2_OFF P4OUT|=BIT1 //关L2
#define L2_NO P4OUT&=~BIT1 //点亮L2
#define L3_OFF P4OUT|=BIT2 //关L3
#define L3_NO P4OUT&=~BIT2 //点亮L3
uchar const Segment1[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; //不带小数点编码
uchar const Segment2[]={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; //带小数点编码
uchar AdcFlag = 0;
uchar TempNum1;
uchar TempNum2;
uchar TempNum3;
void Display( uchar num1, uchar num2, uchar num3 );
void Delay(void)
{
uint m;
for(m=1000;m>0;m--);
}
void main(void)
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD; //关狗
P4DIR = 0XFF; //P4设置为输出,位码控制
P4SEL = 0;
P5DIR = 0XFF; //P5设置为输出,断码控制
P5SEL = 0;
P4OUT = 0XFF; //关闭数码管,共阳极数码管
ADC12CTL0 = SHT0_2 + ADC12ON; // Set sampling time, turn on ADC12
ADC12CTL1 = SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ENC; // Conversion enabled
P6DIR &= ~0x01; // P6.0, i/p
P6SEL |= 0x01; // P6.0-ADC option select
ADC12CTL0 |= ADC12SC; // 软件启动转换
_BIS_SR(GIE); //打开中断,需要注意,不打开不进入中断。
while(1)
{
if( 1 == AdcFlag )
{
AdcFlag = 0;
ADC12CTL0 |= ADC12SC; // Start convn, software controlledc,软件启动转换
Display(TempNum1,TempNum2,TempNum3); //显示转换值
}
}
}
//中断服务子程序
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
ADC12MEM0 = ADC12MEM0/16;
TempNum1 = ADC12MEM0/100; //百位
TempNum2 = ADC12MEM0/10%10; //十位
TempNum3 = ADC12MEM0%10; //个位
AdcFlag=1;
}
void Display( uchar num1, uchar num2, uchar num3 )
{
P5OUT = Segment1[ num1 ];//
L1_NO;
Delay();
L1_OFF;
P5OUT = Segment1[ num2 ];//
L2_NO;
Delay();
L2_OFF;
P5OUT = Segment1[ num3 ];//
L3_NO;
Delay();
L3_OFF;
//P4OUT = 0XF8; //关闭其余数码管
}