这是我自己写的AD转换程序,没有错误,没有警告。但是就是无法显示AD转换的数据。弄了很久了。不知道问题在哪儿。请大家帮帮我,刚开始学430,完全0基础。感激大家。
#include
#include"ADC12.h"
#include "lcd_1602.h"
#define Num_of_Results 8
static unsigned int index=0;
//ADC多通道转换初始化
uint table[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
static unsigned int A0results[Num_of_Results];
static unsigned int A1results[Num_of_Results];
void Delay_1ms(void) //延时程序
{
uchar i,j;
for(i=0;i<2;i++)
for(j=0;j<10;j++);
}
void Adc_Init(void)
{
P6SEL=0x0a;////AD初始化
ADC12CTL0=ADC12ON+SHT0_8+MSC;
ADC12CTL1=SHP+CONSEQ_3; //序列通道多次转换
ADC12MCTL0=INCH_0; //内部参考电源ref+=AVcc=3.3V,通道A0
ADC12MCTL1=INCH_1+EOS; //ref+=AVcc,通道A1,最后通道
ADC12IE=0x02; //使能ADC12IFG
ADC12CTL0 |=ENC; //使能转换
_EINT();
ADC12CTL0 |=ADC12SC;
_BIS_SR(LPM0_bits);
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR(void)
{
static unsigned int index=0;
A0results[index]=ADC12MEM0; //存通道A0结果,清楚IFG
A1results[index]=ADC12MEM1; //存通道A1结果,清楚IFG
index=(index+1)%Num_of_Results;
}
void diaoyong()
{
unsigned int wt,wb,ws,wg,hb,ht,hs,hg;//,bt;
// volatile double bb,bs,bg;
wt=A0results[index];
wb=wt/100;
ws=wt%100/10;
wg=wt%10;
xianshiw(wb,ws,wg);
ht=A1results[index];
hb=ht/100;
hs=ht%100/10;
hg=ht%10;
xianshih( hb,hs,hg);
// bt=wt/(ht*ht);
//bb=bt/100;
//bs=bt%100/10;
//bg=bt%10;
// xianshib( hb,hs,hg);
}
void xianshiw(uint wb,uint ws,uint wg)//显示重量
{
void init_1602();
zhl_1602(0x84);
shj_1602(table[wb]);
zhl_1602(0x85);
shj_1602(table[ws]);
zhl_1602(0x86);
shj_1602(table[wg]);
}
void xianshih(uint hb,uint hs,uint hg)//显示身高
{
void init_1602();
zhl_1602(0x8b);
shj_1602(table[hb]);
zhl_1602(0x8c);
shj_1602(table[hs]);
zhl_1602(0x8d);
shj_1602(table[hg]);
}
//void xianshib(uint bb,uint bs,uint bg)//显示BIM
//{
// void init_1602();
//zhl_1602(0xc4);
//shj_1602(table[bb]);
//zhl_1602(0xc5);
//shj_1602(table[bs]);
//zhl_1602(0xc6);
//shj_1602(table[bg]);
//}
主程序部分
#include
#include "lcd_1602.h"
#include "ADC12.h"
//#define w P6IN=BIT4 //定义AD的输入口为P6
//table[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
void main(void) //主程序开始
{
//uint xh;
WDTCTL=WDTPW+WDTHOLD;
void Adc_Init();
void Delay_1ms();
P1DIR=0xff;
P4DIR=0xff;
P6SEL=0X0a;
while(1)
//if((P1IN &BIT3)==0)//输入。
{
display();
P6SEL=0X0F;
void diaoyong();
//在大循环内调用显示函数,一直显示
//break;
}
}
//计算BMI
LCD显示部分就不放上来了。怕大家看太多眼花。
0
已退回20积分