ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
clock_trim_scan.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
28#include "fw_hal.h"
29
30
32{
33 return (*(unsigned char volatile __CODE *)(__CID_ADDR + offset));
34}
35
36void main(void)
37{
38 uint8_t i, j, vrtrim = 0x01, irtrim = 0;
39
40 // Set system clock. Invoke it to set the frequency band
42 // UART1 configuration: baud 115200 with Timer2, 1T mode, no interrupt
44
45 while(1)
46 {
47 // The upper limit of IRTRIM depends on VRTRIM, MCU becomes unstable if it goes
48 // too high, set 0x30 to a lower value if scan stucks at beginning
49 if (++irtrim == 0x30 + vrtrim)
50 {
51 irtrim = 0x00;
52 // VRTRIM controls the voltage level, normally it won't exceed 0x40
53 if (++vrtrim == 0x40)
54 {
55 vrtrim = 0x00;
56 }
57 }
58 SYS_TrimClock(vrtrim, irtrim);
59
60 UART1_TxString("ADDR: 0x");
62 UART1_TxHex(__CID_ADDR & 0xFF);
63 UART1_TxString("\r\n");
64 UART1_TxString("MCUID: ");
65 for (j = 0; j < 7; j++)
66 {
67 UART1_TxHex(readCode(18 + j));
68 UART1_TxChar(' ');
69 }
70 UART1_TxString("\r\n");
71 UART1_TxString("Current IRCBAND:");
72 UART1_TxHex(IRCBAND);
73 UART1_TxString(", VRTRIM:");
74 UART1_TxHex(VRTRIM);
75 UART1_TxString(", IRTRIM:");
76 UART1_TxHex(IRTRIM);
77 UART1_TxString(", LIRTRIM:");
78 UART1_TxHex(LIRTRIM);
79 UART1_TxString("\r\n\r\n");
80
81 SYS_Delay(50);
82 }
83}
void main(void)
uint8_t readCode(uint8_t offset)
#define __CID_ADDR
Definition: fw_cid_stc8h.h:21
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_TrimClock(uint8_t vrtrim, uint8_t irtrim)
Definition: fw_sys.c:58
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
@ HAL_State_ON
Definition: fw_types.h:71
unsigned char uint8_t
Definition: fw_types.h:18
void UART1_TxChar(char dat)
Definition: fw_uart.c:72
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
uint8_t __XDATA i