MK20DX256 >> Assembly

Button


參考資訊:
1. ds_pdf
2. pm_pdf
3. example

按鍵連接到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

完成


返回上一頁