在线时间606 小时
UID3069928
注册时间2015-11-5
NXP金币2989
TA的每日心情 | 奋斗 半小时前 |
---|
签到天数: 2450 天 连续签到: 6 天 [LV.Master]伴坛终老
金牌会员
 
- 积分
- 11263
- 最后登录
- 2025-7-18
|
本帖最后由 超級稻草人 于 2016-4-19 21:29 编辑
【KL27 mini Board 开发】+ ADC测试
开发工具
- KL27mini
- Keil 5.15
- ST_Link
实现功能:
KL27 mini 开发板上ADC测试,调整RV1的阻值来点亮相应的LED,并通过UART传输ADC的数值信息。
ADC测试程式
测试结果:
LED1点亮
LED2点亮
LED3点亮
LED4点亮
补发代码:
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "lpuart.h"
#include "gpio.h"
#include "adc.h"
#define LED0_PORT HW_GPIOC
#define LED0_PIN 3
#define LED1_PORT HW_GPIOA
#define LED1_PIN 1
#define LED2_PORT HW_GPIOE
#define LED2_PIN 0
#define LED3_PORT HW_GPIOA
#define LED3_PIN 2
int main(void)
{
int value;
DelayInit();
/* LED */
GPIO_QuickInit(LED0_PORT, LED0_PIN, kGPIO_Mode_OPP);
GPIO_QuickInit(LED1_PORT, LED1_PIN, kGPIO_Mode_OPP);
GPIO_QuickInit(LED2_PORT, LED2_PIN, kGPIO_Mode_OPP);
GPIO_QuickInit(LED3_PORT, LED3_PIN, kGPIO_Mode_OPP);
GPIO_WriteBit(LED0_PORT, LED0_PIN, 1);
GPIO_WriteBit(LED2_PORT, LED2_PIN, 1);
GPIO_WriteBit(LED1_PORT, LED1_PIN, 1);
GPIO_WriteBit(LED3_PORT, LED3_PIN, 1);
/* UART */
LPUART_QuickInit(LPUART0_RX_D06_TX_D07, 115200);
ADC_QuickInit(ADC0_SE23A_PE30, kADC_SingleDiff12or13);
while(1)
{
value = ADC_QuickReadValue(ADC0_SE23A_PE30);
printf("ADC:%d\r\n", value);
DelayMs(100);
if(value<=1000)
{
GPIO_WriteBit(LED0_PORT, LED0_PIN, 1);
GPIO_WriteBit(LED2_PORT, LED2_PIN, 1);
GPIO_WriteBit(LED1_PORT, LED1_PIN, 1);
GPIO_WriteBit(LED3_PORT, LED3_PIN, 0);
}
else if(value<=2000){
GPIO_WriteBit(LED0_PORT, LED0_PIN, 1);
GPIO_WriteBit(LED2_PORT, LED2_PIN, 0);
GPIO_WriteBit(LED1_PORT, LED1_PIN, 1);
GPIO_WriteBit(LED3_PORT, LED3_PIN, 1);
}
else if(value<=3000){
GPIO_WriteBit(LED0_PORT, LED0_PIN, 1);
GPIO_WriteBit(LED2_PORT, LED2_PIN, 1);
GPIO_WriteBit(LED1_PORT, LED1_PIN, 0);
GPIO_WriteBit(LED3_PORT, LED3_PIN, 1);
}
else if(value>3000){
GPIO_WriteBit(LED0_PORT, LED0_PIN, 0);
GPIO_WriteBit(LED2_PORT, LED2_PIN, 1);
GPIO_WriteBit(LED1_PORT, LED1_PIN, 1);
GPIO_WriteBit(LED3_PORT, LED3_PIN, 1);
}
}
}
|
评分
-
参与人数 1 | NXP金币 +15 |
收起
理由
|
小七
| + 15 |
打赏!源码可以直接帖上来么?截图看不清啊. |
查看全部评分
|