ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
fw_sys.h File Reference
#include "fw_conf.h"
#include "fw_types.h"

Go to the source code of this file.

Macros

#define __SYSCLOCK   (__CONF_FOSC / ((__CONF_CLKDIV == 0) ? 1 : __CONF_CLKDIV))
 
#define SYS_SetFOSC(__IRCBAND__, __VRTRIM__, __IRTRIM__, __LIRTRIM__)
 
#define SYS_EnableOscillatorHSI()
 
#define SYS_DisableOscillatorHSI()
 
#define SYS_EnableOscillatorLSI()
 
#define SYS_DisableOscillatorLSI()
 
#define SYS_EnableOscillatorHSE()
 
#define SYS_DisableOscillatorHSE()
 
#define SYS_SetExternalOscType(__TYPE__)   SFRX_ASSIGN(XOSCCR, 6, (__TYPE__))
 
#define SYS_EnableOscillatorLSE()
 
#define SYS_DisableOscillatorLSE()
 
#define SYS_SetExternal32kHighGain(__STATE__)   SFRX_ASSIGN(X32KCR, 6, (__STATE__))
 
#define SYS_SetSysClockOutputDivider(__DIV__)
 
#define SYS_SetClockOutputPin(__PORT__)   SFRX_ASSIGN(MCLKOCR, 7, (__STATE__))
 
#define SYS_EnableOscillator48M()
 
#define SYS_DisableOscillator48M()
 

Enumerations

enum  SYS_ExternalOSC_t { SYS_ExternalOSC_Clock = 0x00 , SYS_ExternalOSC_Crystal = 0x01 }
 
enum  SYS_SysClkOutputPort_t { SYS_SysClkOutputPort_P54 = 0x00 , SYS_SysClkOutputPort_P16 = 0x01 }
 

Functions

void SYS_SetClock (void)
 
void SYS_TrimClock (uint8_t vrtrim, uint8_t irtrim)
 
void SYS_Delay (uint16_t t)
 
void SYS_DelayUs (uint16_t t)
 

Macro Definition Documentation

◆ __SYSCLOCK

#define __SYSCLOCK   (__CONF_FOSC / ((__CONF_CLKDIV == 0) ? 1 : __CONF_CLKDIV))

STC8H Clock: MCKSEL ||===> MCLKODIV ==> MCLKO_S => P1.6/P5.4 00 Internal IRC | || 01 External OSC |==> CLKDIV ==> SYSCLK 10 External 32KHz | 11 Internal 32KHz | Precompute system clock based on __CONF_FOSC and __CONF_CLKDIV

Definition at line 45 of file fw_sys.h.

◆ SYS_DisableOscillator48M

#define SYS_DisableOscillator48M ( )
Value:
do { \
SFRX_ON(); \
(IRC48MCR) = (IRC48MCR) & ~(0x01 << 7); \
SFRX_OFF(); \
} while(0)
#define IRC48MCR
Definition: fw_reg_stc8h.h:55

Disable 48MHz USB OSC

Definition at line 163 of file fw_sys.h.

◆ SYS_DisableOscillatorHSE

#define SYS_DisableOscillatorHSE ( )
Value:
do { \
SFRX_ON(); \
(XOSCCR) = (XOSCCR) & ~(0x01 << 7); \
SFRX_OFF(); \
} while(0)
#define XOSCCR

Disable high speed external oscillator

Definition at line 102 of file fw_sys.h.

◆ SYS_DisableOscillatorHSI

#define SYS_DisableOscillatorHSI ( )
Value:
do { \
SFRX_ON(); \
(HIRCCR) = (HIRCCR) & ~(0x01 << 7); \
SFRX_OFF(); \
} while(0)
#define HIRCCR
Definition: fw_reg_stc8g.h:283

Disable high speed internal oscillator

Definition at line 66 of file fw_sys.h.

◆ SYS_DisableOscillatorLSE

#define SYS_DisableOscillatorLSE ( )
Value:
do { \
SFRX_ON(); \
(X32KCR) = (X32KCR) & ~(0x01 << 7); \
SFRX_OFF(); \
} while(0)
#define X32KCR
Definition: fw_reg_stc8g.h:288

Disable low speed external oscillator

Definition at line 124 of file fw_sys.h.

◆ SYS_DisableOscillatorLSI

#define SYS_DisableOscillatorLSI ( )
Value:
do { \
SFRX_ON(); \
(IRC32KCR) = (IRC32KCR) & ~(0x01 << 7); \
SFRX_OFF(); \
} while(0)
#define IRC32KCR

Disable low speed internal oscillator

Definition at line 84 of file fw_sys.h.

◆ SYS_EnableOscillator48M

#define SYS_EnableOscillator48M ( )
Value:
do { \
SFRX_ON(); \
RSTFLAG = 0x07; \
(IRC48MCR) = (IRC48MCR) | (0x01 << 7); \
while (!(IRC48MCR & 0x01)); \
SFRX_OFF(); \
} while(0)
#define RSTFLAG
Definition: fw_reg_stc8h.h:57

Enable 48MHz USB OSC

Definition at line 153 of file fw_sys.h.

◆ SYS_EnableOscillatorHSE

#define SYS_EnableOscillatorHSE ( )
Value:
do { \
SFRX_ON(); \
(XOSCCR) = (XOSCCR) | (0x01 << 7); \
while (!(HIRCCR & 0x01)); \
SFRX_OFF(); \
} while(0)

Enable high speed external oscillator

Definition at line 93 of file fw_sys.h.

◆ SYS_EnableOscillatorHSI

