有人可以引导我完成这段代码(程序集)吗?

时间:2013-04-16 20:11:33

标签: assembly microcontroller msp430

我正在玩MSP430微控制器,我正在尝试了解如何让不同的物理组件相互通信。在这种情况下,我有代码(来自朋友)使用拨码开关打开7段LED显示屏的不同部分。我试图通读这段代码,并了解它是如何工作的,以及正在发挥作用的寄存器。

; 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

我很难理解代码的各个部分。例如:

我们真的需要这条线:

mov.w #0x5A80, &WDTCTL

在主? 6被移入R13怎么样?为什么6而不是其他任何数字?我也觉得好像主要部分可以简化得比目前更多。

如果有人可以帮助我完成此代码?我会非常感激。

1 个答案:

答案 0 :(得分:1)

从I2C读入R12,将其移至R13并从寄存器R13发送至输出I2C(在其他地方定义的子程序中完成 - EXTERN)。

不知道为什么在主循环Init中,但也许有人会说。

第6号是I2C模块的寻址,因为它是在评论中写的。

如果您有其他问题,请询问。

相关问题