Create a counter that starts with 0000 and increments 1 by 1

Create a counter that starts with “0000” and increments 1 by 1 up to “9999” and wraps up to “0000” and continues. Use a 100 milliseconds delay for the loop of incrementing the number. [need an assembly code for atmel (atmelmega32) 8 bit microcontroller]

Solution

.asm code for incrementing by 1.: Test the code and let me know. Thanks!

countl    equ    20h

counth    equ    21h

org     0h        ; reset vector

sjmp    Start

org    03h        ; Ex0 interrupt

sjmp    ISR

org    20h        ; jump over vectors

Start:

setb    P3.2        ; INT0 as input

setb    IT0        ; Set level of interrupt

mov    IE,#081h    ; Global On : INT0 On..

While:

sjmp    While        ; forever loop

ISR:

    mov    A,countl    ; get counter low byte

    mov    B,counth    ; get counter high byte

    add    A,#1        ; increase counter low

    jnc    non       

    inc   b       

non:    mov    countl,A    ; store Low

    mov    counth,B    ; store High

    clr    IE0        ; ensure flag off.

    reti            ; return from interrupt..

    end

Create a counter that starts with “0000” and increments 1 by 1 up to “9999” and wraps up to “0000” and continues. Use a 100 milliseconds delay for the loop of i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site