微處理器 - NXP MK20DX256 (Teensy 3.2) - Assembly - Button



參考資訊:
https://www.nxp.com/docs/en/data-sheet/K20P64M72SF1.pdf
https://www.nxp.com/docs/en/reference-manual/K20P64M72SF1RM.pdf
https://forum.pjrc.com/threads/25762-Turn-the-LED-on-with-assembler-code-(-Teensy-3-1-)?p=47739&viewfull=1#post47739

按鍵連接到PTC-2


Disable Watchdog


Port Clock


Enable Port


Port Direction


Port Input


main.s

    .equiv GPIOC_BASE,   0x400ff080
    .equiv GPIO_PDOR,    0x00
    .equiv GPIO_PDIR,    0x10
    .equiv GPIO_PDDR,    0x14

    .equiv SIM_BASE,     0x40047000
    .equiv SIM_SCGC5,    0x1038

    .equiv WDOG_BASE,    0x40052000
    .equiv WDOG_STCTRLH, 0x00
    .equiv WDOG_UNLOCK,  0x0e

    .equiv PORTC_BASE,   0x4004b000
    .equiv PORTC_PCR2,   0x08
    .equiv PORTC_PCR5,   0x14

    .thumb
    .cpu cortex-m4
    .syntax unified

    .global _start

    .text
    .org 0x0000
_start:
    .word 0x20008000
    .word reset
 
    .org 0x0100
    .thumb_func
reset:
    ldr r0, =WDOG_BASE
    ldr r1, =0xc520
    strh r1, [r0, #WDOG_UNLOCK]
    ldr r1, =0xd928
    strh r1, [r0, #WDOG_UNLOCK]
    ldr r1, =0x0000
    strh r1, [r0, #WDOG_STCTRLH]

    ldr r0, =SIM_BASE + SIM_SCGC5
    ldr r1, =(1 << 11)
    str r1, [r0]

    ldr r0, =PORTC_BASE
    ldr r1, =(1 << 8)
    str r1, [r0, #PORTC_PCR5]
    ldr r1, =(1 << 8) | (1 << 1) | (1 << 0)
    str r1, [r0, #PORTC_PCR2]

    ldr r0, =GPIOC_BASE
    ldr r1, =(1 << 5)
    str r1, [r0, #GPIO_PDDR]

0:
    ldr r1, [r0, #GPIO_PDIR]
    lsl r1, #3
    eor r1, #0xff
    str r1, [r0, #GPIO_PDOR]
    b 0b
    .end

完成