微處理器 - STMicroelectronics STM8S103 - Assembly - Independent watchdog(IWDG)



暫存器


Prescaler


步驟:
1. IWDG_KR(0xcc) > Enable
2. IWDG_KR(0x55) > Unlock IWDG_PR and IWDG_RLR
3. IWDG_KR(0xaa) > Reload IWDG_PR and IWDG_RLR

main.s

    .equ PB_ODR,   0x5005
    .equ PB_IDR,   0x5006
    .equ PB_DDR,   0x5007
    .equ PB_CR1,   0x5008
    .equ PB_CR2,   0x5009
    .equ IWDG_KR,  0x50e0
    .equ IWDG_PR,  0x50e1
    .equ IWDG_RLR, 0x50e2
     
    .area data
    .area sseg
    .area home
    int main

    .area cseg
main:
    mov PB_DDR, #0x20
    mov PB_CR1, #0x20

    mov IWDG_KR, #0xcc 
    mov IWDG_KR, #0x55 
    mov IWDG_RLR, #0xff
    mov IWDG_PR, #0x06
    mov IWDG_KR, #0xaa 

loop:
    ld a, PB_ODR
    xor a, #0x20
    ld PB_ODR, a
    ldw x, #5000 
d0:
    decw x
    tnzw x
    jrne d0
    jp loop

觀察LED的變化,即可發現每秒會有一次閃動變化