?? 實(shí)驗(yàn)12_lcd_點(diǎn)陣.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點(diǎn)陣的片選CS1,CS2,數(shù)據(jù)線D0-D7,讀寫信號等的操作?
// 來對點(diǎn)陣的操作,具體內(nèi)容如“WELLCOME LIERDA ! TEL:0571 -88800000。具體詳瀏覽程序描述
// 硬件連接:必須連接F449邊上的p3.0-P3.7,P4.0,P4.1,P2.6,P2.7口上的短接器。另外,可以通過3296電位器R20來調(diào)節(jié)LCD灰度。
//
;----------------------------------------------------------------------
;--------------------RAM定義-------------------------------------------
;----------------------------------------------------------------------
command equ 202h ;命令緩沖
write_buff equ 203h ;寫指令緩沖
x_count1 equ 204h ;寫數(shù)字或字節(jié)操作字模列計(jì)數(shù)器
x_count equ 205h ;頁計(jì)數(shù)器
y_count equ 206h ;列計(jì)數(shù)器
disp_col equ 207h ;顯示列計(jì)數(shù)器
flag equ 208h ; CS1,CS2選擇標(biāo)志
write_count equ 209h ;字符串寫計(jì)數(shù)器
data_count equ 20ah ;數(shù)字或字符的字模是5X8,即一個(gè)字符或數(shù)字由5個(gè)字節(jié)(5列)組成,data_count=5表示常數(shù)5列
second equ 210h ;秒計(jì)數(shù)器
min equ 211h ;分計(jì)數(shù)器
hour equ 212h ;小時(shí)計(jì)數(shù)器
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 ; 系統(tǒng)堆棧指針
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初始化并產(chǎn)生秒中斷
bis.b #BTIE,&IE2 ;
eint
;-------------------------------------------------------------------------
;----------------主程序 顯示W(wǎng)ELCOME LIERDA 電話號碼 實(shí)時(shí)時(shí)鐘--------
;-------------------------------------------------------------------------
mainloop
call #welcome ;顯示W(wǎng)ELCOME LIERDA !
call #tel
call #dis_second
jmp mainloop
ret
;-------------------------------------------------------------------------
;----------------顯示W(wǎng)ELCOME LIERDA !------------------------------------
;-------------------------------------------------------------------------
welcome mov.b #00h,R6 ;顯示數(shù)字或字節(jié)的個(gè)數(shù)
mov.b #5,R7 ;R7表示顯示當(dāng)前字節(jié)或數(shù)字的列地址
loop_w
mov.b show(R6),R13 ;show是存放當(dāng)前顯示字符的偏移量
cmp.b #0ffh,R13 ;判斷當(dāng)前有字符無顯示完
jz tel
rra R13
mov.b table_count(R13),R10 ;table_count是存放當(dāng)前顯示字模的偏移量。
call #display_init
mov.b #05h,&data_count ;每個(gè)顯示字模的列是5列
mov.b #1,&x_count ;
mov.b R7,&y_count ;顯示列地址
call #display_char
inc.b R6 ;顯示計(jì)數(shù)器加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
;-------------------------------------------------------------------------
;---------------顯示時(shí)鐘-------------------------------------------------
;-------------------------------------------------------------------------
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 ;顯示字符初始化參數(shù) 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 ;顯示字符初始化參數(shù) 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 ;顯示字符初始化參數(shù) 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 ;顯示字符初始化參數(shù) 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 ;顯示小時(shí)
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 ;顯示字符初始化參數(shù) 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 ;顯示字符參數(shù)初始化
clr.b R5 ;數(shù)據(jù)偏移量
clr.b x_count1
clr.b &disp_col
clr.b &write_buff
ret
;-------------------------------------------------------------------------------
;--------------寫單個(gè)字符子程序------------------------------------------------
;----------------------------------------------------------------------------
write_char ;寫單個(gè)字符
mov.b #0ffh,&P3DIR
bit.b #cs1,&flag
jz clr_P2_3_CS1
bis.b #P2_3_CS1,P2OUT ;輸出LCD點(diǎn)陣片選有效。
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 ;判斷當(dāng)前顯示字模是否結(jié)束
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -