老铁们,你们有没有见过这种接线方式的?最近在用AD7606做东西,发现别人分享的程序有一个这样的,rd_and_cs = P1^7;RD和CS接在一起?无法理解啊!老铁们帮我看看吧
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;
} |