#define SYS_EnableOscillatorHSI ( )
Value:
do { \
SFRX_ON(); \
(HIRCCR) = (HIRCCR) | (0x01 << 7); \
while (!(HIRCCR & 0x01)); \
SFRX_OFF(); \
} while(0)

Enable high speed internal oscillator

Definition at line 57 of file fw_sys.h.

◆ SYS_EnableOscillatorLSE

#define SYS_EnableOscillatorLSE ( )
Value:
do { \
SFRX_ON(); \
(X32KCR) = (X32KCR) | (0x01 << 7); \
while (!(X32KCR & 0x01)); \
SFRX_OFF(); \
} while(0)

Enable low speed external oscillator

Definition at line 115 of file fw_sys.h.

◆ SYS_EnableOscillatorLSI

#define SYS_EnableOscillatorLSI ( )
Value:
do { \
SFRX_ON(); \
(IRC32KCR) = (IRC32KCR) | (0x01 << 7); \
while (!(IRC32KCR & 0x01)); \
SFRX_OFF(); \
} while(0)

Enable low speed internal oscillator

Definition at line 75 of file fw_sys.h.

◆ SYS_SetClockOutputPin

#define SYS_SetClockOutputPin (   __PORT__)    SFRX_ASSIGN(MCLKOCR, 7, (__STATE__))

System clock output pin 0:P5.4, 1:P1.6

Definition at line 148 of file fw_sys.h.

◆ SYS_SetExternal32kHighGain

#define SYS_SetExternal32kHighGain (   __STATE__)    SFRX_ASSIGN(X32KCR, 6, (__STATE__))

Set low speed external oscillator gain

Definition at line 132 of file fw_sys.h.

◆ SYS_SetExternalOscType

#define SYS_SetExternalOscType (   __TYPE__)    SFRX_ASSIGN(XOSCCR, 6, (__TYPE__))

Set high speed external oscillator type

Definition at line 110 of file fw_sys.h.

◆ SYS_SetFOSC

#define SYS_SetFOSC (   __IRCBAND__,
  __VRTRIM__,
  __IRTRIM__,
  __LIRTRIM__ 
)
Value:
do { \
IRCBAND = ((__IRCBAND__) & 0x03); \
VRTRIM = (__VRTRIM__); \
IRTRIM = (__IRTRIM__); \
LIRTRIM = ((__LIRTRIM__) & 0x03); \
} while(0)

Definition at line 47 of file fw_sys.h.

◆ SYS_SetSysClockOutputDivider

#define SYS_SetSysClockOutputDivider (   __DIV__)
Value:
do { \
SFRX_ON(); \
(MCLKOCR) = (MCLKOCR) & ~(0x7F) | (__DIV__); \
SFRX_OFF(); \
} while(0)
#define MCLKOCR

System clock output 0:No output, Foutput = SYSCLK / DIV

Definition at line 138 of file fw_sys.h.

Enumeration Type Documentation

◆ SYS_ExternalOSC_t

Enumerator
SYS_ExternalOSC_Clock 
SYS_ExternalOSC_Crystal 

Definition at line 21 of file fw_sys.h.

22{
SYS_ExternalOSC_t
Definition: fw_sys.h:22
@ SYS_ExternalOSC_Crystal
Definition: fw_sys.h:24
@ SYS_ExternalOSC_Clock
Definition: fw_sys.h:23

◆ SYS_SysClkOutputPort_t

Enumerator
SYS_SysClkOutputPort_P54 
SYS_SysClkOutputPort_P16 

Definition at line 27 of file fw_sys.h.

28{
SYS_SysClkOutputPort_t
Definition: fw_sys.h:28
@ SYS_SysClkOutputPort_P16
Definition: fw_sys.h:30
@ SYS_SysClkOutputPort_P54
Definition: fw_sys.h:29

Function Documentation

◆ SYS_Delay()

void SYS_Delay ( uint16_t  t)

Definition at line 65 of file fw_sys.c.

66{
67 uint16_t i;
68 do
69 {
70 i = ticks_ms;
71 while (--i);
72 } while (--t);
73}
__CODE uint16_t ticks_ms
Definition: fw_sys.c:30
unsigned short uint16_t
Definition: fw_types.h:19
uint8_t __XDATA i

◆ SYS_DelayUs()

void SYS_DelayUs ( uint16_t  t)

Definition at line 75 of file fw_sys.c.

76{
77 uint8_t i;
78 do
79 {
80 i = ticks_us;
81 while (--i);
82 } while (--t);
83}
__CODE uint8_t ticks_us
Definition: fw_sys.c:31
unsigned char uint8_t
Definition: fw_types.h:18

◆ SYS_SetClock()

void SYS_SetClock ( void  )

Change system clock

  • For SDCC only.
  • For Keil C51, trim IRC in STC-ISP will be more accurate
  • Invoke this in the beginning of main()

Definition at line 40 of file fw_sys.c.

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 {
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;
54 while (--i); // Wait
55#endif
56}
#define __CONF_IRCBAND
Definition: fw_conf.h:82
#define __CONF_LIRTRIM
Definition: fw_conf.h:94
#define __CONF_CLKDIV
Definition: fw_conf.h:78
#define __CONF_VRTRIM
Definition: fw_conf.h:86
#define __CONF_IRTRIM
Definition: fw_conf.h:90
#define CLKDIV
#define SYS_SetFOSC(__IRCBAND__, __VRTRIM__, __IRTRIM__, __LIRTRIM__)
Definition: fw_sys.h:47

◆ SYS_TrimClock()

void SYS_TrimClock ( uint8_t  vrtrim,
uint8_t  irtrim 
)

Definition at line 58 of file fw_sys.c.

59{
60 uint16_t i = 0;
62 while (--i); // Wait
63}