本帖最后由 zh1981829 于 2012-9-22 15:55 编辑
程序
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit CLK=P2^5;//74hc164
sbit SDA=P2^4;
sbit CS=P3^6;//1549
sbit CKA=P3^4;
sbit SDO=P3^5;
sbit ARM=P1^1;//蜂鸣器报警输输出
sbit DD=P1^4;//段电信号输出
sbit LED=P2^0;//LED数码管报警输出
uint adval;
uchar code tab[]={0x7d,0x50,0x6b,0x7a,0x56,0x3e,0x3f,0x70,0x7f,0x7e,0x02};//共阴极数码管0-9 h
void delay(uint z)
{ uint x;
uchar y;
for(x=z;x>0;x--)
for(y=110;y>0;y--)
;
}
void delay1()
{; ;}
/*1549数据采集程序*/
uint AD_1549()
{
uchar i;
adval=0;
CS=0;
for(i=0;i<10;i++)
{
CKA=0;
adval<<=1;
if(SDO)
adval++;
CKA=1;
}
CS=1;
return adval;
}
void display(uint adval )
{
uchar bai,shi,ge,num,c;
bai=adval/250;
shi=adval%250/25;
ge=adval%25/2.5;
num=tab[ge];
for(c=0;c<8;c++)
{
CLK=0;
SDA=num&0x80;
CLK=1;
num<<=1;
}
num=tab[shi];
for(c=0;c<8;c++)
{
CLK=0;
SDA=num&0x80;
CLK=1;
num<<=1;
}
num=tab[bai];
for(c=0;c<8;c++)
{
CLK=0;
SDA=num&0x80;
CLK=1;
num<<=1;
}
}
void main()
{
while(1)
{
AD_1549();
display(adval);
delay(3000);
ARM=0;
DD=0;
LED=0;
}
这个程序采用 ISIS professional 仿真时,能够采集到数据,但是将程序实际写入单片机,插到板子上面时,一直采集不到数据,王各位朋友给出指导
} |