#include "msp430x14x.h"
#define uint unsigned int
#define uchar unsigned char
uint Results[32]; //存放ADC的转换结果
uint Average;
uchar duma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar wema[]={0x01,0x02,0x04,0x08};
uchar DispBuf[]={0,0,0,0};
void delay(uint z)
{
uint x;
for(x=z;x>0;x--);
}
void display(uint z)
{ uint a,b,c,d;
a=Z/1000;
b=Z%1000/100;
c=Z%100/10;
d=Z%10;
P3OUT=duma[a]&0x7f;
P4OUT=wema[0];
delay(100);
P3OUT=duma
;
P4OUT=wema[1];
delay(100);
P3OUT=duma[c];
P4OUT=wema[2];
delay(100);
P3OUT=duma[d];
P4OUT=wema[3];
delay(100);
}
void main( void )
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗定时器
P6SEL|=0x01; //使能AD转换通道A0
ADC12CTL0=ADC12ON+SHT0_15+MSC; //打开ADC12,
ADC12CTL1=SHP+CONSEQ_2; //使用采样定时器,单通道多次转换
ADC12IE=0x01; //使能ADC12中断标志位ADC12IFG.0
ADC12CTL0|=ENC; //使能转换
P3DIR=0xff;
P4DIR=0xff;
_EINT();
ADC12CTL0|=ADC12SC; //开始转换
while(1)
{
_BIS_SR(LPM0_bits+GIE); //使能LPM0,使能
}
}
#pragma vecor=ADC_VECTOR
_interrupt void ADC12ISR(void)
{
static ucahr index=0;
Results[index++]=ADC12MEM0; //转移结果
if(index==31)
{
uchar i;
Average=0;
for(i=0;i<32;i++)
Average+=Results;
Average>>5; //除以32求平均
display();
index=0;
_BIC_SR_IRQ(LPM_bits); //清除低功耗模式0
}
}
前面的函数没有问题,就是下面的中断服务函数出现了两个错误和两个警告,我实在改不出来,请帮我看一下吧谢了
Warning[Pe161]: unrecognized #pragma
Error[Pe077]: this declaration has no storage class or type specifier
Error[Pe065]: expected a ";"
Warning[Pe012]: parsing restarts here after previous syntax error
此帖出自小平头技术问答
这是什么程序呀,那么多错误,真是难!
改后:
#include "msp430x14x.h"
typedef unsigned int uint;
typedef unsigned char uchar;
uint Results[32]; //存放ADC的转换结果
uint Average;
uchar duma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar wema[]={0x01,0x02,0x04,0x08};
uchar DispBuf[]={0,0,0,0};
void delay(uint z)
{
uint x;
for(x=z;x>0;x--);
}
void display(uint z)
{
uint a,b,c,d;
a=Z/1000;
b=Z%1000/100;
c=Z%100/10;
d=Z%10;
P3OUT=duma[a]&0x7f;
P4OUT=wema[0];
delay(100);
P3OUT=duma[1];
P4OUT=wema[1];
delay(100);
P3OUT=duma[c];
P4OUT=wema[2];
delay(100);
P3OUT=duma[d];
P4OUT=wema[3];
delay(100);
}
void main( void )
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗定时器
P6SEL|=0x01; //使能AD转换通道A0
ADC12CTL0=ADC12ON+SHT0_15+MSC; //打开ADC12,
ADC12CTL1=SHP+CONSEQ_2; //使用采样定时器,单通道多次转换
ADC12IE=0x01; //使能ADC12中断标志位ADC12IFG.0
ADC12CTL0|=ENC; //使能转换
P3DIR=0xff;
P4DIR=0xff;
_EINT();
ADC12CTL0|=ADC12SC; //开始转换
while(1)
{
_BIS_SR(LPM0_bits+GIE); //使能LPM0,使能
}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR(void)
{
static uchar index=0;
Results[index++]=ADC12MEM0; //转移结果
if(index==31)
{
uchar i;
Average=0;
for(i=0;i<32;i++)
Average+=Results;
Average>>=5; //除以32求平均
display(100);
index=0;
_BIC_SR_IRQ(LPM0_bits); //清除低功耗模式0
}
}
一周热门 更多>