;除了官网提供的汇编例程,另外找个msp430汇编的代码挺难的
#include "msp430x11x1.h"
;******************************************************************************
; 高位在前,先传输,最后是低位
; MSP-FET430x110 Demo - Serial Interface with HC164 Shift Register
;
; Description: Transfer byte data from Data (R4) serially to to HC164.
; Data incremented in the mainloop, effectively increment HC164 QA - QH.
;
; MSP430F1121 ^ HC164
; ----------------- | ----------
; | | |-|/CLR,B | 8
; | P2.1|-->|CLK Qx|--->
; | P2.3|-->|A |
; | | | |
;
#define Data R4
CLK equ 002h ; P2.1 Serial Clock 9脚
A equ 008h ; P2.3 Data Out 11脚
T_CE equ 080h ; 时钟芯片片选信号CE
T_CLK equ 040h ; 时钟芯片时钟脉冲信号SCLK
T_INT equ 020h ; 时钟芯片中断输出端INT0
;高位在前,先传输,最后是低位
;******************************************************************************
;-----------------------------------------------------------------------------
ORG 0F000h ; Program Start
;-----------------------------------------------------------------------------
RESET mov.w #0300h,SP ; 堆栈初始化
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; 关掉看门狗
SetupP1 bis.b #001h,&P1DIR ; P1.0 output
SetupP2 bic.b #CLK+A,&P2OUT ; Reset CLK and A
bis.b #CLK+A,&P2DIR ; CLK and A config. as output
eint ; 开总中断
bic.b #T_INT,&P2DIR ; P2.5 为输入模式
bis.b #T_INT,&P2IE ; P2.5 中断允许
bis.b #T_INT,&P2IES ; P2.5 中断下降沿有效
bic.b #T_INT,&P2IFG ; 复位中断标志
Mainloop
call #DisHELLO ;显示英文HELLO
call #DisPASS ;显示英文PAS
jmp Mainloop;
;-----------------------------------------------------------------------------
clrdipl;显示清除
;-----------------------------------------------------------------------------
clrloop mov.b #000h,Data;
call #TX_HC164;
call #Delay;
mov.b #000h,Data;
call #TX_HC164;
call #Delay;
mov.b #000h,Data;
call #TX_HC164;
call #Delay;
mov.b #000h,Data;
call #TX_HC164;
call #Delay;
mov.b #000h,Data;
call #TX_HC164;
call #Delay;
mov.b #000h,Data;
call #TX_HC164;
call #Delay;
mov.b #000h,Data;
call #TX_HC164;
call #Delay;
mov.b #000h,Data;
call #TX_HC164;
call #Delay;
mov.b #000h,Data;
call #TX_HC164;
call #Delay;
mov.b #000h,Data;
call #TX_HC164;
call #Delay;
call #Delay;
endclr ret
;
;
;-----------------------------------------------------------------------------
TX_HC164; Shift Data (R4) --> HC164
;-----------------------------------------------------------------------------
push.b #08 ; TOS = 8-bit counter
TX_loop bic.b #A,&P2OUT ; A reset
rla.b Data ; Data MSB -> Carry
jnc Clk_1 ;
Out_1 bis.b #A,&P2OUT ; A set
Clk_1 bis.b #CLK,&P2OUT ; SCLK set
Clk_0 bic.b #CLK,&P2OUT ; SCLK reset
dec.b 0(SP) ; All 8 bits sent?
jnz TX_loop ;
incd.w SP ; bit counter off stack
ret ; Return from subroutine
;-----------------------------------------------------------------------------
Delay; Software delay
;-----------------------------------------------------------------------------
push.w #00fffh ; Delay to TOS
L1 dec.w 0(SP) ; Decrement TOS
jnz L1 ; Delay over?
incd.w SP ; Clean TOS
ret ;
;
;-----------------------------------------------------------------------------
Ldelay; Software delay
;-----------------------------------------------------------------------------
push.w #09fffh ; Delay to TOS
L2 dec.w 0(SP) ; Decrement TOS
jnz L2 ; Delay over?
incd.w SP ; Clean TOS
ret ;
;-----------------------------------------------------------------------------
DisPASS;显示英文PASS
;-----------------------------------------------------------------------------
call #clrdipl;
mov.b #08eh,Data;
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #0080h,Data;8
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #080h,Data;5
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #0e6h,Data;6
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #0eeh,Data;7
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #0dah,Data;9
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #0dah,Data;1
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #080h,Data;2
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #080h,Data;3
call #TX_HC164;
call #Ldelay;
call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
ret
;-----------------------------------------------------------------------------
DisHELLO;显示英文HELLO
;-----------------------------------------------------------------------------
call #clrdipl;
mov.b #04eh,Data;
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #0080h,Data;-
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #0ech,Data;H
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #0f3h,Data;E
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #071h,Data;L
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #070h,Data;L
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #07eh,Data;O
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #010h,Data;-
call #TX_HC164;
call #Delay;
call #Delay;
mov.b #010h,Data;-
call #TX_HC164;
call #Ldelay;
call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
;call #Ldelay;
ret
;-----------------------------------------------------------------------------
P2_ISR;
;-----------------------------------------------------------------------------
xor.b #001h,&P1OUT ; Toggle P1.0
call #Delay;
call #DisPASS ;显示英文PAS
call #Ldelay;
reti ;
;-----------------------------------------------------------------------------
; Interrupt Vectors Used MSP430x11x1
;-----------------------------------------------------------------------------
ORG 0FFFEh ; MSP430 RESET Vector
DW RESET ;
ORG 0FFE6h ; P2.x Vector
DW P2_ISR ;
END
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>