#include <reg52.h>
#include <intrins.h> //_nop_()
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
//数码管查找显示
uchar code px[4]={0x08,0x04,0x02,0x01};
uchar code sk[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
//引脚定义
sbit CLK=P3^4;
sbit DATA=P3^2;
sbit CS=P3^3;
static uint j[4]=0; //存十进制数据
void display(uint *q) //数码显示
{ uint r;
for(r=0;r<4;r++)
{
P0=px[r];
P2=sk[*(q+r)];
}
}
uchar tlc549_ad_read(void) //ad读取
{ uchar i,da1=0x00;
CLK=0;
CS=0;
DATA=1; //置位准备读
i=8; //读8位
while(i!=0)
{ i--;
da1=da1<<1;
_nop_();
CLK=1;
da1|=DATA;
_nop_();
CLK=0;
}
P1=da1; //读到的数据送显示
CLK=1;
CS=1;
return(da1);
}
void timer1() interrupt 3 using 0 //定时采集
{ uchar k,adc_data;
adc_data=tlc549_ad_read();
display(j);
for(k=0;k<4;k++) //转十进制存j【】中
{
j[k]=adc_data%10;
adc_data/=10;
}
}
void main()
{
TMOD|=0X10;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
ET1=1;
TR1=1;
EA=1;
CS=1;
CLK=1;
while(1)
{
display(j); //显示
}
}
|