兄弟:不知道你玩不玩32 ,有个32 的在工程上用过,直接刷程序,串口连接电脑就可以输出AD 转换的结果。如果不玩32 的话。
首先第一步排查: 排查单片机能不能正确显示 你测试到的 AD 信号,显示正确不?
比如给他 3V 电压 ,用数码管显示出来。
第二: 串口发送,找个能正确发送数据的代码 ,直接把 ,你检查的数值给这个变量,让串口发送,
一步一步找问题,你绝对能解决的。我把AD0809 的代码给你用数码管测试
#include <reg52h>
#define uint unsigned int
#define uchar unsigned char
uchar code LEDData[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
sbit OE = P1^0;
sbit EOC = P1^1;
sbit ST = P1^2;
sbit CLK = P1^3;
void DelayMS(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
void Display_Result(uchar d)
{
P2 = 0xf7;
P0 = LEDData[d%10];
DelayMS(5);
P2 = 0xfb;
P0 = LEDData[d%100/10];
DelayMS(5);
P2 = 0xfd;
P0 = LEDData[d/100];
DelayMS(5);
}
void main()
{
TMOD = 0x02;
TH0 = 0x14;
TL0 = 0x00;
IE = 0x82;
TR0 = 1;
P1 = 0x3f;
while(1)
{
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
Display_Result(P3);
OE = 0;
}
}
void Timer0_INT() interrupt 1
{
CLK = !CLK;
}
这个是F247的程序。
#include "msp430x24xh"
#define Latch_addr_H P5OUT|=0x10
#define Latch_addr_L P5OUT&=0xef
#define Latch_data_H P5OUT|=0x20
#define Latch_data_L P5OUT&=0xdf
#define uchar unsigned char
void delay(unsigned int i);
void LED_Disp(uchar pos,uchar value);
void init();
void transport();
void ADC12setup(void);
const uchar tab[11]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09,0xfe};
uchar shuma[4]={6,7,8,9};
unsigned int shuju;
//主函数
main( void )
{
uchar m;
P5DIR |= 0x30; //定义为输出端口
P4DIR |= 0xff;
P2DIR |=0xff;
P2OUT=0xff;
init();
transport();
delay(2000);
ADC12CTL0 |= ADC12SC; //sampling open,AD转换完成后(ADC12BUSY=0),ADC12SC自动复位;
while((ADC12IFG & BIT0) == 0); //等转换结束
shuju = ADC12MEM0; //读转换数据值,同时清ADC12IFG0标志
while(1)
{
//ADC12CTL0 |= ADC12SC; //sampling open,AD转换完成后(ADC12BUSY=0),ADC12SC自动复位;
//while((ADC12IFG & BIT0) == 0); //等转换结束
//shuju = ADC12MEM0;
transport();
LED_Disp(m,shuma[m]);
delay(5);
m++;
if(m>3)
m=0;
if(m==3)
{
LED_Disp(m,10);
delay(5);
}
}
}
//初始化+采集
void init()
{
WDTCTL = WDTPW + WDTHOLD; // 停止WDT
P1DIR=0x01;P1OUT=0x0f; //LED设置
ADC12setup();
_EINT(); // 全局中断使能
}
//ADC12初始化
void ADC12setup(void)
{
//ADC12设置
P6SEL |= 0x01; //使用A/D通道 A0
ADC12CTL0 = ADC12ON ; //开ADC12内核,设SHT0=2 (N=4)
ADC12CTL1 = SHP ; //SAMPCON信号选为采样定时器输出
//ADC12内部参考电压设置
ADC12CTL0 |= REF2_5V; //选用内部参考电压为25V
ADC12CTL0 |= REFON; //内部参考电压打开
ADC12MCTL0 |= SREF_0; //R+=33V R-=VSS
//转换允许
ADC12CTL0 |= ENC ; //转换允许(上升沿)
shuju=0x00;
}
//转换
void transport()
{
unsigned int q;
q=(shuju5)/4;
shuma[0]=q%10;
shuma[1]=(q%100)/10;
shuma[2]=(q%1000)/100;
shuma[3]=q/1000;
}
//显示函数
void LED_Disp(uchar pos,uchar value)
{
P5OUT=0x00;
P4OUT=0x10<<(pos);
Latch_addr_H;
Latch_addr_L;
if( value<=10)
{
P4OUT=tab[value];
Latch_data_H;
Latch_data_L;
}
}
//延时
void delay(unsigned int i)
{ int m,n;
for(m=0;m<i;m++)
for(n=0;n<120;n++);
}
/adc中断服务程序
#pragma vector=ADC_VECTOR//ADC 中断服务程序
__interrupt void ADC12ISR (void)
{
static unsigned int index = 0; // 中断服务程序中的静态变量
A0results[index] = ADC12MEM0; //移动A0 结果往数组,此 *** 作的同时清除ADC12FIG0
A1results[index] = ADC12MEM1; //移动A1 结果往数组,此 *** 作的同时清除ADC12FIG1
A2results[index] = ADC12MEM2; //移动A2 结果往数组,此 *** 作的同时清除ADC12FIG2
A3results[index] = ADC12MEM3; //移动A3 结果往数组,此 *** 作的同时清除ADC12FIG3
index = (index+1)%Num_of_Results; // 增加结果的索引,取index 变量的模(余数)
}
/
我只能给你提供个思路,10脚似乎有电压检测功能,用12C5410AD的有
开启电压变化检测-->当电压变化,开启A/D采样-->根据采样值的范围查表跳转到相应的功能
#include "reg51h"
#define data_point P0
sbit EOC=P2^0;
sbit ADDA=P2^1;
sbit ADDB=P2^2;
sbit ADDC=P2^3;
sbit OE=P2^5;
sbit START=P2^6;
sbit CLK=P2^7;
sbit ALE=P2^6;
unsigned char disp[3]={0,0,0};
char code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char t0count=0;
unsigned int temp;
double sum;
unsigned char val_Integer; //整数
unsigned int val_Decimal; //小数
sbit k1 = P1^0;
sbit k2 = P1^1;
sbit k3 = P1^2;
sbit k4 = P1^3;
void delay(unsigned char ms)
{
unsigned char i;
while(ms--)
for(i=0;i<125;i++);
}
void display()
{
disp[0]=disp[0]&0x7f;
P3= disp[0];
k1 = 1;
delay(2);
k1 = 0;
P3= disp[1];
k2 = 1;
delay(2);
k2 = 0;
P3= disp[2];
k3 = 1;
delay(2);
k3 = 0;
P3= disp[3];
k4 = 1;
delay(2);
k4 = 0;
}
unsigned char ADC0808()
{
unsigned char d;
ADDC=0;
ADDB=0;
ADDA=0;
TR1=1;
ALE=1;ALE=0;
START=1;START=0;
while(EOC==0);
OE=1;
d=data_point;
OE=0;
TR1=1;
return d;
}
void covert(unsigned char x)
{
sum=x00201378;
val_Integer=(unsigned char)sum;
val_Decimal=(unsigned int)((sum-val_Integer)1000);
disp[3]=dispcode[val_Decimal%10];
disp[2]=dispcode[val_Decimal/10%10];
disp[1]=dispcode[val_Decimal/100];
disp[0]=dispcode[val_Integer];
}
void main()
{
TMOD=0x21;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TH1=256-2;
ET0=1;
ET1=1;
EA=1;
TR0=1;
OE=0;
START=0;
EOC=1;
while(1)
{
display();
}
}
void time0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
t0count++;
if(t0count==100)
{
t0count=0;
covert(ADC0808());
}
}
void time1() interrupt 3
{
CLK=~CLK;
}
以上就是关于关于单片机向串口发送AD转换结果的程序全部的内容,包括:关于单片机向串口发送AD转换结果的程序、十万火急【msp430单片机的AD转换程序】!!!!!、单片机AD检测按键电压程序怎么写等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)