#include"msp430f169.h"
//#include "keypad.h"
#include "1602(zhp)LT.h"
//#include"舵机.h"
#include"BoardConfig.h"
/********************************************
软件延时
********************************************/
//typedef unsigned int uint;
//typedef unsigned char uchar;
#define CPU_F ((double)8000000)
#define DELAY_US(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define DELAY_MS(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define num 20
unsigned char wan,qian,bai,shi,ge;
unsigned int results[num]={0};
unsigned char t=0;
unsigned int ave=0;
unsigned int filter[2];
void transform(unsigned int dat)
{
wan=dat/10000+0x30;
qian=dat%10000/1000+0x30;
bai=dat%1000/100+0x30;
shi=dat%100/10+0x30;
ge=dat%10+0x30;
}
void main()
{
WDTCTL = WDTPW+WDTHOLD; //关闭看门狗
BCSCTL1 &= ~XT2OFF;
while(IFG1&OFIFG)
{
IFG1&= ~OFIFG;
DELAY_US(50);
}
BCSCTL2 |= SELM_2+SELS+DIVS_3; //MCLK 8M,SMCLK 1M
lcd_init1602 ();
//keypad_init();
//write1char1602(0,0,i/10+0x30);
//BoardConfig(0xb8);//11111000
//_EINT();
WDTCTL=WDTPW+WDTHOLD;
P6SEL|=BIT1;
ADC12CTL0=ADC12ON+SHT0_8+SHT1_8+MSC;
ADC12CTL1=SHP+CONSEQ_2+CSTARTADD_1;
ADC12MCTL1=INCH_1;
ADC12IE=BIT1;
ADC12CTL0|=ENC;
_EINT();
ADC12CTL0|=ADC12SC;
while(2);
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR()
{
ADC12IFG=0X00;
t++;
filter[0]=ADC12MEM0;
if(filter[0]-filter[1]>5)
ave=ave+filter[1];
else
ave=ave+filter[0];
if(t==11)
{
t=0;
ave=(unsigned int)(ave/11);
transform(ave);
write1char1602(0,0,wan);
write1char1602(1,0,qian);
write1char1602(2,0,bai);
write1char1602(3,0,shi);
write1char1602(4,0,ge);
ave=0;
}
filter[1]=filter[0];
}
真的被困扰了很久很久啊,总是解决不了,都快疯了。。
此帖出自
小平头技术问答
一周热门 更多>