原创 【敏矽微ME32F103 Demokit】+ LED显示和定时器(IAR)

2024-11-3 19:58 333 3 3 分类: MCU/ 嵌入式 文集: 测评

【敏矽微ME32F103 Demokit】+ 万年历

拿到一个芯片后,习惯看一下芯片的时钟树,这次也不例外,查看手册找到了。如下图:

屏幕截图 2024-11-03 192455

看着是不是很清晰?

时钟树:

比较简单,容易看懂。

PLL可以选择IRC或外部高速晶振,

MainClock可以选IRC或外部高速晶振或者PLL,

SystemCoreClock可以分频,

AHB_CLK 等于SystemCoreClock,继续,

PCLK来源是SystemCoreClock,

APB_CLK 等于 PCLK。

测试LED和定时器,做一个万年历。

ME32F103的LED外设最多可以驱动 128个小灯,挺多的。可以设置亮度,从 0 - 255等级。初始化完管脚,取字模,将字模写入寄存器内即可实现显示。挺方便。

下面是我自己写的代码,分析给大家:

数码管各段对应MCU的seg:


数字取模如下:

#define Font_Zero (SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F)

#define Font_One (SEG_B | SEG_C)

#define Font_Two (SEG_A | SEG_B | SEG_G | SEG_E | SEG_D)

#define Font_Three (SEG_A | SEG_B | SEG_C | SEG_D | SEG_G)

#define Font_Four (SEG_F | SEG_G | SEG_B | SEG_C)

#define Font_Five (SEG_A | SEG_F | SEG_G | SEG_C | SEG_D)

#define Font_Six (SEG_A | SEG_F | SEG_E | SEG_D | SEG_C | SEG_G)

#define Font_Seven (SEG_A | SEG_B | SEG_C)

#define Font_Eight (SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G)

#define Font_Nine (SEG_A | SEG_B | SEG_C | SEG_D | SEG_G | SEG_F)

还可以取字母,我觉得这样简单好移植。

代码中再定义两个数组,数组1(cstrChar)纯字符串,定义可现实的字符;数组2(CODE)存放对应数组1字符的字模。如下图:

屏幕截图 2024-11-03 194530

显示前,先从cstrChar找到索引号,然后再根据索引从CODE数组中取出对应的字模。

屏幕截图 2024-11-03 195028

定时器外设,因为F103没有RTC,只能用定时器计数累加实现RTC的功能。这里遇到问题了。开启中断后,程序没有进入定时器中断函数,经过查找,发现IAR用的.s文件是错误的。更改后的如下:

MODULE ?cstartup

;; Forward declaration of sections.

SECTION CSTACK:DATA:NOROOT(3) ;; 8 bytes alignment

SECTION .intvec:CODE:NOROOT(2);; 4 bytes alignment

EXTERN __iar_program_start

;EXTERN HardFault_Handler

PUBLIC __vector_table

DATA

__vector_table

DCD sfe(CSTACK)

DCD __iar_program_start

DCD NMI_Handler

DCD HardFault_Handler

DCD 0

DCD 0

DCD 0

DCD 0

DCD 0

DCD 0

DCD 0

DCD SVC_Handler

DCD 0

DCD 0

DCD PendSV_Handler

DCD SysTick_Handler

; External Interrupts

DCD UART0_IRQHandler ;0

DCD BOD_IRQHandler ;1

DCD PWM_IRQHandler ;2

DCD PWMFAULT_IRQHandler ;3

DCD PA_IRQHandler ;4

DCD PB_IRQHandler ;5

DCD PC_IRQHandler ;6

DCD PD_IRQHandler ;7

DCD WAKEUP_IRQHandler ;8

DCD DMA_IRQHandler ;9

DCD IWDG_IRQHandler ;10

DCD ADC_IRQHandler ;11

DCD WWDG_IRQHandler ;12

DCD I2C0_IRQHandler ;13

DCD I2C1_IRQHandler ;14

DCD 0 ;15

DCD SPI0_IRQHandler ;16

DCD SPI1_IRQHandler ;17

DCD 0 ;18

DCD CAN_IRQHandler ;19

DCD UART3_IRQHandler ;20

DCD UART4_IRQHandler ;21

DCD UART1_IRQHandler ;22

DCD UART2_IRQHandler ;23

DCD 0 ;24

DCD ACMP0_IRQHandler ;25

DCD ACMP1_IRQHandler ;26

DCD 0 ;27

DCD BTIM0_IRQHandler ;28

DCD BTIM1_IRQHandler ;29

