|
求各路大神,帮看下程序。运行后读出的数据都不正确。用51读取LTC1867采集的电压。
#include<reg52.h>
sbit cs=P2^0;
sbit sck=P2^1;
sbit SDI=P2^2;
sbit SD0=P2^3;
//unsigned int high_byte;
unsigned int vale;
unsigned int read_high_byte();
unsigned char read_low_byte();
void delay(unsigned int x);
void UART_Init();
void UART_Send_Byte(unsigned char mydata);
void main()
{
UART_Init();
cs=0;
cs=1;
delay(1);
cs=0;
//high_byte=(read_high_byte())<<8;
//vale=high_byte+read_low_byte();
UART_Send_Byte(read_high_byte());
UART_Send_Byte(read_low_byte());
while(1);
}
void delay(unsigned int x)
{
unsigned char i;
while(x--){
for(i=0;i<100;i++);
}
}
unsigned int read_high_byte()
{
unsigned char i;
unsigned char date,high_byte;
date=0x88;
sck=0;
for(i=0;i<8;i++)
{
SDI=((date<<i)&0x80);
sck=1;
if(SD0) high_byte|=(0x80>>i);
delay(2);
sck=0;
delay(2);
}
return high_byte;
}
unsigned char read_low_byte()
{
unsigned int i,low_byte=0;
sck=0;
for(i=0;i<8;i++)
{
sck=1;
delay(10);
if(SD0) low_byte|=(0x80>>i);
sck=0;
delay(10);
}
// high_byte=high_byte<<8;
// high_byte+=low_byte;
return low_byte;
}
void UART_Init()
{
TMOD=0x20; //定时器T1使用工作方式2
TH1=0xfd; //设置初值
TH0=0xfd;
TR1=1; //开始计时
SM0=0;
SM1=1; //设置串口为方式1
REN=1; //接受使能
EA=1; //打开总中断开关
ES=1; //打开串口中断开关
}
void UART_Send_Byte(unsigned char mydata)
{
ES=0;
TI=0;
SBUF=mydata;
while(!TI);
TI=0;
ES=1;
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。
|