#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar table[6]="00.00V";
uchar num,temp;
uint voltage;
sbit ad_clk=P3^3;
sbit ad_out=P3^4;
sbit ad_cs=P3^5;
sbit lcden=P2^4;
sbit lcdrs=P2^5;
void delayms(uint xms);
void write_com(uchar com);
void write_data(uchar date);
void led_init();
void tlc549_ad();
void main()
{
led_init();
tlc549_ad();
}
void led_init()
{
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void tlc549_ad()
{
ad_cs=1;
ad_clk=0;
ad_cs=0;
_nop_();
_nop_();
for(num=0;num<8;num++) / /串行数据移位输出
{
temp<<=1;
temp|=ad_out;
ad_clk=1;
_nop_();
ad_clk=0;
}
ad_cs=1;
for(num=17;num>0;num--)
_nop_();
voltage=(uint)(5.0/256*temp*400);
temp=0;
table[0]=voltage/1000+48;
table[1]=voltage%1000/100+48;
table[3]=voltage%1000%100/10+48;
table[4]=voltage%1000%100%10+48;
write_com(0x80);
for(num=0;num<6;num++)
{
write_data(table[num]);
delayms(5);
}
delayms(2000);
}
链接:https://pan.baidu.com/s/1dfWm6QwtIB_WhDHYUCcMCg 提取码:tbnt
|