对这个就是设置的参考电压为25v
如果改成
ADC12CTL0=ADC12ON+REFON+SHT0_6;//为15v参考电压
如果改成
ADC12CTL0=ADC12ON+SHT0_6;//SetupADC12,ref,samplingtime
ADC12CTL1=SHP;//Usesamplingtimer
ADC12MCTL0=INCH_10+SREF_0;//
则选择的为以电源电压为基准
有时内部的基准会不是很准在精确采集的时候一定要用万用表测一下参考电压的值用测的值计算25v只是理论上的值
首先你没有给电路连接图,仅凭汇编中的地址很难想象,下面只有使用伪代码表示,控制接口自行定义了。假设可以位寻址。
int seg_table[]={0x3F,0x06,};//数码管的表
GPIO(start) = 0;//启动,低电平有效
while(!EOC);//等待转换完成
LED = DATA;//读入数据,LED显示
int temp = DATA;
delay_ms();
int i =0;
while(temp)
{
duan = temp&0x0f;
temp >>= 4;
GPIO(duan) = 0;
GPIO(duan) = seg_table[duan];
GPIO(duan) = 0;
wei = i++;
GPIO(wei) = 0;
GPIO(wei) = wei;
delay_ms();
}
对于串行发送很简单,
for(i= 0;i<8;i++)
{
GPIO_BITx = DATA&0x01;
ATA >>= 1;
}
#include<STC12h>
#define uchar unsigned char
#define uint unsigned int
uchar code seg_data1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code seg_data2[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
sbit p20=P2^0;
sbit p21=P2^1;
sbit p22=P2^2;
//sfr ADC_CONTR=0xBC;
//sfr P1ASF=0x9D;
//sfr ADC_RES=0xBD;
void delay(uint a1);
void input();
void display(uint count);
void main()
{
uint x;
while(1)
{
input();
x=5(ADC_RES50)/255;
display(x);
}
}
void input()
{
P1ASF=0x01;
ADC_CONTR=0x88;
delay(25);
IE=0xA0;
}
void drop() interrupt 5
{
ADC_CONTR=0X88;
}
void display(uint count)
{
uchar i;
for (i=0;i<5;i++)
{
P0=seg_data1[count%10];
p20=0;
delay(25);
p20=1;
P0=seg_data2[count/10%10];
p21=0;
delay(25);
p21=1;
if(count>=100)
{
P0=seg_data1[count/100];
p22=0;
delay(25);
p22=1;
}
}
}
void delay(uint a1) //误差 0us
{
unsigned char a,b,c;
for(c=a1;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
这是我自己写的,用数码管显示,你只需要把void display(uint count)函数改为12864的显示函数即可
void write_CS5550(uchar data_to_send) //
{
uchar i; AD_SCLK=0;
// AD_CS =0;
Delay_us(20); // for (i=0;i<8;i++)
{
if( (data_to_send&0X80)==0 )
{
AD_SDI=0;
}
else{AD_SDI=1;}
AD_SCLK=1;
Delay_us(10); //
AD_SCLK=0;
data_to_send<<=1;
}
}
uchar read_CS5550(void) //
{
unsigned char n=0,i=0;
for(n=0;n<3;n++)
{
for(i=0;i<8;i++)
{
cs5550_receive_table[n]<<=1;
if(AD_SDO==0)
{
cs5550_receive_table[n]|=0x01;
}
else cs5550_receive_table[n]&=0xFE;
Delay_us(5);
ACC_0=AD_SDO; //
Delay_us(5);
AD_SCLK=1; //
a<<=1;
Delay_us(10);
AD_SCLK=0; //
Delay_us(30); //
}
a=0xfe;
// cs5550_receive_table[n]=ACC;
}
// AD_CS=1;
return ACC;
}
//1602 四线制驱动程序,根据需要自己改端口定义和延时
#define LINE1 0
#define LINE2 1
#define LINE1_HEAD 0x80
#define LINE2_HEAD 0xC0
#define CLEARSCREEN LCD_en_com(0x01);LCD_delay(30)
//
//change this part at different board
sbit DB7=P2^7;
sbit DB6=P2^6;
sbit DB5=P2^5;
sbit DB4=P2^4;
sbit LCD1602_RS=P2^1; //data command select 1 data 0 command pin 4
sbit LCD1602_RW=P2^2; //read write select 1 read 0 write pin 5
sbit LCD1602_EN=P2^3; //LCD enable signal pin 6
//
void LCD_delay(unsigned int n)
{
unsigned int i=0,j=0;
for (i=n;i>0;i--)
for (j=0;j<12;j++);
}
void LCD_en_com(unsigned char command)
{
DB7=(command>>7)%2;
DB6=(command>>6)%2;
DB5=(command>>5)%2;
DB4=(command>>4)%2;
LCD1602_RS = 0; //RS 0
LCD1602_RW = 0; //RW 0
LCD1602_EN = 1; //EN --\|/__ Write command
LCD_delay(2);
LCD1602_EN = 0;
DB7=(command>>3)%2;
DB6=(command>>2)%2;
DB5=(command>>1)%2;
DB4=(command>>0)%2;
LCD1602_RS = 0; //RS 0
LCD1602_RW = 0; //RW 0
LCD1602_EN = 1; //EN --\|/__ Write command
LCD_delay(2);
LCD1602_EN = 0;
}
void LCD_en_dat(unsigned char command)
{
DB7=(command>>7)%2;
DB6=(command>>6)%2;
DB5=(command>>5)%2;
DB4=(command>>4)%2;
LCD1602_RS = 1; //RS 1
LCD1602_RW = 0; //RW 0
LCD1602_EN = 1; //EN --\|/__ Write data
LCD_delay(2);
LCD1602_EN = 0;
DB7=(command>>3)%2;
DB6=(command>>2)%2;
DB5=(command>>1)%2;
DB4=(command>>0)%2;
LCD1602_RS = 1; //RS 1
LCD1602_RW = 0; //RW 0
LCD1602_EN = 1; //EN --\|/__ Write data
LCD_delay(2);
LCD1602_EN = 0;
}
void LCD_set_xy(unsigned char x,unsigned char y)
{
unsigned char address;
if(y == LINE1)
address = LINE1_HEAD + x;
else
address = LINE2_HEAD + x;
LCD_delay(10);
LCD_en_com(address);
}
void LCD_write_string(unsigned char x,unsigned char y,unsigned char s)
{
LCD_set_xy(x,y);
while(s)
{
LCD_en_dat(s);
s++;
}
}
//
void InitTimer0(void)//200us
{
TMOD = 0x01;
TH0 = 0x0FE;
TL0 = 0x70;
EA = 1;
ET0 = 1;
TR0 = 1;
}
unsigned char LCD_ContCount=0;
sbit LCDCONT=P2^0;
void Timer0Interrupt(void) interrupt 1
{
TH0 = 0x0FE;
TL0 = 0x70;
if(LCD_ContCount<LCD_CONTRAST){LCDCONT=0;}
else{LCDCONT=1;}
LCD_ContCount++;
if(LCD_ContCount==100){LCD_ContCount=0;}
}
//
void LCD_init(void)
{
LCD_delay(50);
LCD_en_com(0x33);//原来1602初始化成4位数据线之前必需先初始化成8位(此时命令发送方式是8位格式,但数据线只需接4位)
LCD_delay(10);
LCD_en_com(0x32);//然后再改到4位线宽,这样初始化才稳定
LCD_delay(10);
LCD_en_com(0x28);//四线模式设置
LCD_delay(10);
LCD_en_com(0x0c);//显示开--对应开关显示控制指令
LCD_delay(10);
CLEARSCREEN;
InitTimer0();
}
//
至于AD,用片上自带的AD就行,没有具体的电路,只能帮你这些了。
另:楼上说用ADC0834的,STC12C5A60S2已经有AD了啊
以上就是关于msp430一段有关AD数模转换参考电压设置的c程序高手请进全部的内容,包括:msp430一段有关AD数模转换参考电压设置的c程序高手请进、求大神把下面ADC0808A/D模数转换汇编改成C语言、STC12C5A60S2 AD转换C语言程序,转换结果在12864液晶上显示.等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)