标题:
多路ADC转换-模拟串口发送 STC15系列库函数与例程
[打印本页]
作者:
王中心
时间:
2017-3-4 19:59
标题:
多路ADC转换-模拟串口发送 STC15系列库函数与例程
STC15系列库函数与例程 03-多路ADC转换-模拟串口发送
0.png
(67.19 KB, 下载次数: 61)
下载附件
2017-3-5 02:04 上传
完整的源码下载:
01-IO-跑马灯.rar
(26.46 KB, 下载次数: 27)
2017-3-4 19:58 上传
点击文件名下载附件
下载积分: 黑币 -5
03-多路ADC转换-模拟串口发送.rar
(30.86 KB, 下载次数: 84)
2017-3-4 19:58 上传
点击文件名下载附件
下载积分: 黑币 -5
主程序预览:
/*------------------------------------------------------------------*/
/* --- STC MCU International Limited -------------------------------*/
/* --- STC 1T Series MCU RC Demo -----------------------------------*/
/* --- Mobile: (86)13922805190 -------------------------------------*/
/* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/
/* --- Tel: 86-0513-55012928,55012929,55012966 ---------------------*/
/* If you want to use the program or the program referenced in the */
/* article, please specify in which data and procedures from STC */
/*------------------------------------------------------------------*/
#include "config.h"
#include "GPIO.h"
#include "delay.h"
/************* 功能说明 **************
本程序演示跑马灯。
程序使用P2口来演示,输出低驱动。用户可以修改为别的口。
******************************************/
/************* 本地常量声明 **************/
/************* 本地变量声明 **************/
/************* 本地函数声明 **************/
/************* 外部函数和变量声明 *****************/
/******************** IO配置函数 **************************/
void GPIO_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //结构定义
GPIO_InitStructure.Pin = GPIO_Pin_All; //指定要初始化的IO, GPIO_Pin_0 ~ GPIO_Pin_7, 或操作
GPIO_InitStructure.Mode = GPIO_OUT_PP; //指定IO的输入或输出方式,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
GPIO_Inilize(GPIO_P2,&GPIO_InitStructure); //初始化
}
/******************** 主函数 **************************/
void main(void)
{
u8 i,tmp;
GPIO_config();
while(1)
{
tmp = 1;
for(i=0; i<8; i++)
{
P2 = ~tmp;
tmp <<= 1;
delay_ms(250);
}
tmp = 0x80;
for(i=0; i<8; i++)
{
P2 = ~tmp;
tmp >>= 1;
delay_ms(250);
}
}
}
复制代码
/*------------------------------------------------------------------*/
/* --- STC MCU International Limited -------------------------------*/
/* --- STC 1T Series MCU RC Demo -----------------------------------*/
/* --- Mobile: (86)13922805190 -------------------------------------*/
/* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/
/* --- Tel: 86-0513-55012928,55012929,55012966 ---------------------*/
/* If you want to use the program or the program referenced in the */
/* article, please specify in which data and procedures from STC */
/*------------------------------------------------------------------*/
#include "config.h"
#include "adc.h"
#include "delay.h"
#include "soft_uart.h"
/************* 功能说明 **************
本程序演示多路ADC查询采样,通过模拟串口发送给上位机,波特率9600,8,n,1。
用户可以修改为1~8路的ADC转换。
******************************************/
/************* 本地常量声明 **************/
/************* 本地变量声明 **************/
/************* 本地函数声明 **************/
/************* 外部函数和变量声明 *****************/
void ADC_config(void)
{
ADC_InitTypeDef ADC_InitStructure; //结构定义
ADC_InitStructure.ADC_Px = ADC_P10 | ADC_P11 | ADC_P12; //设置要做ADC的IO, ADC_P10 ~ ADC_P17(或操作),ADC_P1_All
ADC_InitStructure.ADC_Speed = ADC_360T; //ADC速度 ADC_90T,ADC_180T,ADC_360T,ADC_540T
ADC_InitStructure.ADC_Power = ENABLE; //ADC功率允许/关闭 ENABLE,DISABLE
ADC_InitStructure.ADC_AdjResult = ADC_RES_H8L2; //ADC结果调整, ADC_RES_H2L8,ADC_RES_H8L2
ADC_InitStructure.ADC_Polity = PolityLow; //优先级设置 PolityHigh,PolityLow
ADC_InitStructure.ADC_Interrupt = DISABLE; //中断允许 ENABLE,DISABLE
ADC_Inilize(&ADC_InitStructure); //初始化
ADC_PowerControl(ENABLE); //单独的ADC电源操作函数, ENABLE或DISABLE
}
/**********************************************/
void main(void)
{
u8 i;
u16 j;
ADC_config();
while (1)
{
for(i=0; i<3; i++)
{
delay_ms(250);
// Get_ADC10bitResult(i); //参数0~7,查询方式做一次ADC, 丢弃一次
j = Get_ADC10bitResult(i); //参数0~7,查询方式做一次ADC, 返回值就是结果, == 1024 为错误
TxSend('A');
TxSend('D');
TxSend(i+'0');
TxSend('=');
TxSend(j/1000 + '0');
TxSend(j%1000/100 + '0');
TxSend(j%100/10 + '0');
TxSend(j%10 + '0');
TxSend(' ');
TxSend(' ');
}
PrintString("\r\n");
}
}
复制代码
作者:
a1075511750
时间:
2018-7-16 22:33
谢谢,我收下了
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1