ATY_LIB
V2_102_230218
ATY_LIB for general devices or ALGO
Loading...
Searching...
No Matches
fw_sys.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
15
#include "
fw_sys.h
"
16
22
#if defined (__SDCC_SYNTAX_FIX)
23
#define __CLK_REF 10000
24
#elif defined (SDCC) || defined (__SDCC)
25
#define __CLK_REF 9000
26
#elif defined __CX51__ || defined __C51__
27
#define __CLK_REF 10000
28
#endif
29
30
__CODE
uint16_t
ticks_ms
= (
__CONF_FOSC
/ ((
__CONF_CLKDIV
== 0)? 1 :
__CONF_CLKDIV
) / __CLK_REF);
31
__CODE
uint8_t
ticks_us
= (
__CONF_FOSC
/ ((
__CONF_CLKDIV
== 0)? 1 :
__CONF_CLKDIV
) / __CLK_REF / 1000);
32
33
40
void
SYS_SetClock
(
void
)
41
{
42
#if defined (SDCC) || defined (__SDCC)
43
uint16_t
i
= 0;
uint8_t
j = 5;
44
P_SW2 = 0x80;
45
if
(
CLKDIV
!= (
__CONF_CLKDIV
))
46
{
47
CLKDIV
= (
__CONF_CLKDIV
);
48
do
{
// Wait a while after clock changed, or it may block the main process
49
while
(--
i
);
50
}
while
(--j);
51
}
52
P_SW2 = 0x00;
53
SYS_SetFOSC
(
__CONF_IRCBAND
,
__CONF_VRTRIM
,
__CONF_IRTRIM
,
__CONF_LIRTRIM
);
54
while
(--
i
);
// Wait
55
#endif
56
}
57
58
void
SYS_TrimClock
(
uint8_t
vrtrim,
uint8_t
irtrim)
59
{
60
uint16_t
i
= 0;
61
SYS_SetFOSC
(
__CONF_IRCBAND
, vrtrim, irtrim,
__CONF_LIRTRIM
);
62
while
(--
i
);
// Wait
63
}
64
65
void
SYS_Delay
(
uint16_t
t)
66
{
67
uint16_t
i
;
68
do
69
{
70
i
=
ticks_ms
;
71
while
(--
i
);
72
}
while
(--t);
73
}
74
75
void
SYS_DelayUs
(
uint16_t
t)
76
{
77
uint8_t
i
;
78
do
79
{
80
i
=
ticks_us
;
81
while
(--
i
);
82
}
while
(--t);
83
}
__CONF_IRCBAND
#define __CONF_IRCBAND
Definition:
fw_conf.h:82
__CONF_LIRTRIM
#define __CONF_LIRTRIM
Definition:
fw_conf.h:94
__CONF_CLKDIV
#define __CONF_CLKDIV
Definition:
fw_conf.h:78
__CONF_VRTRIM
#define __CONF_VRTRIM
Definition:
fw_conf.h:86
__CONF_FOSC
#define __CONF_FOSC
Definition:
fw_conf.h:74
__CONF_IRTRIM
#define __CONF_IRTRIM
Definition:
fw_conf.h:90
CLKDIV
#define CLKDIV
Definition:
fw_reg_stc8a8k64d4.h:141
ticks_us
__CODE uint8_t ticks_us
Definition:
fw_sys.c:31
SYS_SetClock
void SYS_SetClock(void)
Definition:
fw_sys.c:40
SYS_TrimClock
void SYS_TrimClock(uint8_t vrtrim, uint8_t irtrim)
Definition:
fw_sys.c:58
SYS_Delay
void SYS_Delay(uint16_t t)
Definition:
fw_sys.c:65
ticks_ms
__CODE uint16_t ticks_ms
Definition:
fw_sys.c:30
SYS_DelayUs
void SYS_DelayUs(uint16_t t)
Definition:
fw_sys.c:75
fw_sys.h
SYS_SetFOSC
#define SYS_SetFOSC(__IRCBAND__, __VRTRIM__, __IRTRIM__, __LIRTRIM__)
Definition:
fw_sys.h:47
uint16_t
unsigned short uint16_t
Definition:
fw_types.h:19
uint8_t
unsigned char uint8_t
Definition:
fw_types.h:18
i
uint8_t __XDATA i
Definition:
mem_read_chipid.c:24
ATY_LIB
FwLib_STC8
src
fw_sys.c
Generated by
1.9.6