/*
* 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;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
51例程.zip (20个子文件)
51例程
AD7076.c 2KB
AD7076.LST 6KB
AD7076progrm_uvproj.bak 14KB
AD7076.h 1KB
AD7076progrm_uvopt.bak 57KB
main.OBJ 8KB
other.c 764B
AD7076progrm.plg 0B
AD7076.OBJ 6KB
AD7076progrm 14KB
other.h 203B
AD7076progrm.hex 2KB
AD7076progrm.uvproj 14KB
other.LST 3KB
AD7076progrm.lnp 77B
other.OBJ 2KB
AD7076progrm.uvopt 57KB
main.LST 7KB
main.c 3KB
AD7076progrm.M51 14KB
共 20 条
- 1
资源评论
- oblivioner2023-12-01很完整的项目,基本的注释也有,很有帮助!淘宝店没提供,还好这里有,谢谢。
kinsun868
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功