STM8S103 >> Assembly

UART


暫存器


main.s

  .equ PD_ODR,     0x500f
  .equ PD_IDR,     0x5010
  .equ PD_DDR,     0x5011
  .equ PD_CR1,     0x5012
  .equ PD_CR2,     0x5013
  .equ UART1_DR,   0x5231
  .equ UART1_BRR1, 0x5232
  .equ UART1_BRR2, 0x5233
  .equ UART1_CR2,  0x5235

  .area data
  .area sseg
  .area home
  int main
   
  .area cseg
main:
  mov PD_DDR, #0x20
  mov PD_CR1, #0x20
  mov PD_CR2, #0x20

  ; 9600bps
  mov UART1_BRR2, #0x00
  mov UART1_BRR1, #0x0d
  mov UART1_CR2, #0x08
loop:
  mov UART1_DR, #0x55
  ldw x, #50000
d0:
  decw x
  jrne d0
  jp loop

編譯、燒錄

$ sdasstm8 -o main.s
$ sdldstm8 -ni -b home=0x8000 -b cseg=0x8080 -b data=0x0001 -b sseg=0xffff main.rel
$ sudo stm8flash -c stlinkv2 -p stm8s103f3 -u
$ sudo stm8flash -c stlinkv2 -p stm8s103f3 -s flash -w main.ihx

完成


返回上一頁