diff --git a/demo/tim/timer0_timer_1t.c b/demo/tim/timer0_timer_1t.c index adbfd40..bf511a6 100644 --- a/demo/tim/timer0_timer_1t.c +++ b/demo/tim/timer0_timer_1t.c @@ -18,24 +18,24 @@ static uint16_t counter = 0; INTERRUPT(Timer0_Routine, EXTI_VectTimer0) { - counter++; - if (counter == 1000) - { - counter = 0; - UART1_TxString("hello\r\n"); - } + counter++; + if (counter == 1000) + { + counter = 0; + UART1_TxString("hello\r\n"); + } } void main(void) { - // Set system clock. Remove this line if system clock is already set by STC-ISP + // Set system clock. Remove this line if system clock is already set by STC-ISP SYS_SetClock(); - // UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt + // UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200); - TIM_Timer0_Config(HAL_State_ON, TIM_TimerMode_16BitAuto, 1000); - EXTI_Timer0_SetIntState(HAL_State_ON); - EXTI_Timer0_SetIntPriority(EXTI_IntPriority_High); - EXTI_Global_SetIntState(HAL_State_ON); - TIM_Timer0_SetRunState(HAL_State_ON); + TIM_Timer0_Config(HAL_State_ON, TIM_TimerMode_16BitAuto, 1000); + EXTI_Timer0_SetIntState(HAL_State_ON); + EXTI_Timer0_SetIntPriority(EXTI_IntPriority_High); + EXTI_Global_SetIntState(HAL_State_ON); + TIM_Timer0_SetRunState(HAL_State_ON); while(1); } \ No newline at end of file diff --git a/demo/tim/timer2_timer_12t.c b/demo/tim/timer2_timer_12t.c index 9598d8b..6988245 100644 --- a/demo/tim/timer2_timer_12t.c +++ b/demo/tim/timer2_timer_12t.c @@ -16,19 +16,19 @@ INTERRUPT(Timer2_Routine, EXTI_VectTimer2) { - UART1_TxString("hello\r\n"); + UART1_TxString("hello\r\n"); } void main(void) { - SYS_SetClock(); - // UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt + SYS_SetClock(); + // UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200); - // 12T mode, prescaler:255+1, frequency: 1, interrupt: ON - TIM_Timer2_Config(HAL_State_OFF, 0xFF, 1); - EXTI_Timer2_SetIntState(HAL_State_ON); - EXTI_Global_SetIntState(HAL_State_ON); - TIM_Timer2_SetRunState(HAL_State_ON); + // 12T mode, prescaler:255+1, frequency: 1, interrupt: ON + TIM_Timer2_Config(HAL_State_OFF, 0xFF, 1); + EXTI_Timer2_SetIntState(HAL_State_ON); + EXTI_Global_SetIntState(HAL_State_ON); + TIM_Timer2_SetRunState(HAL_State_ON); while(1); } \ No newline at end of file diff --git a/demo/tim/timer2_timer_1t.c b/demo/tim/timer2_timer_1t.c index 5d6eb01..e0b3287 100644 --- a/demo/tim/timer2_timer_1t.c +++ b/demo/tim/timer2_timer_1t.c @@ -18,24 +18,24 @@ static uint8_t counter = 0; INTERRUPT(Timer2_Routine, EXTI_VectTimer2) { - counter++; - if (counter == 5) - { - counter = 0; - UART1_TxString("hello\r\n"); - } + counter++; + if (counter == 5) + { + counter = 0; + UART1_TxString("hello\r\n"); + } } void main(void) { - SYS_SetClock(); - // UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt + SYS_SetClock(); + // UART1 configuration: baud 115200 with Timer1, 1T mode, no interrupt UART1_ConfigMode1Dyn8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200); - // 1T mode, prescaler:255+1, frequency: 5, interrupt: ON - TIM_Timer2_Config(HAL_State_ON, 0xFF, 5); - EXTI_Timer2_SetIntState(HAL_State_ON); - EXTI_Global_SetIntState(HAL_State_ON); - TIM_Timer2_SetRunState(HAL_State_ON); + // 1T mode, prescaler:255+1, frequency: 5, interrupt: ON + TIM_Timer2_Config(HAL_State_ON, 0xFF, 5); + EXTI_Timer2_SetIntState(HAL_State_ON); + EXTI_Global_SetIntState(HAL_State_ON); + TIM_Timer2_SetRunState(HAL_State_ON); while(1); } \ No newline at end of file diff --git a/include/fw_cid_stc8h.h b/include/fw_cid_stc8h.h index 4f7c0ef..4cd27d0 100644 --- a/include/fw_cid_stc8h.h +++ b/include/fw_cid_stc8h.h @@ -18,19 +18,19 @@ #include "fw_reg_base.h" #if (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K08 ) - #define __CID_ADDR 0x1FE9 + #define __CID_ADDR 0x1FE7 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K12 ) - #define __CID_ADDR 0x2FE9 + #define __CID_ADDR 0x2FE7 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K16 ) - #define __CID_ADDR 0x3FE9 + #define __CID_ADDR 0x3FE7 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K17 ) - #define __CID_ADDR 0x43E9 + #define __CID_ADDR 0x43E7 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K24 ) - #define __CID_ADDR 0x5FE9 + #define __CID_ADDR 0x5FE7 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K28 ) - #define __CID_ADDR 0x6FE9 + #define __CID_ADDR 0x6FE7 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K33 ) - #define __CID_ADDR 0x83E9 + #define __CID_ADDR 0x83E7 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H3K32S4 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H3K32S2 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H2K32T ) || \ @@ -44,21 +44,22 @@ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K48TLR ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K48TLCD ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K48LCD ) - #define __CID_ADDR 0xBFE9 + #define __CID_ADDR 0xBFE7 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H3K60S4 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H3K60S2 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H2K60T ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K60TLR ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K60TLCD ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K60LCD ) - #define __CID_ADDR 0xEFE9 + #define __CID_ADDR 0xEFE7 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H3K64S4 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H3K64S2 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H2K64T ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64TLR ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64TLCD ) || \ - (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64LCD ) - #define __CID_ADDR 0xFDE9 + (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64LCD ) || \ + (__CONF_MCU_MODEL == MCU_MODEL_STC8H8K64U ) + #define __CID_ADDR 0xFDE7 #endif #define ID_ROMADDR ( (unsigned char __CODE *)(__CID_ADDR + 15)) // MCU ID 7 bytes diff --git a/include/fw_conf.h b/include/fw_conf.h index ed8d1e5..090f007 100644 --- a/include/fw_conf.h +++ b/include/fw_conf.h @@ -63,6 +63,8 @@ #define MCU_MODEL_STC8H4K64TLCD 0x2D #define MCU_MODEL_STC8H4K64LCD 0x2E +#define MCU_MODEL_STC8H8K64U 0x2F + #ifndef __CONF_FOSC #define __CONF_FOSC 24000000UL @@ -93,7 +95,7 @@ #endif #if (__CONF_MCU_MODEL == MCU_MODEL_STC8A8K64D4) - #define __CONF_MCU_TYPE_STC8A8K64D4 1 + #define __CONF_MCU_TYPE 1 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8G1K04 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8G1K08 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8G1K12 ) || \ @@ -103,7 +105,7 @@ (__CONF_MCU_MODEL == MCU_MODEL_STC8G2K48 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8G2K60 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8G2K64 ) - #define __CONF_MCU_TYPE_STC8G 1 + #define __CONF_MCU_TYPE 2 #elif (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K08 ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H1K12 ) || \ @@ -135,16 +137,17 @@ (__CONF_MCU_MODEL == MCU_MODEL_STC8H2K64T ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64TLR ) || \ (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64TLCD ) || \ - (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64LCD ) - #define __CONF_MCU_TYPE_STC8H 1 + (__CONF_MCU_MODEL == MCU_MODEL_STC8H4K64LCD ) || \ + (__CONF_MCU_MODEL == MCU_MODEL_STC8H8K64U ) + #define __CONF_MCU_TYPE 3 #endif -#if __CONF_MCU_TYPE_STC8A8K64D4 +#if (__CONF_MCU_TYPE == 1 ) #include "fw_reg_stc8a.h" -#elif __CONF_MCU_TYPE_STC8G +#elif (__CONF_MCU_TYPE == 2 ) #include "fw_reg_stc8g.h" #include "fw_cid_stc8g.h" -#elif __CONF_MCU_TYPE_STC8H +#elif (__CONF_MCU_TYPE == 3 ) #include "fw_reg_stc8h.h" #include "fw_cid_stc8h.h" #endif diff --git a/include/fw_exti.h b/include/fw_exti.h index c8bc6bd..eeecfa1 100644 --- a/include/fw_exti.h +++ b/include/fw_exti.h @@ -56,7 +56,7 @@ typedef enum #define EXTI_VectI2C 24 #define EXTI_VectTKSU 35 -#if __CONF_MCU_TYPE_STC8G +#if (__CONF_MCU_TYPE == 2 ) #define EXTI_VectPWM0 22 #define EXTI_VectPWM0FD 23 #define EXTI_VectPWM1 28 @@ -67,7 +67,7 @@ typedef enum #define EXTI_VectPWM2FD 33 #define EXTI_VectPWM4FD 34 -#elif __CONF_MCU_TYPE_STC8H +#elif (__CONF_MCU_TYPE == 3 ) #define EXTI_VectUSB 25 #define EXTI_VectPWMA 26 #define EXTI_VectPWMB 27 diff --git a/include/fw_gpio.h b/include/fw_gpio.h index 1607cff..4012d93 100644 --- a/include/fw_gpio.h +++ b/include/fw_gpio.h @@ -34,7 +34,7 @@ typedef enum GPIO_Port_3 = 3U, GPIO_Port_4 = 4U, GPIO_Port_5 = 5U, -#if __CONF_MCU_TYPE_STC8H +#if (__CONF_MCU_TYPE == 3 ) GPIO_Port_6 = 6U, GPIO_Port_7 = 7U, #endif @@ -101,7 +101,7 @@ typedef enum P5M1 = P5M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \ } while(0) -#if __CONF_MCU_TYPE_STC8H +#if (__CONF_MCU_TYPE == 3 ) #define GPIO_P6_SetMode(__PINS__, __MODE__) do { \ P6M0 = P6M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \ P6M1 = P6M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \ diff --git a/src/fw_uart.c b/src/fw_uart.c index 74175da..4e60caa 100644 --- a/src/fw_uart.c +++ b/src/fw_uart.c @@ -160,8 +160,9 @@ void UART2_TxString(uint8_t *str) void UART3_ConfigOnTimer2(HAL_State_t _1TMode, uint32_t baudrate) { + uint16_t init; UART3_SetBaudSource(0x00); - uint16_t init = _UART1_Timer_InitValueCalculate(_1TMode, baudrate); + init = _UART1_Timer_InitValueCalculate(_1TMode, baudrate); // Timer2: 1T mode and initial value. prescaler is ignored, no interrupt. TIM_Timer2_Set1TMode(_1TMode); TIM_Timer2_SetInitValue(init >> 8, init & 0xFF); @@ -170,8 +171,9 @@ void UART3_ConfigOnTimer2(HAL_State_t _1TMode, uint32_t baudrate) void UART3_ConfigOnTimer3(HAL_State_t _1TMode, uint32_t baudrate) { + uint16_t init; UART3_SetBaudSource(0x01); - uint16_t init = _UART1_Timer_InitValueCalculate(_1TMode, baudrate); + init = _UART1_Timer_InitValueCalculate(_1TMode, baudrate); // Timer3: 1T mode and initial value. prescaler is ignored, no interrupt. TIM_Timer3_Set1TMode(_1TMode); TIM_Timer3_SetInitValue(init >> 8, init & 0xFF); @@ -185,8 +187,9 @@ void UART3_ConfigOnTimer3(HAL_State_t _1TMode, uint32_t baudrate) void UART4_ConfigOnTimer2(HAL_State_t _1TMode, uint32_t baudrate) { + uint16_t init; UART4_SetBaudSource(0x00); - uint16_t init = _UART1_Timer_InitValueCalculate(_1TMode, baudrate); + init = _UART1_Timer_InitValueCalculate(_1TMode, baudrate); TIM_Timer2_Set1TMode(_1TMode); TIM_Timer2_SetInitValue(init >> 8, init & 0xFF); TIM_Timer2_SetRunState(HAL_State_ON); @@ -194,8 +197,9 @@ void UART4_ConfigOnTimer2(HAL_State_t _1TMode, uint32_t baudrate) void UART4_ConfigOnTimer4(HAL_State_t _1TMode, uint32_t baudrate) { + uint16_t init; UART4_SetBaudSource(0x01); - uint16_t init = _UART1_Timer_InitValueCalculate(_1TMode, baudrate); + init = _UART1_Timer_InitValueCalculate(_1TMode, baudrate); TIM_Timer4_Set1TMode(_1TMode); TIM_Timer4_SetInitValue(init >> 8, init & 0xFF); TIM_Timer4_SetRunState(HAL_State_ON);