ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
adc_poll_10bit.c
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
30#include "fw_hal.h"
31
32void main(void)
33{
36 // For debug print
38 // Set ADC1(GPIO P1.1) HIP
40 // Channel: ADC1
41 ADC_SetChannel(0x01);
42 // ADC Clock = SYSCLK / 2 / (1+1) = SYSCLK / 4
44 // Right alignment, high 2-bit/4-bit in ADC_RES, low 8-bit in ADC_RESL
46 // Turn on ADC power
48
49 while(1)
50 {
51 ADC_Start();
52 NOP();
53 NOP();
54 while (!ADC_SamplingFinished());
56 /*
57 res = ADC_RESL;
58 res |= (ADC_RES & 0x0F) << 8;
59 */
60 UART1_TxHex(ADC_RES);
61 UART1_TxHex(ADC_RESL);
62 UART1_TxString("\r\n");
63 SYS_Delay(100);
64 }
65}
uint16_t res
void main(void)
#define ADC_SetChannel(__CHANNEL__)
Definition: fw_adc.h:52
#define ADC_SetClockPrescaler(__PRESCALER__)
Definition: fw_adc.h:75
#define ADC_SamplingFinished()
Definition: fw_adc.h:23
#define ADC_ClearInterrupt()
Definition: fw_adc.h:24
#define ADC_SetResultAlignmentRight()
Definition: fw_adc.h:59
#define ADC_Start()
Definition: fw_adc.h:22
#define ADC_SetPowerState(__STATE__)
Definition: fw_adc.h:21
@ GPIO_Pin_1
Definition: fw_gpio.h:46
#define GPIO_P1_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:79
@ GPIO_Mode_Input_HIP
Definition: fw_gpio.h:25
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
unsigned short uint16_t
Definition: fw_types.h:19
@ HAL_State_ON
Definition: fw_types.h:71
void UART1_TxString(uint8_t *str)
Definition: fw_uart.c:85
@ UART1_BaudSource_Timer2
Definition: fw_uart.h:34
void UART1_TxHex(uint8_t hex)
Definition: fw_uart.c:79
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition: fw_uart.c:56