#include <reg52.h>
#include <absacc.h>
#include <intrins.h>
#include"uart.h"
#define uint unsigned int
#define uchar unsigned char
sbit cs = P1^0;
sbit a0 = P1^1;
sbit rc = P1^2;
sbit sts = P1^3; //sts
sbit rd = P1^6;
sbit wr = P1^7;
uint temp;
uint ad574()
{
uint temp_h;
uint temp_l;
rc = 0;
cs = 0;
rd = 0;
wr = 0; //ce = 1;
a0 = 0; //启动转换
sts = 1;
while(sts==1);
cs = 0; //读高8位
rc = 1;
a0 = 0;
temp_h = P2;
_nop_();
_nop_();
_nop_();
rc = 1; //读低4位+低位补零
a0 = 1;
temp_l = P2;
temp_h=(uint)(temp_h<<8);
temp=(uint)(temp_h+(temp_l&0xf0));
return(temp);
}
test574()
{
uint a;
uart_Init();
putstr("start\n");
while(1)
{
a=ad574();
putstr("the ad574 out is:");
putint(a);
putstr("\n");
_getkey();
}
}
void main()
{
test574();
}
通过串口接收显示在电脑上,但是改变模拟量,数据没有变化。之前的程序用的是书上的写法,用xbyte,没成功,就自己按照时序写,也没成功,请大侠们有时间能点拨一下。 |