|
麻烦大家看看问题出在哪啊? (程序有点长,主要好像是中断有问题)
[复制链接]
#include
#include "Cry1602.h"
#define uchar unsigned char
uchar shuzi[] = {"0123456789"};
uchar zimu1[] = {"abcdefghigklmnopqrstuvwxyz"};
uchar zimu2[] = {"ABCDEFGHIGKLMNOPQRSTUVWXYZ"};
uchar *fuhao = "~`!@#$%^&*()_+-=/|,.、;'<>?:""";
uchar *jieshu = "This is the end!";
unsigned int i=0,left_1=0,left_2=0;
unsigned int ave_A0,ave_A1,ave_A2,ave_A3;
unsigned int A0result[8],A1result[8],A2result[8],A3result[8];
unsigned char index=0;
void delay(unsigned int x)
{
unsigned int y,z;
for(y=0;y
for(z=0;z<1000;z++);
}
/***********************主函数************************/
void main( void )
{
WDTCTL=WDTPW+WDTHOLD; //关闭看门狗
P1SEL =BIT3+BIT2; //P1.2和P1.3作为捕获模块功能的输入端输入方波
BCSCTL1&=~XT2OFF; //打开XT2振荡器
P2DIR|=0xff;
P5DIR|=0xff; //超声波测距触发脚
P2OUT=0x00;
P6SEL|=0x0f; // P6.0,1,2,3为采集端
do
{
IFG1 &= ~OFIFG; // 清除振荡器失效标志
for (i=256;i>0;i--); // 延时,等待XT2起振
}
while ((IFG1 & OFIFG) != 0); // 判断XT2是否起振
BCSCTL2 =SELM_2+SELS; //选择MCLK=SMCLK为XT2 //-----------------------------
TACCTL2&=~(CCIS1+CCIS0); // 捕获源为P1.2,即CCI0A(也是CCI0B)
TACCTL2 =CM_2+SCS+CAP; //下降沿捕获,同步捕获,工作在捕获模式
TACCTL2 |=CCIE; //允许捕获比较模块提出中断请求
TACCTL1&=~(CCIS1+CCIS0); // 捕获源为P1.3,即CCI1A(也是CCI1B)
TACCTL1 =CM_2+SCS+CAP; //下降沿捕获,同步捕获,工作在捕获模式
TACCTL1 |=CCIE; //允许捕获比较模块提出中断请求
ADC12CTL0=ADC12ON+MSC+SHT0_12;
ADC12CTL1=SHP+CONSEQ_3;
ADC12MCTL0=INCH_0;
ADC12MCTL1=INCH_1;
ADC12MCTL2=INCH_2;
ADC12MCTL3=INCH_3+EOS;
ADC12IE=0x08;
ADC12CTL0|=ENC;
TACTL |=TACLR; //定时器清零,
TACTL |=ID_3;
TACTL |=TASSEL_2; //选择时钟MCLK
//定时器开始计数(连续计数模式0~0xFFFF)
TACTL |=MC_2; _EINT();
while(1)
{
unsigned char ge,shi,bai,qian,wan;
unsigned int Delay=50;
P5OUT=0x00;
delay(20);
P5OUT=BIT0;
while(Delay--);
P5OUT=0x00;
Delay=50;
P5OUT=0x00;
delay(20);
P5OUT=BIT1;
while(Delay--);
P5OUT=0x00;
delay(60000);
//*****************显示left_1的值**********************//
wan=left_1/10000;
qian=left_1%10000/1000;
bai=left_1%1000/100;
shi=left_1%100/10;
ge=left_1%10;
LcdReset();
LcdWriteCommand(0x01, 1); //清除显示
Disp1Char(0,1,shuzi[wan]);
Disp1Char(1,1,shuzi[qian]);
Disp1Char(2,1,shuzi[bai]);
Disp1Char(3,1,shuzi[shi]);
Disp1Char(4,1,shuzi[ge]);
//*****************显示left_2的值**********************//
wan=left_2/10000;
qian=left_2%10000/1000;
bai=left_2%1000/100;
shi=left_2%100/10;
ge=left_2%10;
Disp1Char(0,0,shuzi[wan]);
Disp1Char(1,0,shuzi[qian]);
Disp1Char(2,0,shuzi[bai]);
Disp1Char(3,0,shuzi[shi]);
Disp1Char(4,0,shuzi[ge]);
wan=ave_A0/10000;
qian=ave_A0%10000/1000;
bai=ave_A0%1000/100;
shi=ave_A0%100/10;
ge=ave_A0%10;
Disp1Char(5,0,shuzi[wan]);
Disp1Char(6,0,shuzi[qian]);
Disp1Char(7,0,shuzi[bai]);
Disp1Char(8,0,shuzi[shi]);
Disp1Char(9,0,shuzi[ge]);
wan=ave_A1/10000;
qian=ave_A1%10000/1000;
bai=ave_A1%1000/100;
shi=ave_A1%100/10;
ge=ave_A1%10;
Disp1Char(5,1,shuzi[wan]);
Disp1Char(6,1,shuzi[qian]);
Disp1Char(7,1,shuzi[bai]);
Disp1Char(8,1,shuzi[shi]);
Disp1Char(9,1,shuzi[ge]);
wan=ave_A2/10000;
qian=ave_A2%10000/1000;
bai=ave_A2%1000/100;
shi=ave_A2%100/10;
ge=ave_A2%10;
Disp1Char(10,1,shuzi[wan]);
Disp1Char(11,1,shuzi[qian]);
Disp1Char(12,1,shuzi[bai]);
Disp1Char(13,1,shuzi[shi]);
Disp1Char(14,1,shuzi[ge]);
wan=ave_A3/10000;
qian=ave_A3%10000/1000;
bai=ave_A3%1000/100;
shi=ave_A3%100/10;
ge=ave_A3%10;
Disp1Char(10,0,shuzi[wan]);
Disp1Char(11,0,shuzi[qian]);
Disp1Char(12,0,shuzi[bai]);
Disp1Char(13,0,shuzi[shi]);
Disp1Char(14,0,shuzi[ge]);
}
}
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
{
_EINT();
switch(TAIV)
{
case 2:
if(TACCTL1&CM0) //捕获到上升沿
{
TACTL |=TACLR;
TACTL |=ID_3;
TACTL |=TASSEL_2; //选择时钟MCLK
TACCTL1=(TACCTL1&(~CM0))| CM1; //改为下降沿捕获:CM0置零,CM1置一
}
else if(TACCTL1&CM1) //捕获到下降沿
{
left_1=TACCR1;
TACCTL1=(TACCTL1&(~CM1))| CM0; //改为下降沿捕获:CM1置零,CM0置一
}
break;
case 4:
if(TACCTL2&CM0) //捕获到上升沿
{
TACTL |=TACLR;
TACTL |=ID_3;
TACTL |=TASSEL_2; //选择时钟MCLK
TACCTL2=(TACCTL2&(~CM0))| CM1; //改为下降沿捕获:CM0置零,CM1置一
}
else if(TACCTL2&CM1) //捕获到下降沿
{
left_2=TACCR2;
TACCTL2=(TACCTL2&(~CM1))| CM0; //改为下降沿捕获:CM1置零,CM0置一
}
break;
case 10: break;
}
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR(void)
{
unsigned int sum_A0,sum_A1,sum_A2,sum_A3;
A0result[index]=ADC12MEM0;
A1result[index]=ADC12MEM1;
A2result[index]=ADC12MEM2;
A3result[index]=ADC12MEM3;
index++;
if(index==8)
{
for(index=0;index<8;index++)
{
sum_A0+=A0result[index];
sum_A1+=A1result[index];
sum_A2+=A2result[index];
sum_A3+=A3result[index];
}
ave_A0=(int)(sum_A0/8);
ave_A1=(int)(sum_A1/8);
ave_A2=(int)(sum_A2/8);
ave_A3=(int)(sum_A3/8);
}
P2OUT^=BIT0;
}
用示波器测P2.0根本就没波形啊,根本进不了ADC中断啊
|
|