user2288023
user2288023

Reputation: 25

Can someone walk me through this code (assembly)?

I am playing around with an MSP430 Microcontroller and I am trying to understand how to get different physical components to talk with each other. In this case I have the code (from a friend) that uses a dip switch to turn on different segments of an 7 segment LED display. I am trying to read through this code and understand how it works, and what registers are in play.

; Author:
; Date:
; Title:
;
#include "msp430.h"                     ; #define controlled include file
;
; This is a basic template for the MSP430(G2231).
; The I2C.r43 library should be linked into this build to resolve references
; to the subroutines defined as EXTERN below.
;
RESET   EQU     0FFFEh
RAM     EQU     00200h
FLASH   EQU     0F800h
;
; The possible "Address" values to be passed into the subroutines below.
;
I2C_0   EQU     00000000b   // A2-A0: 000 ;Switches
I2C_1   EQU     00000010b   // A2-A0: 001
I2C_2   EQU     00000100b   // A2-A0: 010
I2C_3   EQU     00000110b   // A2-A0: 011 ;LEDs
I2C_4   EQU     00001000b   // A2-A0: 100
I2C_5   EQU     00001010b   // A2-A0: 101
I2C_6   EQU     00001100b   // A2-A0: 110
I2C_7   EQU     00001110b   // A2-A0: 111
;
; Routines below come from external I2C module
;
; No parameters
        EXTERN  InitI2C  
; Address in R12 (just A3-A1 required) - A2-A0 pins left-shifted one
; On return:  R12 = 1 if A part exists, R12 = 2 if _ part exists, R12 = 0 if no device
        EXTERN  ChkI2C        
; Address in R12 (just A3-A1 required) - A2-A0 pins left-shifted one
; Data to output in R13
        EXTERN  OutI2C        
; Address in R12 (just A3-A1 required) - A2-A0 pins left-shifted one
; Data received in R12 on return
        EXTERN  InI2C

        PUBLIC  main

        ORG     RESET
        DC16    init                    ; Set reset vector to 'init' label

        ORG     RAM

        ; <declare any global variables here>

        ORG     FLASH

init:   mov     #0280h, SP              ; Set up stack pointer
        mov     #WDTPW+WDTHOLD,&WDTCTL  ; Stop watchdog timer

main:   ; <insert additional program code here>

      mov.w #0x5A80, &WDTCTL
      call #InitI2C
      clr.w R12
      call #InI2C
      mov.w R12, R13
      mov.w #0x6, R12
      call #OutI2C
      jmp main 

        END

I am having a very tough time understanding various parts of the code. For example:

Do we really need this line:

mov.w #0x5A80, &WDTCTL

in main? How about the 6 being moved into R13? Why is it 6 and not any other number? I also feel as though the main section can be simplified alot more than what it currently is.

If someone can help run me through this code? I would appreciate it a lot.

Upvotes: 0

Views: 500

Answers (1)

Jakuje
Jakuje

Reputation: 25956

There is something read from I2C into R12, this is moved to R13 and send to output I2C from register R13 (it is done in subroutines defined somewhere else - EXTERN).

Don't know why is in main loop Init, but maybe someone will say.

Number 6 is addressing of I2C module, as it is written in comments up.

If you have other questions, just ask.

Upvotes: 1

Related Questions