/*------------------------------------------------------------------*/
/* --- STC MCU Limited ---------------------------------------------*/
/* --- STC12C56xx Series MCU A/D Conversion Demo -------------------*/
/* --- 外部晶振:11.0592MHz
/* --- 9600 -----------------------------------------*/
/* If you want to use the program or the program referenced in the */
/* article, please specify in which data and procedures from STC */
/*------------------------------------------------------------------*/
#include "reg51.h"
#include "STC_Y3_UART.h"
typedef unsigned char uchar;
typedef unsigned int uint;
/*Declare SFR associated with the ADC */
sfr AUXR = 0x8e;
sfr ADC_CONTR = 0xC5; //ADC control register
sfr ADC_DATA = 0xC6; //ADC high 8-bit result register
sfr ADC_LOW2 = 0xBE; //ADC low 2-bit result register
sfr P1M0 = 0x91; //P1 mode control register0
sfr P1M1 = 0x92; //P1 mode control register1
/*Define ADC operation const for ADC_CONTR*/
#define ADC_POWER 0x80 //ADC power control bit
#define ADC_FLAG 0x10 //ADC complete flag
#define ADC_START 0x08 //ADC start control bit
#define ADC_SPEEDLL 0x00 //420 clocks
#define ADC_SPEEDL 0x20 //280 clocks
#define ADC_SPEEDH 0x40 //140 clocks
#define ADC_SPEEDHH 0x60 //70 clocks
sbit P32 = P3^2;
void InitUart();
void SendData(uchar dat);
void Delay(uint n);
void InitADC();
uchar ch = 0; //ADC channel NO.
bit ADC_over_flag;
uchar data0,data1,data2,data3;
uchar Vdat0,Vdat1,Vdat2,Vdat3;
uint Vout,AD10_store,ADTEMP,i;
unsigned long zdata;
void main(void)
{
InitUART();
InitADC(); //Init ADC sfr
AUXR |= 0x10; //set EADCI
IE = 0xa0; //Enable ADC interrupt and Open master interrupt switch
ADC_DATA = 0; //Start A/D conversion
AD10_store = 0;
while(1)
{
if(P32==0)
{
PrintString(" STC_Y3_UART SENGD TEST \r\n");
}
if(ADC_over_flag)
{
ADC_over_flag = 0;
PrintString("ADC");
//SendByte(HEX2ASCII(ch>>4));
SendByte(HEX2ASCII(ch)); //Show Channel NO.
AD10_store =(AD10_store|ADC_DATA)&0x00ff;
AD10_store = (AD10_store<<2)|(ADC_LOW2&0X03);
ADTEMP = AD10_store;
data3 = AD10_store/1000;
i = AD10_store%1000;
data2 = i/100;
i = i%100;
data1 = i/10;
data0 = i%10;
SendByte(' ');
SendByte(HEX2ASCII(data3)); //Get ADC high 8-bit result and Send to UART
SendByte(HEX2ASCII(data2)); //Get ADC high 8-bit result and Send to UART
SendByte(HEX2ASCII(data1));
SendByte(HEX2ASCII(data0));
SendByte(' ');
zdata = (unsigned long)ADTEMP*5000;
Vout = (uint)(zdata/1023);
Vdat3 = (uchar)(Vout/1000);
i = Vout%1000;
Vdat2 = (uchar)(i/100);
Vdat1 = (uchar)(i%100/10);
Vdat0 = (uchar)(i%100%10);
SendByte(HEX2ASCII(Vdat3));
SendByte('.');
SendByte(HEX2ASCII(Vdat2)); //Get ADC high 8-bit result and Send to UART
SendByte(HEX2ASCII(Vdat1));
SendByte(HEX2ASCII(Vdat0));
SendByte('V');
SendByte(' ');
//if you want show 10-bit result, uncomment next line
// SendData(ADC_LOW2); //Show ADC low 2-bit result
Delay(50);
AD10_store = 0;
if (++ch > 7)
{
ch = 0; //switch to next channel
SendByte(0x0d); //发回车
SendByte(0x0a); //发回车
}
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START | ch;
}
}
}
/*----------------------------
ADC interrupt service routine
----------------------------*/
void adc_isr() interrupt 5 using 1
{
ADC_CONTR &= !ADC_FLAG; //Clear ADC interrupt flag
// SendByte(ch); //Show Channel NO.
// SendByte(ADC_DATA); //Get ADC high 8-bit result and Send to UART
ADC_over_flag = 1;
//if you want show 10-bit result, uncomment next line
// SendData(ADC_LOW2); //Show ADC low 2-bit result
//if (++ch > 7) ch = 0; //switch to next channel
//ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START | ch;
}
/*----------------------------
Initial ADC sfr
----------------------------*/
void InitADC()
{
P1 = P1M0 = P1M1 = 0xff; //Set all P1 as Open-Drain mode
ADC_DATA = 0; //Clear previous result
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ADC_START | ch;
Delay(2); //ADC power-on delay and Start A/D conversion
}
/*----------------------------
Software delay function
----------------------------*/
void Delay(uint n)
{
uint x;
while (n--)
{
x = 5000;
while (x--);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
STC12C5616AD--10位AD转换串口显示
共23个文件
bak:4个
obj:3个
lst:3个
需积分: 21 20 下载量 71 浏览量
2018-01-15
14:14:15
上传
评论
收藏 41KB ZIP 举报
温馨提示
STC12C56AD--10位AD采集,通过串口返回采集数据,.......
资源推荐
资源详情
资源评论
收起资源包目录
STC12C5616AD--10位AD转换串口显示.zip (23个子文件)
39-STC12C5616AD--10位AD转换串口显示
STC12C5616AD_Uv2.Bak 0B
STC_Y3_UART.OBJ 3KB
STC12C5616AD.uvopt 6KB
STC_Y3_UART.c 2KB
STC12C5616AD_Opt.Bak 1004B
STARTUP.OBJ 749B
2052ADUartdisplay.LST 9KB
2052ADUartdisplay.c 5KB
2052ADUartdisplay.OBJ 9KB
STC12C5616AD.plg 15KB
STC12C5616AD.M51 12KB
STARTUP.A51 6KB
STC12C5616AD.Uv2.bak 2KB
STC12C5616AD.build_log.htm 313B
STC_Y3_UART.h 360B
STC12C5616AD.lnp 97B
STC12C5616AD.hex 3KB
STC12C5616AD.uvgui.ASUS 70KB
STC12C5616AD.uvproj 14KB
STC_Y3_UART.LST 4KB
STARTUP.LST 14KB
STC12C5616AD.opt.bak 1KB
STC12C5616AD 11KB
共 23 条
- 1
资源评论
阳光12
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功