打印
[MCU]

链接问题(AD7606的RD和CS)

[复制链接]
382|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xxmmi|  楼主 | 2020-7-5 18:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
xxmmi|  楼主 | 2020-7-5 18:14 | 只看该作者

sbit OS0 = P1^0;
sbit OS1 = P1^1;
sbit OS2 = P1^2;

sbit rage = P1^3;
sbit convst = P1^4;
sbit busy = P1^5;
sbit rst = P1^6;
sbit rd_and_cs = P1^7;
全部程序在下面:
* This is a program for testing AD7606        used STC89C52RC
* The line connecting AD7606 with STC89C52RC is:
* STC89C52RC    |    AD7606
*          P0                         |          DB[0:7]
*   P2          |    DB[8:15]
*   OS0         |    P1^0
*   OS1         |    P1^1
*   OS2         |    P1^2
*   rage        |    P1^3
*   convst      |    P1^4
*   busy        |    P1^5
*   rst         |    P1^6
*   rd_and_cs   |    P1^7
*   green_led   |    P3^6
*   red_led     |    P3^7
*         GND                 |    GND
*   +5V                 |    VCC
*   green_led   |    P3_6
*   red_led     |    P3_7
* Author : jinming chen
* Compang : Hongwei in dongguan
* Date : Sep 1        ,2015
*/

#include <reg52.h>
#include <intrins.h>
#include <stdio.h>
#include "AD7076.h"
#include "other.h"

//uchar introduce1[] = "This is a program ";
//uchar introduce2[] = "for testing AD7606\r\n";
uchar sampling[] = "The sampling data is : ";
uchar newline[] = "\r\n";
uchar space[] = " ";
uchar *DB_str[16] = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};

/*
uchar *data_to_string(uchar Data)
{
        uchar tmp;
        tmp = Data & 0x0f;
        str[1] =DB_str[binary_to_decimal(tmp)];
        tmp = Data>>4;
        str[0] =DB_str[binary_to_decimal(tmp)];
        return str;
}
*/


void serial_init(void)
{
        SCON = 0x50;  //UART为模式一,8位数据,允许接收
        TMOD |= 0x20;        //定时器1为模式二,8位自动重装
        PCON |= 0x80;        //SMOD=1
        TH1 =0xfd;                //波特率为19200,晶振频率为11.0592MHz
        IE = 0x00;
        TR1 = 1;
        TI = 1;
}
/*
//向串口发送一个函数
void serial_send_byte(uchar ch)
{
        SBUF=ch;
    while (TI== 0);
    TI = 0 ;
}
*/

//向串口发送一串字符数据
void serial_send_string(uchar *p)
{
        while(*p != '\0')
        {
                SBUF = *p;
                while(TI == 0);
                TI = 0;
                p++;
        }         
}

int main()
{
        struct DB_data_struct *DB_data;
        uchar k,tmp;
        uchar DB_data_cmp[8];
        serial_init();
        AD7606_init();
        while(1)
        {
//                DB_data = DB_str;
//                serial_send_string(introduce1);
//                serial_send_string(introduce2);
                AD7606_startconvst();
                while((busy == 1))                //当busy为低电平时,数据转换完毕,此时可以读取数据
                {
//                        serial_send_byte(busy);
//                        delay_ms(500);
                        ;
                }
                DB_data = AD7606_read_data();
                serial_send_string(sampling);
                for(k=0;k<8;k++)
                {
                        tmp = (DB_data->DB_data_H>>4) & 0x0f;
                        serial_send_string(DB_str[tmp]);
                        tmp = (DB_data->DB_data_H) & 0x0f;
                        serial_send_string(DB_str[tmp]);
                        tmp = (DB_data->DB_data_L>>4) & 0x0f;
                        serial_send_string(DB_str[tmp]);
                        tmp = (DB_data->DB_data_L) & 0x0f;
                        serial_send_string(DB_str[tmp]);
                        serial_send_string(space);
                        DB_data_cmp[k] = DB_data->DB_data_H;
                        DB_data += 1;
                }
                if((DB_data_cmp[0]>0x7D)&&(DB_data_cmp[1]>0x7D)&&(DB_data_cmp[2]>0x7D)&&(DB_data_cmp[3]>0x7D)        \
                &&(DB_data_cmp[4]>0x7D)&&(DB_data_cmp[5]>0x7D)&&(DB_data_cmp[6]>0x7D)&&(DB_data_cmp[7]>0x7D))
                {        //电压检测为预定值,则绿灯亮
                        red_led = 0;
                        green_led = 1;
                }
                else
                {        //电压检测为非预定值,则红灯亮
                        green_led = 0;
                        red_led = 1;
                }
                serial_send_string(newline);
                serial_send_string(newline);
                serial_send_string(newline);
                delay_ms(300);
        }
        return 0;        
}

使用特权

评论回复
板凳
pangb| | 2020-7-5 18:18 | 只看该作者
看时序就知道了啊

使用特权

评论回复
地板
guoyt| | 2020-7-5 18:22 | 只看该作者
一定漏掉了什么,我怎么没有看到AD7606_read_data();这个函数。

使用特权

评论回复
5
juventus9554| | 2020-7-24 18:20 | 只看该作者
let me see the comment

使用特权

评论回复
6
llljh| | 2020-7-24 18:28 | 只看该作者
你说的  RD是AD那边的芯片吗   

使用特权

评论回复
7
xxrs| | 2020-7-24 18:34 | 只看该作者
spi配置还是比较简单 的       配置好寄存器  然后直接读取就可以了  

使用特权

评论回复
8
xxmmi|  楼主 | 2020-7-24 18:38 | 只看该作者

其实还是不大明白,我再琢磨琢磨吧,多谢了哈先

使用特权

评论回复
9
zhangmangui| | 2020-7-24 23:25 | 只看该作者
TI的AD/DA与TI的控制器可以无缝连接

使用特权

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

本版积分规则

369

主题

4278

帖子

2

粉丝