From 0f08cb1f418712d8ea0b36e2a6fcb15ec52bb4a2 Mon Sep 17 00:00:00 2001 From: IOsetting Date: Fri, 31 Dec 2021 23:47:26 +0800 Subject: [PATCH] opt: sfr macros for stc8g --- include/fw_adc.h | 37 ++++++++++++++++----------------- include/fw_conf.h | 15 +++++++++++--- include/fw_exti.h | 46 ++++++++++++++++++++++++++++++++++++++++-- include/fw_gpio.h | 4 ++++ include/fw_reg_stc8g.h | 6 +++++- include/fw_spi.h | 4 ++++ include/fw_uart.h | 6 ++++++ 7 files changed, 94 insertions(+), 24 deletions(-) diff --git a/include/fw_adc.h b/include/fw_adc.h index febce8a..5a5b14b 100644 --- a/include/fw_adc.h +++ b/include/fw_adc.h @@ -23,30 +23,31 @@ #define ADC_SamplingFinished() (ADC_CONTR & (0x01 << 5)) #define ADC_ClearInterrupt() SFR_RESET(ADC_CONTR, 5) #define ADC_SetPWMTriggerState(__STATE__) SFR_ASSIGN(ADC_CONTR, 4, __STATE__) + /** * ADC input channels selection * Set PxM0/PxM1 to high-impedance input for selected I/O port, and set PxIE * to shutdown digital input if you want to enable ADC in powerdown mode * * STC8H8K64U - * STC8H3K64S4 STC8H2K64T STC8H4K64TLCD - * STC8H1K28: STC8H1K08 STC8H3K64S2 STC8H4K64TLR STC8H4K64LCD - * 0000 P1.0/ADC0 P1.0/ADC0 P1.0/ADC0 P1.0/ADC0 P1.0/ADC0 - * 0001 P1.1/ADC1 P1.1/ADC1 P1.1/ADC1 P1.1/ADC1 P1.1/ADC1 - * 0010 P1.2/ADC2 N/A P1.2/ADC2 P5.4/ADC2 P5.4/ADC2 - * 0011 P1.3/ADC3 N/A N/A P1.3/ADC3 P1.3/ADC3 - * 0100 P1.4/ADC4 N/A N/A P1.4/ADC4 P1.4/ADC4 - * 0101 P1.5/ADC5 N/A N/A P1.5/ADC5 P1.5/ADC5 - * 0110 P1.6/ADC6 N/A P1.6/ADC6 P1.6/ADC6 P6.2/ADC6 - * 0111 P1.7/ADC7 N/A P1.7/ADC7 P1.7/ADC7 P6.3/ADC7 - * 1000 P0.0/ADC8 P3.0/ADC8 P0.0/ADC8 P0.0/ADC8 P0.0/ADC8 - * 1001 P0.1/ADC9 P3.1/ADC9 P0.1/ADC9 P0.1/ADC9 P0.1/ADC9 - * 1010 P0.2/ADC10 P3.2/ADC10 P0.2/ADC10 P0.2/ADC10 P0.2/ADC10 - * 1011 P0.3/ADC11 P3.3/ADC11 P0.3/ADC11 P0.3/ADC11 P0.3/ADC11 - * 1100 N/A P3.4/ADC12 P0.4/ADC12 P0.4/ADC12 P0.4/ADC12 - * 1101 N/A P3.5/ADC13 P0.5/ADC13 P0.5/ADC13 P0.5/ADC13 - * 1110 N/A P3.6/ADC14 P0.6/ADC14 P0.6/ADC14 P0.6/ADC14 - * 1111 Internal 1.19V Internal 1.19V Internal 1.19V Internal 1.19V Internal 1.19V + * STC8H3K64S4 STC8H2K64T STC8H4K64TLCD STC8G1K08 STC8G2K64S4 + * STC8H1K28: STC8H1K08 STC8H3K64S2 STC8H4K64TLR STC8H4K64LCD STC8G1K08A STC8G1K08T STC8G2K64S2 + * 0000 P1.0/ADC0 P1.0/ADC0 P1.0/ADC0 P1.0/ADC0 P1.0/ADC0 P3.0/ADC0 P1.0/ADC0 P1.0/ADC0 + * 0001 P1.1/ADC1 P1.1/ADC1 P1.1/ADC1 P1.1/ADC1 P1.1/ADC1 P3.1/ADC1 P1.1/ADC1 P1.1/ADC1 + * 0010 P1.2/ADC2 N/A P1.2/ADC2 P5.4/ADC2 P5.4/ADC2 P3.2/ADC2 P1.2/ADC2 P1.2/ADC2 + * 0011 P1.3/ADC3 N/A N/A P1.3/ADC3 P1.3/ADC3 P3.3/ADC3 P1.3/ADC3 P1.3/ADC3 + * 0100 P1.4/ADC4 N/A N/A P1.4/ADC4 P1.4/ADC4 P5.4/ADC4 P1.4/ADC4 P1.4/ADC4 + * 0101 P1.5/ADC5 N/A N/A P1.5/ADC5 P1.5/ADC5 P5.5/ADC5 P1.5/ADC5 P1.5/ADC5 + * 0110 P1.6/ADC6 N/A P1.6/ADC6 P1.6/ADC6 P6.2/ADC6 N/A P1.6/ADC6 P1.6/ADC6 + * 0111 P1.7/ADC7 N/A P1.7/ADC7 P1.7/ADC7 P6.3/ADC7 N/A P1.7/ADC7 P1.7/ADC7 + * 1000 P0.0/ADC8 P3.0/ADC8 P0.0/ADC8 P0.0/ADC8 P0.0/ADC8 N/A P3.0/ADC8 P0.0/ADC8 + * 1001 P0.1/ADC9 P3.1/ADC9 P0.1/ADC9 P0.1/ADC9 P0.1/ADC9 N/A P3.1/ADC9 P0.1/ADC9 + * 1010 P0.2/ADC10 P3.2/ADC10 P0.2/ADC10 P0.2/ADC10 P0.2/ADC10 N/A P3.2/ADC10 P0.2/ADC10 + * 1011 P0.3/ADC11 P3.3/ADC11 P0.3/ADC11 P0.3/ADC11 P0.3/ADC11 N/A P3.3/ADC11 P0.3/ADC11 + * 1100 N/A P3.4/ADC12 P0.4/ADC12 P0.4/ADC12 P0.4/ADC12 N/A P3.4/ADC12 P0.4/ADC12 + * 1101 N/A P3.5/ADC13 P0.5/ADC13 P0.5/ADC13 P0.5/ADC13 N/A P3.5/ADC13 P0.5/ADC13 + * 1110 N/A P3.6/ADC14 P0.6/ADC14 P0.6/ADC14 P0.6/ADC14 N/A P3.6/ADC14 P0.6/ADC14 + * 1111 Internal 1.19V voltage reference */ #define ADC_SetChannel(__CHANNEL__) (ADC_CONTR = ADC_CONTR & ~0x0F | ((__CHANNEL__) << 0)) diff --git a/include/fw_conf.h b/include/fw_conf.h index 218a39d..ed8d1e5 100644 --- a/include/fw_conf.h +++ b/include/fw_conf.h @@ -93,7 +93,7 @@ #endif #if (__CONF_MCU_MODEL == MCU_MODEL_STC8A8K64D4) - #include "fw_reg_stc8a.h" + #define __CONF_MCU_TYPE_STC8A8K64D4 1 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8G1K04 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8G1K08 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8G1K12 ) || \ @@ -103,8 +103,8 @@ (__CONF_MCU_MODEL == MCU_MODEL_STC8G2K48 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8G2K60 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8G2K64 ) - #include "fw_reg_stc8g.h" - #include "fw_cid_stc8g.h" + #define __CONF_MCU_TYPE_STC8G 1 + #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K08 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K12 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K16 ) || \ @@ -136,6 +136,15 @@ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64TLR ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64TLCD ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64LCD ) + #define __CONF_MCU_TYPE_STC8H 1 +#endif + +#if __CONF_MCU_TYPE_STC8A8K64D4 + #include "fw_reg_stc8a.h" +#elif __CONF_MCU_TYPE_STC8G + #include "fw_reg_stc8g.h" + #include "fw_cid_stc8g.h" +#elif __CONF_MCU_TYPE_STC8H #include "fw_reg_stc8h.h" #include "fw_cid_stc8h.h" #endif diff --git a/include/fw_exti.h b/include/fw_exti.h index 2066736..c8bc6bd 100644 --- a/include/fw_exti.h +++ b/include/fw_exti.h @@ -53,9 +53,51 @@ typedef enum #define EXTI_VectTimer3 19 #define EXTI_VectTimer4 20 #define EXTI_VectCMP 21 -#define EXTI_VectPWM 22 -#define EXTI_VectPWMFD 23 #define EXTI_VectI2C 24 +#define EXTI_VectTKSU 35 + +#if __CONF_MCU_TYPE_STC8G + #define EXTI_VectPWM0 22 + #define EXTI_VectPWM0FD 23 + #define EXTI_VectPWM1 28 + #define EXTI_VectPWM2 29 + #define EXTI_VectPWM3 30 + #define EXTI_VectPWM4 31 + #define EXTI_VectPWM5 32 + #define EXTI_VectPWM2FD 33 + #define EXTI_VectPWM4FD 34 + +#elif __CONF_MCU_TYPE_STC8H + #define EXTI_VectUSB 25 + #define EXTI_VectPWMA 26 + #define EXTI_VectPWMB 27 + + #define EXTI_VectRTC 36 + + #define EXTI_VectP0 37 + #define EXTI_VectP1 38 + #define EXTI_VectP2 39 + #define EXTI_VectP3 40 + #define EXTI_VectP4 41 + #define EXTI_VectP5 42 + #define EXTI_VectP6 43 + #define EXTI_VectP7 44 + + #define EXTI_VectDMA_M2M 47 + #define EXTI_VectDMA_ADC 48 + #define EXTI_VectDMA_SPI 49 + #define EXTI_VectDMA_UR1T 50 + #define EXTI_VectDMA_UR1R 51 + #define EXTI_VectDMA_UR2T 52 + #define EXTI_VectDMA_UR2R 53 + #define EXTI_VectDMA_UR3T 54 + #define EXTI_VectDMA_UR3R 55 + #define EXTI_VectDMA_UR4T 56 + #define EXTI_VectDMA_UR4R 57 + #define EXTI_VectDMA_LCM 58 + #define EXTI_VectLCM 59 + +#endif #define EXTI_Global_SetIntState(__STATE__) SBIT_ASSIGN(EA, __STATE__) #define EXTI_Timer0_SetIntState(__STATE__) SBIT_ASSIGN(ET0, __STATE__) diff --git a/include/fw_gpio.h b/include/fw_gpio.h index cf851c8..1607cff 100644 --- a/include/fw_gpio.h +++ b/include/fw_gpio.h @@ -34,8 +34,10 @@ typedef enum GPIO_Port_3 = 3U, GPIO_Port_4 = 4U, GPIO_Port_5 = 5U, +#if __CONF_MCU_TYPE_STC8H GPIO_Port_6 = 6U, GPIO_Port_7 = 7U, +#endif } GPIO_Port_t; typedef enum @@ -99,6 +101,7 @@ typedef enum P5M1 = P5M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \ } while(0) +#if __CONF_MCU_TYPE_STC8H #define GPIO_P6_SetMode(__PINS__, __MODE__) do { \ P6M0 = P6M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \ P6M1 = P6M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \ @@ -108,6 +111,7 @@ typedef enum P7M0 = P7M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \ P7M1 = P7M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \ } while(0) +#endif #define GPIO_SetPullUp(__PORT__, __PINS__, __STATE__) do { \ P_SW2 = 0x80; \ diff --git a/include/fw_reg_stc8g.h b/include/fw_reg_stc8g.h index 0512aef..2670a38 100644 --- a/include/fw_reg_stc8g.h +++ b/include/fw_reg_stc8g.h @@ -283,7 +283,7 @@ SFR(RSTCFG, 0xFF); #define MCLKOCR (*(unsigned char volatile __XDATA *)0xfe05) #define IRCDB (*(unsigned char volatile __XDATA *)0xfe06) #define X32KCR (*(unsigned char volatile __XDATA *)0xfe08) - +#define PxPU 0xfe10 #define P0PU (*(unsigned char volatile __XDATA *)0xfe10) #define P1PU (*(unsigned char volatile __XDATA *)0xfe11) #define P2PU (*(unsigned char volatile __XDATA *)0xfe12) @@ -292,6 +292,7 @@ SFR(RSTCFG, 0xFF); #define P5PU (*(unsigned char volatile __XDATA *)0xfe15) #define P6PU (*(unsigned char volatile __XDATA *)0xfe16) #define P7PU (*(unsigned char volatile __XDATA *)0xfe17) +#define PxNCS 0xfe18 #define P0NCS (*(unsigned char volatile __XDATA *)0xfe18) #define P1NCS (*(unsigned char volatile __XDATA *)0xfe19) #define P2NCS (*(unsigned char volatile __XDATA *)0xfe1a) @@ -300,6 +301,7 @@ SFR(RSTCFG, 0xFF); #define P5NCS (*(unsigned char volatile __XDATA *)0xfe1d) #define P6NCS (*(unsigned char volatile __XDATA *)0xfe1e) #define P7NCS (*(unsigned char volatile __XDATA *)0xfe1f) +#define PxSR 0xfe20 #define P0SR (*(unsigned char volatile __XDATA *)0xfe20) #define P1SR (*(unsigned char volatile __XDATA *)0xfe21) #define P2SR (*(unsigned char volatile __XDATA *)0xfe22) @@ -308,6 +310,7 @@ SFR(RSTCFG, 0xFF); #define P5SR (*(unsigned char volatile __XDATA *)0xfe25) #define P6SR (*(unsigned char volatile __XDATA *)0xfe26) #define P7SR (*(unsigned char volatile __XDATA *)0xfe27) +#define PxDR 0xfe28 #define P0DR (*(unsigned char volatile __XDATA *)0xfe28) #define P1DR (*(unsigned char volatile __XDATA *)0xfe29) #define P2DR (*(unsigned char volatile __XDATA *)0xfe2a) @@ -316,6 +319,7 @@ SFR(RSTCFG, 0xFF); #define P5DR (*(unsigned char volatile __XDATA *)0xfe2d) #define P6DR (*(unsigned char volatile __XDATA *)0xfe2e) #define P7DR (*(unsigned char volatile __XDATA *)0xfe2f) +#define PxIE 0xfe30 #define P0IE (*(unsigned char volatile __XDATA *)0xfe30) #define P1IE (*(unsigned char volatile __XDATA *)0xfe31) #define P2IE (*(unsigned char volatile __XDATA *)0xfe32) diff --git a/include/fw_spi.h b/include/fw_spi.h index 2bee452..fb6b72d 100644 --- a/include/fw_spi.h +++ b/include/fw_spi.h @@ -25,6 +25,10 @@ * SPI MOSI -> 2 15 15(P34) * SPI MISO -> 3 14 14(P33) * SPI CLK -> 4 13 13(P32) + * + * The ports for STC8G1K08-8Pin, STC8G1K08A are different: + * SS MO MI SCLK + * 00 - P5.5 P5.4 P3.3 P3.2, 01/10/11 - n/a */ typedef enum { diff --git a/include/fw_uart.h b/include/fw_uart.h index edd64b3..3ae45d0 100644 --- a/include/fw_uart.h +++ b/include/fw_uart.h @@ -32,6 +32,12 @@ typedef enum UART1_BaudSource_Timer2 = 0x01, } UART1_BaudSource_t; +/** + * Alternative ports + * + * The ports for STC8G1K08-8Pin and STC8G1K08A are different: + * 00 - P3.0 P3.1, 01 - P3.2 P3.3, 10 - P5.4 P5.5, 11 - n/a +*/ typedef enum { UART1_AlterPort_P30_P31 = 0x00,