📄 实验12_lcd_点阵.s43
字号:
#include "msp430x44x.h "
;*********************************************************************
;MSP-Test44x Demo LCD DISPLAY
;
; MSP430F449
; -----------------
; /|\| XIN|-
; | | |
; --|RST XOUT|- ________
; | | | |
; | P2.0|-->| l |
; | . | . | |
; | P2.3| . | C |
; | P2.6| . | |
; | P2.7| . | D |
; | P3.0| . | |
; | . | . | |
; | P3.8|-->|________|
; | |
;
// zhangchong
// Lierda, Inc
// February 2006.03
// Built with IAR Embedded Workbench Version: 3.40a
// ID: MSP430-TEST44X
// DATA:2005-7-12
// REV: 2.0A
// 程序功能:该程序是用F449来控制对128X64点阵的片选CS1,CS2,数据线D0-D7,读写信号等的操作?
// 来对点阵的操作,具体内容如“WELLCOME LIERDA ! TEL:0571 -88800000。具体详浏览程序描述
// 硬件连接:必须连接F449边上的p3.0-P3.7,P4.0,P4.1,P2.6,P2.7口上的短接器。另外,可以通过3296电位器R20来调节LCD灰度。
//
;----------------------------------------------------------------------
;--------------------RAM定义-------------------------------------------
;----------------------------------------------------------------------
command equ 202h ;命令缓冲
write_buff equ 203h ;写指令缓冲
x_count1 equ 204h ;写数字或字节操作字模列计数器
x_count equ 205h ;页计数器
y_count equ 206h ;列计数器
disp_col equ 207h ;显示列计数器
flag equ 208h ; CS1,CS2选择标志
write_count equ 209h ;字符串写计数器
data_count equ 20ah ;数字或字符的字模是5X8,即一个字符或数字由5个字节(5列)组成,data_count=5表示常数5列
second equ 210h ;秒计数器
min equ 211h ;分计数器
hour equ 212h ;小时计数器
cs1 equ 01h ;前64列选择
cs2 equ 02h ;后64列选择
;-----------------------------------------------------------------------
;---------------端口定义-------------------------------------------------
;-----------------------------------------------------------------------
#define P2_0_RS 0x01 // RS PIN
#define P2_1_RW 0x02 // R/W PIN
#define P2_2_EN 0x04 // EN PIN
#define P2_3_CS1 0x08 // CS1 PIN
#define P2_3_CS2 0x40 // CS2 PIN
#define P2_3_RST 0x80 // RST PIN
#define P3_0_DB0 0x01 // DB0 PIN
#define P3_1_DB1 0x02 // DB1 PIN
#define P3_2_DB2 0x04 // DB2 PIN
#define P3_3_DB3 0x08 // DB3 PIN
#define P3_4_DB4 0x10 // DB4 PIN
#define P3_5_DB5 0x20 // DB5 PIN
#define P3_6_DB6 0x40 // DB6 PIN
#define P3_7_DB7 0x80 // DB7 PIN
;-----------------------------------------------------------------------
ORG 01100h ;程序开始处
;-----------------------------------------------------------------------
Reset
mov.w #0a00h,SP ; 系统堆栈指针
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; 禁止看门狗
;-----------------------------------------------------------------------
;-----------------初始化 ,包括端口,ram------------------------------
;-----------------------------------------------------------------------
call #port_ini ;端口初始化
nop
nop
clr.b &second ;RAM初始化
clr.b &min
clr.b &hour
clr.b &flag
mov.b #0c0h,&command
call #write_command
mov.b #3fh,&command
call #write_command
call #clear_lcd
mov.b #40h,&command
call #write_command
mov.b #0b8h,&command
call #write_command
mov.b #0a6h,&BTCTL ;BT初始化并产生秒中断
bis.b #BTIE,&IE2 ;
eint
;-------------------------------------------------------------------------
;----------------主程序 显示WELCOME LIERDA 电话号码 实时时钟--------
;-------------------------------------------------------------------------
mainloop
call #welcome ;显示WELCOME LIERDA !
call #tel
call #dis_second
jmp mainloop
ret
;-------------------------------------------------------------------------
;----------------显示WELCOME LIERDA !------------------------------------
;-------------------------------------------------------------------------
welcome mov.b #00h,R6 ;显示数字或字节的个数
mov.b #5,R7 ;R7表示显示当前字节或数字的列地址
loop_w
mov.b show(R6),R13 ;show是存放当前显示字符的偏移量
cmp.b #0ffh,R13 ;判断当前有字符无显示完
jz tel
rra R13
mov.b table_count(R13),R10 ;table_count是存放当前显示字模的偏移量。
call #display_init
mov.b #05h,&data_count ;每个显示字模的列是5列
mov.b #1,&x_count ;
mov.b R7,&y_count ;显示列地址
call #display_char
inc.b R6 ;显示计数器加1
add.b #7,R7 ;获取下一字符显示列地址
jmp loop_w
ret
;-------------------------------------------------------------
;----------------显示TEL:0571-88800000------------------------
;-------------------------------------------------------------
tel
mov.b #00h,R6
mov.b #5,R7
loop mov.b show_1(R6),R13
cmp.b #0ffh,R13 ; 判断有无显示完
jz dis_second
rra R13
mov.b table_count(R13),R10
call #display_init
mov.b #05h,&data_count
mov.b #4,&x_count
mov.b R7,&y_count
call #display_char
inc.b R6
add.b #7,R7
jmp loop
ret
;-------------------------------------------------------------------------
;---------------显示时钟-------------------------------------------------
;-------------------------------------------------------------------------
dis_second mov.b &second,R13 ;显示秒
rra.b R13
rra.b R13
rra.b R13
rra.b R13
and.b #0fh,R13
mov.b table_count(R13),R10 ;字符索?
call #display_init ;显示字符初始化参数 00
mov.b #05h,&data_count
mov.b #7,&x_count
mov.b #78,&y_count
call #display_char
mov.b &second,R13
and.b #0fh,R13
mov.b table_count(R13),R10 ;字符艘
call #display_init ;显示字符初始化参
mov.b #05h,&data_count
mov.b #7,&x_count
mov.b #84,&y_count
call #display_char
mov.b #1eh,R10
call #display_init ;显示字符初始化参数 00
mov.b #05h,&data_count
mov.b #7,&x_count
mov.b #72,&y_count
call #display_char
dis_min mov.b &min,R13 ;显示分
rra.b R13
rra.b R13
rra.b R13
rra.b R13
and.b #0fh,R13
mov.b table_count(R13),R10 ;字符索?
call #display_init ;显示字符初始化参数 00
mov.b #05h,&data_count
mov.b #7,&x_count
mov.b #60,&y_count
call #display_char
mov.b &min,R13
and.b #0fh,R13
mov.b table_count(R13),R10
call #display_init ;显示字符初始化参
mov.b #05h,&data_count
mov.b #7,&x_count
mov.b #66,&y_count
call #display_char
mov.b #1eh,R10
call #display_init ;显示字符初始化参数 00
mov.b #05h,&data_count
mov.b #7,&x_count
mov.b #54,&y_count
call #display_char
dis_hour mov.b &hour,R13 ;显示小时
rra.b R13
rra.b R13
rra.b R13
rra.b R13
and.b #0fh,R13
mov.b table_count(R13),R10 ;字符索?
call #display_init ;显示字符初始化参数 00
mov.b #05h,&data_count
mov.b #7,&x_count
mov.b #42,&y_count
call #display_char
mov.b &hour,R13
and.b #0fh,R13
mov.b table_count(R13),R10 ;字符索?
call #display_init ;显示字符初始化参
mov.b #05h,&data_count
mov.b #7,&x_count
mov.b #48,&y_count
call #display_char
nop
; jmp mainloop
ret
;----------------------------------------------------------------------------------
;-----------------端口初始化-----------------------------------------------------
;----------------------------------------------------------------------------------
port_ini ;端口初始化
mov.b #0ffh,&P3DIR
mov.b #0ffh,&P3OUT
mov.b #0ffh,&P2DIR
bis.b #P2_3_CS1+P2_3_CS2+P2_3_RST,&P2OUT
bic.b &P2_3_RST,&P2OUT
nop
nop
bis.b #P2_2_EN,&P2OUT
nop
nop
bic.b #P2_2_EN,&P2OUT
nop
nop
bis.b #P2_3_RST,&P2OUT
nop
nop
bis.b #02h,&P6DIR
bis.b #02h,&P6OUT
ret
;-----------------------------------------------------------------------
;---------------写控制命令子程序----------------------------------------
;-----------------------------------------------------------------------
write_command ;写控制命令
mov.b #0ffh,&P3DIR
bis.b #P2_3_CS1+P2_3_CS2,P2OUT
bic.b #P2_0_RS+P2_1_RW,&P2OUT
mov.b &command,&P3OUT
bis.b #P2_2_EN,P2OUT
bic.b #P2_2_EN,P2OUT
ret
;---------------------------------------------------------------------
;---------------LCD清屏子程序-----------------------------------------
;---------------------------------------------------------------------
clear_lcd ;LCD清屏
clr.b x_count
clr.b y_count
next_clear_lcd
mov.b #0b8H,&command
add.b &x_count,&command
call #write_command
write_first
mov.b #40H,&command
add.b &y_count,&command
call #write_command
bis.b #cs1,&flag
bis.b #cs2,&flag
clr.b &write_buff
call #write_char
inc.b &y_count
cmp.b #64,&y_count
jlo write_first
check_x clr.b &y_count
inc.b &x_count
cmp.b &08,&x_count
jnz next_clear_lcd
ret
;-------------------------------------------------------------------------------
;---------------显示初始化子程序------------------------------------------------
;-------------------------------------------------------------------------------
display_init ;显示字符参数初始化
clr.b R5 ;数据偏移量
clr.b x_count1
clr.b &disp_col
clr.b &write_buff
ret
;-------------------------------------------------------------------------------
;--------------写单个字符子程序------------------------------------------------
;----------------------------------------------------------------------------
write_char ;写单个字符
mov.b #0ffh,&P3DIR
bit.b #cs1,&flag
jz clr_P2_3_CS1
bis.b #P2_3_CS1,P2OUT ;输出LCD点阵片选有效。
jmp check_cs2
clr_P2_3_CS1
bic.b #P2_3_CS1,P2OUT
check_cs2
bit.b #cs2,&flag
jz clr_P2_3_CS2
bis.b #P2_3_CS2,P2OUT
jmp write_char1
clr_P2_3_CS2
bic.b #P2_3_CS2,P2OUT
write_char1
bis.b #P2_0_RS,&P2OUT
bic.b #P2_1_RW,&P2OUT
mov.b &write_buff,&P3OUT
bis.b #P2_2_EN,&P2OUT
bic.b #P2_2_EN,&P2OUT
ret
;----------------------------------------------------------------------------
;----------------写字符串子程序----------------------------------------------
;----------------------------------------------------------------------------
write_strings ;写字符串
mov.b #0ffh,&P3DIR
bis.b #P2_3_CS1+P2_3_CS2,&P2OUT
bis.b #P2_0_RS,&P2OUT
bic.b #P2_1_RW,P2OUT
write_next_byte
mov.b data_table(R5),&P3OUT
bis.b #P2_2_EN,&P2OUT
nop
nop
bic.b #P2_2_EN,P2OUT
inc.b R5
dec.b &write_count
jnz write_next_byte
ret
;-----------------------------------------------------------------------------
;---------------显示字符子程序-----------------------------------------------
;-----------------------------------------------------------------------------
display_char ;显示字符
mov.b &y_count,&disp_col
clr.b &x_count1
mov.b #0b8h,&command
add.b &x_count,&command ;写页地址
call #write_command
next_char cmp.b &data_count,&x_count1 ;判断当前显示字模是否结束
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -