微處理器 - STMicroelectronics STM8S001 - Assembly - Button



表格


main.s

    .equ PB_ODR, 0x5005
    .equ PB_IDR, 0x5006
    .equ PB_DDR, 0x5007
    .equ PB_CR1, 0x5008
    .equ PB_CR2, 0x5009
    .equ PD_ODR, 0x500f
    .equ PD_IDR, 0x5010
    .equ PD_DDR, 0x5011
    .equ PD_CR1, 0x5012
    .equ PD_CR2, 0x5013

    .area data
    .area sseg
    .area home
    int main

    .area cseg
main:
    mov PB_DDR, #0x20
    mov PB_CR1, #0x20
    mov PD_DDR, #0x00
    mov PD_CR1, #0x40
  
loop:
    btjf PD_IDR, #6, press
    bset PB_ODR, #5
    jp loop
press:
    bres PB_ODR, #5
    jp loop

完成