我正在玩一个 MSP430 微控制器,我试图了解如何让不同的物理组件相互通信。在这种情况下,我有代码(来自朋友),它使用 DIP 开关打开 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
而不是任何其他数字?我也觉得主要部分可以比现在简化很多。
如果有人可以帮助我完成这段代码?我会很感激的。