2021-12-30 16:09:36 +01:00
|
|
|
// Copyright 2021 IOsetting <iosetting(at)outlook.com>
|
2021-12-30 05:19:02 +01:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* STC8H3K64S2
|
|
|
|
* AGrnd -> GND
|
|
|
|
* AVcc -> VCC
|
|
|
|
* AVref -> VCC
|
|
|
|
* Vcc -> VCC
|
|
|
|
* Gnd -> GND
|
|
|
|
* ADC1 -> Test voltage
|
|
|
|
*
|
|
|
|
* STC8H1K08
|
|
|
|
* AVref -> VCC
|
|
|
|
* Vcc -> VCC
|
|
|
|
* Gnd -> GND
|
|
|
|
* ADC1 -> Test voltage
|
|
|
|
*/
|
|
|
|
#include "fw_hal.h"
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
uint8_t res;
|
2021-12-30 15:48:21 +01:00
|
|
|
SYS_SetClock();
|
2021-12-30 05:19:02 +01:00
|
|
|
// For debug print
|
2022-01-09 12:26:52 +01:00
|
|
|
UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
|
2021-12-30 05:19:02 +01:00
|
|
|
// Set ADC1(GPIO P1.1) HIP
|
|
|
|
GPIO_P1_SetMode(GPIO_Pin_1, GPIO_Mode_Input_HIP);
|
|
|
|
// Channel: ADC1
|
|
|
|
ADC_SetChannel(0x01);
|
|
|
|
// ADC Clock = SYSCLK / 2 / (1+1) = SYSCLK / 4
|
2022-01-08 16:58:12 +01:00
|
|
|
ADC_SetClockPrescaler(0x01);
|
2021-12-30 05:19:02 +01:00
|
|
|
// Left alignment, high 8-bit in ADC_RES
|
|
|
|
ADC_SetResultAlignmentLeft();
|
|
|
|
// Turn on ADC power
|
|
|
|
ADC_SetPowerState(HAL_State_ON);
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
ADC_Start();
|
|
|
|
NOP();
|
|
|
|
NOP();
|
2021-12-30 15:48:21 +01:00
|
|
|
while (!ADC_SamplingFinished());
|
2021-12-30 05:19:02 +01:00
|
|
|
ADC_ClearInterrupt();
|
|
|
|
res = ADC_RES;
|
|
|
|
|
|
|
|
UART1_TxString("Result: ");
|
|
|
|
UART1_TxHex(res);
|
|
|
|
UART1_TxString("\r\n");
|
|
|
|
SYS_Delay(100);
|
|
|
|
}
|
|
|
|
}
|