This is the personal website of Garthee, who believes it is the perspiration not the perception that brings the success

Search:     All roads lead to ROME !  

Be Miracle!

Another program on AVR

This program explain some programming aspects rather than microcontroller oriented design

;**********************************************************************
;                                                                     *
;    Filename:      test2.asm                                         *
;    Date:          17 july 2008                                      *
;    File Version:  0.1                                               *
;                                                                     *
;    Author:        Gartheeban. G                                     *
;    Company:       University of Moratuwa, ETNC                      *
;    Description:   Converts the BCD fed to PORTA to 7Seg display     *
;                   code on PORTB                                     *
;                                                                     *
;**********************************************************************
;    Files required: m16def.inc                                       *
;                                                                     *
; m16def defines All the registers by the name used in datasheets     *
; with few definitions for bit locations as well. Further, it         *
; it provides macros for widely used instructions to gurantee         *
; the proper use and familiar nomenclature.                           *
;                                                                     *
;**********************************************************************

; Lets skip the general comments

.NOLIST
.INCLUDE "m16def.inc"
.LIST

.DEF    mp = R16                ; General Purpose
.DEF    tp = R17                ; Store output

.ORG    0x0000                  ; processor reset vector
RJMP    MAIN                    ; go to beginning of program

; Main program begins here, whatever the instruction line it is in
; the program memory it will be identified as MAIN elsewhere.

Main:

        ldi        mp, 0b00000000  ; Set all 0s
        out        DDRA, mp        ; PortA Input
        com        mp              ; Invert to make all 1s
        out        DDRB, mp        ; PortB Output
        out        PORTB, mp       ; Also write 0 to the ouput

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;Lookup table simpler than logic equations
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AVR assembler seems to lack "while" hence needs the whole list

START:   
         clz
         in         mp, PINA        ; Read PINA
         cpi         mp, 0          ; Is it eq to 0
         brne        P1             ; If not jump to P1
P0:      ldi        tp, 0b00111111  ; PINA eq 0 or invalid
         rjmp         ES            ; Jump to End of Sequence
P1:      cpi         mp, 1          ; Is it eq to 1
         brne        P2
         ldi        tp, 0b00000110
         rjmp         ES
P2:      cpi         mp, 2
         brne        P3
         ldi        tp, 0b01011011
         rjmp         ES
P3:      cpi         mp, 3
         brne        P4
         ldi        tp, 0b01001111
         rjmp         ES
P4:      cpi         mp, 4
         brne        P5
         ldi        tp, 0b01100110
         rjmp         ES
P5:      cpi        mp, 5
         brne        P6
         ldi        tp, 0b01101101
         rjmp         ES
P6:      cpi         mp, 6
         brne        P7
         ldi        tp, 0b01111100
         rjmp         ES
P7:      cpi         mp, 7
         brne        P8
         ldi        tp, 0b00000111
         rjmp         ES
P8:      cpi         mp, 8
         brne        P9
         ldi        tp, 0b01111111
         rjmp         ES
P9:      cpi         mp, 9
         brne        P0      

 
; If not eq to 0-9 it must be an invalid input,
; hence display 1 thus jump to P0

        ldi        tp, 0b01100111
ES:     out        PORTB, tp        ; End of sequence
        rjmp        START           ;loop