DCD BTIM2_IRQHandler ;30

DCD BTIM3_IRQHandler ;31

DCD CTIM0_IRQHandler ;32

DCD CTIM1_IRQHandler ;33

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;

;; Default interrupt handlers.

;;

THUMB

PUBWEAK Reset_Handler

SECTION .text:CODE:REORDER(2) ; 4 bytes alignment

Reset_Handler

LDR R0, =__iar_program_start

BX R0

PUBWEAK NMI_Handler

SECTION .text:CODE:NOROOT:REORDER(1)

NMI_Handler

B NMI_Handler

PUBWEAK HardFault_Handler

SECTION .text:CODE:NOROOT:REORDER(1)

HardFault_Handler

B HardFault_Handler

PUBWEAK SVC_Handler

SECTION .text:CODE:NOROOT:REORDER(1)

SVC_Handler

B SVC_Handler

PUBWEAK PendSV_Handler

SECTION .text:CODE:NOROOT:REORDER(1)

PendSV_Handler

B PendSV_Handler

PUBWEAK SysTick_Handler

SECTION .text:CODE:NOROOT:REORDER(1)

SysTick_Handler

B SysTick_Handler

PUBWEAK UART0_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

UART0_IRQHandler

B UART0_IRQHandler

PUBWEAK BOD_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

BOD_IRQHandler

B BOD_IRQHandler

PUBWEAK PWM_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

PWM_IRQHandler

B PWM_IRQHandler

PUBWEAK PWMFAULT_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

PWMFAULT_IRQHandler

B PWMFAULT_IRQHandler

PUBWEAK PA_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

PA_IRQHandler

B PA_IRQHandler

PUBWEAK PB_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

PB_IRQHandler

B PB_IRQHandler

PUBWEAK PC_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

PC_IRQHandler

B PC_IRQHandler

PUBWEAK PD_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

PD_IRQHandler

B PD_IRQHandler

PUBWEAK WAKEUP_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

WAKEUP_IRQHandler

B WAKEUP_IRQHandler

PUBWEAK IWDG_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

IWDG_IRQHandler

B IWDG_IRQHandler

PUBWEAK DMA_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

DMA_IRQHandler

B DMA_IRQHandler

PUBWEAK ADC_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

ADC_IRQHandler

B ADC_IRQHandler

PUBWEAK WWDG_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

WWDG_IRQHandler

B WWDG_IRQHandler

PUBWEAK I2C0_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

I2C0_IRQHandler

B I2C0_IRQHandler

PUBWEAK I2C1_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

I2C1_IRQHandler

B I2C1_IRQHandler

PUBWEAK SPI0_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

SPI0_IRQHandler

B SPI0_IRQHandler

PUBWEAK SPI1_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

SPI1_IRQHandler

B SPI1_IRQHandler

PUBWEAK CAN_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

CAN_IRQHandler

B CAN_IRQHandler

PUBWEAK UART1_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

UART1_IRQHandler

B UART1_IRQHandler

PUBWEAK UART2_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

UART2_IRQHandler

B UART2_IRQHandler

PUBWEAK UART3_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

UART3_IRQHandler

B UART3_IRQHandler

PUBWEAK UART4_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

UART4_IRQHandler

B UART4_IRQHandler

PUBWEAK BTIM0_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

BTIM0_IRQHandler

B BTIM0_IRQHandler

PUBWEAK BTIM1_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

BTIM1_IRQHandler

B BTIM1_IRQHandler

PUBWEAK BTIM2_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

BTIM2_IRQHandler

B BTIM2_IRQHandler

PUBWEAK BTIM3_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

BTIM3_IRQHandler

B BTIM3_IRQHandler

PUBWEAK CTIM0_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

CTIM0_IRQHandler

B CTIM0_IRQHandler

PUBWEAK CTIM1_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

CTIM1_IRQHandler

B CTIM1_IRQHandler

PUBWEAK ACMP0_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

ACMP0_IRQHandler

B ACMP0_IRQHandler

PUBWEAK ACMP1_IRQHandler

SECTION .text:CODE:NOROOT:REORDER(1)

ACMP1_IRQHandler

B ACMP1_IRQHandler

END

;

剩下的代码比较简单,没有什么特点,不再写出了。

作者: 王晓明, 来源:面包板社区

链接: https://mbb.eet-china.com/blog/uid-me-3925432.html

版权声明:本文为博主原创,未经本人允许,禁止转载!

文章评论0条评论)

登录后参与讨论
我要评论
0
3
关闭 站长推荐上一条 /2 下一条