我stc89c52rc单片机板子上的ad芯片是tlc549,怎样用它写模数转换程序?尽量简洁明了~
展开全部
//////////***你自己看看吧******引脚改改就能用*********/////
#include <AT89X51.H>
#define uint unsigned int
#define uchar unsigned char
uint Volt;
sbit CS=P3^4;//////////////TLC549引脚
sbit CLK=P3^2;
sbit DO=P3^3;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳
uchar code table1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
void delay(uint time)
{
int x,y;
for(x=time;x>0;x--)
for(y=time;y>0;y--);
}
void shortdelay(uint time)
{
uint i;
for(i<0;i<time;i++);
}
uchar TLC549_ADC(void)
{
uchar i, tmp;
CS=1;
CLK=0;
CS=0;
shortdelay(2);
for(i=0;i<8;i++)
{
tmp<<=1;
//tmp|=DO;
tmp=tmp|DO;
CLK=1;
shortdelay(2);
CLK=0;
}
CS=1;
shortdelay(17);
return (tmp);
}
void Data_Conversion(void)
{
uchar AD_Data;
AD_Data=TLC549_ADC();
Volt=5.0/255*AD_Data*100 ;
}
void display()
{
uint m;
for(m=0;m<80;m++)
{
P2=0xc1;
P1=0x08;
delay(5);
P1=0x00;
P2=table[Volt%10];
P1=0x04;
delay(5);
P1=0x00;
P2=table[Volt/10%10];
P1=0x02;
delay(5);
P1=0x00;
P2=table1[Volt/100];
P1=0x01;
delay(5);
P1=0x00;
}
}
void main()
{
while(1)
{
display();
delay(20);
Data_Conversion();
}
}
#include <AT89X51.H>
#define uint unsigned int
#define uchar unsigned char
uint Volt;
sbit CS=P3^4;//////////////TLC549引脚
sbit CLK=P3^2;
sbit DO=P3^3;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳
uchar code table1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
void delay(uint time)
{
int x,y;
for(x=time;x>0;x--)
for(y=time;y>0;y--);
}
void shortdelay(uint time)
{
uint i;
for(i<0;i<time;i++);
}
uchar TLC549_ADC(void)
{
uchar i, tmp;
CS=1;
CLK=0;
CS=0;
shortdelay(2);
for(i=0;i<8;i++)
{
tmp<<=1;
//tmp|=DO;
tmp=tmp|DO;
CLK=1;
shortdelay(2);
CLK=0;
}
CS=1;
shortdelay(17);
return (tmp);
}
void Data_Conversion(void)
{
uchar AD_Data;
AD_Data=TLC549_ADC();
Volt=5.0/255*AD_Data*100 ;
}
void display()
{
uint m;
for(m=0;m<80;m++)
{
P2=0xc1;
P1=0x08;
delay(5);
P1=0x00;
P2=table[Volt%10];
P1=0x04;
delay(5);
P1=0x00;
P2=table[Volt/10%10];
P1=0x02;
delay(5);
P1=0x00;
P2=table1[Volt/100];
P1=0x01;
delay(5);
P1=0x00;
}
}
void main()
{
while(1)
{
display();
delay(20);
Data_Conversion();
}
}
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
透过STM32您的嵌入式应用将得益于意法半导体优秀的产品架构、技术、多源产地和全方位支持。意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的8位单片机和基于ARM Cortex-M0、M0+、M3、M4、M33、M7及A7内核并具备...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询