打印

搞了一个星期的AD574,一直没有搞好,请大侠指点

[复制链接]
1495|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
沙发
醉笙梦嗣|  楼主 | 2011-7-30 09:36 | 只看该作者
#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,没成功,就自己按照时序写,也没成功,请大侠们有时间能点拨一下。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

12

帖子

1

粉丝