Báo cáo Thí nghiệm vi xử lý

BÀI 6: BÀN PHÍM MA TRẬN 4X4

Bài tập : Xác định sơ đồ chân và cách bố trí ma trận của bàn phím sử dụng chức năng đo điện trở của máy đo vạn năng. Viết một chương trình Assembler để hiện thị lên màn hình giá tri của phím được nhấn trên bàn phím.

 

doc51 trang | Chia sẻ: maiphuongdc | Lượt xem: 2120 | Lượt tải: 4download
Bạn đang xem trước 20 trang tài liệu Báo cáo Thí nghiệm vi xử lý, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
ử dụng timer và ngắt ngoài theo yêu cầu sau: Khi không có ngắt, điều khiển đèn sáng luân phiên: xanh – đỏ (0,5s), đỏ - vàng (0,5s), vàng – xanh (0,5s), và lặp lại….giống như đèn giao thông. Khi có ngắt ngoài, điều khiển chớp tắt cả ba đèn cùng lúc cho đến khi có tác động ngắt ngoài lần nữa thì trở lại chương trình đèn giao thông. Chương trình mẫu: **************************************** ;timer0 should gennerate interrupts 0.001 seconds ;timer0 overflow time is calculated as follows: ;0.01 seconds=(timer count value)*(1/22118400Hz)*12 ;because our clock speed is 22.184MHz and timer is advanced by one count every ;12 clock cycles.Therefore,the timer count value is calculated as 18432 .Timer ;starts from its reload value and counts upwards until it overflows at 65536 ;timer reload value is calculated as: ;timer reload value=65536-timer count value ;timer reload value=65536-18432=47104 t10ms equ 47104 ;period of blinking/running(*0.01sek.) period equ 50 ;pins,assigned to LEDs led1 equ P1.3 led2 equ P1.1 led3 equ P1.0 ;switch 1 connected to INT0 pin sw1 equ P3.2 ;TCON bits: TF1 equ TCON.7 TR1 equ TCON.6 TF0 equ TCON.5 TR0 equ TCON.4 IE1 equ TCON.3 IT1 equ TCON.2 IE0 equ TCON.2 IT0 equ TCON.0 ;IE bits EA equ IE.7 ET2 equ IE.5 ES equ IE.4 ET1 equ IE.3 EX1 equ IE.2 ET0 equ IE.1 EX0 equ IE.0 ;8051 stack stack equ $60 ;counts 0-20(*0.025) to generate 0.5 seconds counter1 equ $30 ;timer of INT0 disable counter2 equ $31 ;LEDs status LEDs equ $32 DisableINT0 bit $20.0 ;run/blinking together mode bit $20.1 odd_tact bit $20.2 ;jump to main body of the program ajmp prog ;INT0 interrupt org 3 ajmp int0_sr ;TIMER0 interrupt org 0bh ajmp t0_int ;INT1 interrupt( not used) org 13h reti ;TIMER1 interrupt( not used) org 1bh reti ;UART( serial port)interrupt( not used) org 23h reti ************* Main program******************** ;set stack pointer prog: mov SP,#stack ;TIMER0-16 bit timer mode1 mov a,TMOD anl a,#11110000b orl a,#00000001b mov TMOD,a ;Run TIMER0 setb TR0 ;INT0 low level activated clr IT0 ;Enable both TIMER0 and INT0 mov IE,#00000011b ;TIMER0-high priority mov IP,#00000010B mov counter1,#period mov LEDs,#00000001b ;Global interrupts enable setb EA m001: ;Set idle mode,loop forever until interrupted mov a,pcon orl a,#10000000b mov pcon,a sjmp m001 ****************TIMER0 interrupt service routine************** t0_int: push psw push acc ;clear interrupt flag clr TF0 ;Load TIMER0 for next 0.01 sek mov TL0,#t10ms mov TH0,#=t10ms ;suppress swich contacts bouncing: ;INT0 will remain disabled till SW1 will ;relised and 0.1 sek more jnb sw1,ti01 ;if INT0 is temporary disabled count time ;and exit i.s.r. jnb DisableINT0,ti01 djnz counter2,ti01 ;re-enable INT0 clr DisableINT0 setb ex0 ;Drive LEDs ;count 0.01 sek.intervals and exits i.s.r. ti01: djnz counter1,ti02 ;reload counter mov counter1,#period ;mode=1-all LEDs are blinking ;mode=0-LEDs are running jb mode,ti03 ;rotate LEDs 1 position left mov a,LEDs mov c,acc.2 rlc a mov LEDs,a ;drive LED pins ti05: mov c,acc.0 mov led1,c mov c,acc.1 mov led2,c mov c,acc.2 mov led3,c sjmp ti02 ;LEDs are blinking ti03: cpl odd_tact jb odd_tact,ti04 ;at even tacts will turn LEDs OFF mov a,#0 sjmp ti05 ;at odd tacts will turn them ON ti04: mov a,#00000111b sjmp i05 ti02: pop acc pop psw reti ************** External interrupt0 service rountine********* int0_sr: ;clear interrupt flag clr ie0 ; to prevent multiple interrupts due to the bouncing of ;switch contacts, disable it for 0.1 seconds clr ex0 ;load counter for 0.1 seconds mov counter2,#10 setb disableINT0 ;change mode from blinking to shift or vice versa cpl mode mov LEDs,#00000001b reti BÀI 6: BÀN PHÍM MA TRẬN 4X4 Bài tập : Xác định sơ đồ chân và cách bố trí ma trận của bàn phím sử dụng chức năng đo điện trở của máy đo vạn năng. Viết một chương trình Assembler để hiện thị lên màn hình giá tri của phím được nhấn trên bàn phím. Chương trình mẫu: ;***********DIFINITIONS********** ;-------------R0,R7 REGISTERS------------ ;R0- ;R1- ;R2- ;R3- ;R4-key index ;R5-row counter ;R6-counter for delay ;R7-counter for delay ;-------------LOWER BANK RAM------------------ FLAGS EQU 20H ;REGISTER OF EVENTS MAX_ROW EQU 4 ;KEYPAD DEFINITIONS COL1 BIT P2.4 COL2 BIT P2.5 COL3 BIT P2.6 COL4 BIT P2.7 ON_FLAG BIT FLAGS.0 ;=1if any pressed key was found TI BIT SCON.1 TR1 BIT TCON.6 CR EQU 0DH ;-------------INTERRUPT HANDLERS----------- ORG 00H LJMP MAIN ORG 03H RETI ORG 0BH RETI ORG 13H RETI ORG 1BH RETI ORG 23H RETI ;********************************** ORG 4BH ;********************************* RowSEL: DB 0FEH DB 0FDH DB 0FBH DB 0F7H KeyTBL: DB '1','2','3','A' DB '4','5','6','B' DB '7','8','9','C' DB '*','0','#','D' ;********************************** DELAY: DLY0: MOV R6,#0FFH DLY1: MOV R7,#0FFH DLY2: NOP NOP NOP DJNZ R7,DLY2 DJNZ R6,DLY1 RET ;********************************** SCAN_KEYPAD: MOV DPTR,#RowSEL MOV R5,#MAX_ROW MOV R4,#0 CLR ON_FLAG SCAN0: CLR A MOVC A,@A+DPTR MOV P2,A JNB COL1,SCAN1 INC R4 JNB COL2,SCAN1 INC R4 JNB COL3,SCAN1 INC R4 JNB COL4,SCAN1 INC R4 INC DPTR DJNZ R5,SCAN0 RET SCAN1: SETB ON_FLAG MOV DPTR,#KeyTBL MOV A,R4 MOVC A,@A+DPTR RET ;********************************** MAIN: MOV SCON,#%01010000 MOV TMOD,#20H MOV TH1,#0FDH MOV TL1,#0FDH MOV TCON,#%01001001 MOV DPTR,#MESSAGE ACALL SEND_MESSAGE LOOP: LCALL DELAY LCALL SCAN_KEYPAD JNB ON_FLAG,LOOP ACALL SEND_CHAR MOV A,#CR ACALL SEND_CHAR AJMP LOOP SEND_CHAR: MOV SBUF,A JNB TI,$ CLR TI RET SEND_MESSAGE: CLR A MOVC A,@A+DPTR JZ EXIT ACALL SEND_CHAR INC DPTR AJMP SEND_MESSAGE ;********************************** EXIT: RET ;********************************** MESSAGE STR "4*4 KEYPAD" DB CR,0 ;********************************** END Sơ đồ giải thuật chương trình : =1 =0 Quay lại =1 =0 =0 Tạo vòng LOOP Ghi 0101000 vào SCON Ghi 20H vào TMOD (timer1) Ghi 0FDh vào TH1 Ghi 01001001 vào TCON Ghi nội dung hàm MESSENGE vào DPTR Gọi hàm con SEND_MESSENGE Gọi hàm con DELAY Gọi hàm con SCAN_KEYPAD Ghi (CR) vào A Kết thúc Kiểm tra hàm ON_FLAG=0? Gọi hàm con SEND_CHAR Gọi hàm con SEND_CHAR Xóa A Ghi (A+DPTR) vào A A = 0? EXIT Gọi hàm con SEND_CHAR Tăng DPTR Ghi A vào bộ nhớ đệm TI = 0 ? Không làm gì cả Xóa cờ TI Kết thúc hàm con SEND_CHAR Nội dung cần xuất ra màn hình Câu hỏi 2: Mở rộng chương trình trên sao cho khi có phím nhấn thì giá trị nhị phân tương ứng sẽ được thể hiện trên 4 bit thấp của P0 cho đến khi phím khác được nhấn? ;***********DIFINITIONS********** ;-------------R0,R7 REGISTERS------------ ;R0- ;R1- ;R2- ;R3- ;R4-key index ;R5-row counter ;R6-counter for delay ;R7-counter for delay ;-------------LOWER BANK RAM------------------ FLAGS EQU 20H ;REGISTER OF EVENTS MAX_ROW EQU 4 ;KEYPAD DEFINITIONS COL1 BIT P2.4 COL2 BIT P2.5 COL3 BIT P2.6 COL4 BIT P2.7 ON_FLAG BIT FLAGS.0 ;=1if any pressed key was found TI BIT SCON.1 TR1 BIT TCON.6 CR EQU 0DH ;-------------INTERRUPT HANDLERS----------- ORG 00H LJMP MAIN ORG 03H RETI ORG 0BH RETI ORG 13H RETI ORG 1BH RETI ORG 23H RETI ;********************************** ORG 4BH ;********************************* RowSEL: DB 0FEH DB 0FDH DB 0FBH DB 0F7H KeyTBL: DB '1','2','3','A' DB '4','5','6','B' DB '7','8','9','C' DB '*','0','#','D' ;********************************** DELAY: DLY0: MOV R6,#0FFH DLY1: MOV R7,#0FFH DLY2: NOP NOP NOP DJNZ R7,DLY2 DJNZ R6,DLY1 RET ;********************************** SCAN_KEYPAD: MOV DPTR,#RowSEL MOV R5,#MAX_ROW MOV R4,#0 CLR ON_FLAG SCAN0: CLR A MOVC A,@A+DPTR MOV P2,A JNB COL1,SCAN1 INC R4 JNB COL2,SCAN1 INC R4 JNB COL3,SCAN1 INC R4 JNB COL4,SCAN1 INC R4 INC DPTR DJNZ R5,SCAN0 RET SCAN1: SETB ON_FLAG MOV DPTR,#KeyTBL MOV A,R4 MOVC A,@A+DPTR RET ;********************************** MAIN: MOV SCON,#%01010000 MOV TMOD,#20H MOV TH1,#0FDH MOV TL1,#0FDH MOV TCON,#%01001001 MOV DPTR,#MESSAGE ACALL SEND_MESSAGE LOOP: LCALL DELAY LCALL SCAN_KEYPAD MOV P0,P2 JNB ON_FLAG,LOOP ACALL SEND_CHAR MOV A,#CR ACALL SEND_CHAR AJMP LOOP SEND_CHAR: MOV SBUF,A JNB TI,$ CLR TI RET SEND_MESSAGE: CLR A MOVC A,@A+DPTR JZ EXIT ACALL SEND_CHAR INC DPTR AJMP SEND_MESSAGE ;********************************** EXIT: RET ;********************************** MESSAGE STR "4*4 KEYPAD" DB CR,0 ;********************************** END BÀI 7: MÀN HÌNH TINH THỂ LỎNG LCD Bài tập : Sử dụng bảng đặc tính (datasheet) của LCD, viết chương trình Assembler để hiển thị dòng ký tự “ Hello World” lên hàng đầu của LCD. Sau đó, hiểu thị dòng ký tự ở hàng thứ hai của LCD. ;************************************************************************** ; ; This module is presented here only to serve as a sample for ; 8051 program development on the MINI-MAX/51 or PRO-MAX/51 system. ; BiPOM Electronics does not guarantee its functionality ; with other micro-controller systems. ; Please e-mail any questions and suggestions to info@bipom.com. ; Visit BiPOM Electronics webpage at www.bipom.com for 8051 code examples. ; ; Module: LCDASM.ASM ; ; Revision: 1.01 ; ; Description: Subroutines to access an alphanumeric LCD ; ; InitLCD : Initializes the LCD ; WriteData : Writes the value to the data register ; WriteCtrl : Writes the value to the control register ; _MM51C_PWM : Sets a new level of Vee (LCD contrast) ; ; ; NOTE: The LCD is accessed in 4-bit mode to save port pins. ; ;************************************************************************* CTRL EQU P0.0 ;CONTROL BIT (CONTROL=RESET & DATA=SET) READ EQU P0.1 ;READ=SET & WRITE=RESET STROBE EQU P0.2 ;DATA STROBE (ENABLE) DATAPORT EQU P0 ;LCD DATA ( ONLY LOWER 4 BITS ARE USED ) ;*************** INTERRUPT HANDLERS *************************************** ORG 0H ;Reset vector SJMP main ;************************************************************************** ; Function: Main ; ; Description: Main program. ; Serves as an example of how to access peripherals ; on MINI-MAX/51. ; Never returns. ;************************************************************************** main: MOV R7,#40 ACALL InitLCD ;Initialize LCD MOV DPTR,#LCD_MESSAGE0 ;Assign pointer to LCD message PRINT: CLR A ;Clear offset MOVC A,@A+DPTR ;Read next char from string JZ EXIT ;If == 0 then exit ACALL WriteData ;Write next char to LCD INC DPTR ;Increase pointer ;SJMP PRINT ;Go to next char DJNZ R7,PRINT MOV DPTR,#LCD_MESSAGE1 ;Assign pointer to LCD message PRINT1: CLR A ;Clear offset MOVC A,@A+DPTR ;Read next char from string JZ EXIT ;If == 0 then exit ACALL WriteData ;Write next char to LCD INC DPTR ;Increase pointer SJMP PRINT1 ;Go to next char EXIT: SJMP $ ;Loop forever LCD_MESSAGE0: STRZ 'HELLO WORLD! ' LCD_MESSAGE1: STRZ 'TON DUC THANG UNIVERSITY' ;************************************************************************** ; Function: InitLCD ; ; Description: Initializes the LCD ; ; Inputs: None ; ; Returns: None ; ;************************************************************************** InitLCD: ;CTRL = READ = STROBE = 1 MOV P0,#7 ;Initialize the LCD to 4-bit mode MOV A,#3 ACALL WriteCtrl ;WriteCtrl(3) MOV R3,#50 MOV R4,#0 ACALL Delay ;delay(50); ; MOV A,#3 ACALL WriteCtrl ;WriteCtrl(3); ACALL Delay10ms ;delay(10); ; MOV A,#3 ACALL WriteCtrl ;WriteCtrl(3); ACALL Delay10ms ;delay(10); ; MOV A,#2 ACALL WriteCtrl ;WriteCtrl(2); ACALL Delay10ms ;delay(10); ; ; Function Set MOV A,#2 ACALL WriteCtrl ;WriteCtrl(2); ACALL Delay10ms ;delay(10); ; MOV A,#8 ACALL WriteCtrl ;WriteCtrl(8); ACALL Delay10ms ;delay(10); ; ; Display OFF CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#8 ACALL WriteCtrl ;WriteCtrl(8); ACALL Delay10ms ;delay(10); ; ; Display ON CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#0FH ACALL WriteCtrl ;WriteCtrl(0x0F); ACALL Delay10ms ;delay(10); ; ; Entry mode CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#6 ACALL WriteCtrl ;WriteCtrl(6); ACALL Delay10ms ;delay(10); ; ; Clear Screen CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#1 ACALL WriteCtrl ;WriteCtrl(1); MOV R3,#100 MOV R4,#0 ACALL Delay ;delay(100); ; ; Cursor home CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#2 ACALL WriteCtrl ;WriteCtrl(2); MOV R3,#100 MOV R4,#0 ACALL Delay ;delay(100); ; RET ;*************************************************************************** ; Function: WriteCtrl ; ; Description: Writes the value to the control register ; ; Inputs: ACC = value ; ; Returns: None ; ;*************************************************************************** WriteCtrl: CLR CTRL ;select control register ACALL WriteCommon ;write value to control register RET ;*************************************************************************** ; Function: WriteData ; ; Description: Writes the value to the data register ; ; Inputs: ACC = value ; ; Returns: None ; ;*************************************************************************** WriteData: SETB CTRL ;select data register PUSH ACC ;store 4 low bits SWAP A ;ACC = value >> 4 ACALL WriteCommon ;write data to LCD POP ACC ;ACC = value ACALL WriteCommon ;write data to LCD RET ;*************************************************************************** ; Function: WriteCommon ; ; Description: Writes the value to LCD ; ; Inputs: ACC = value ; ; Returns: None ; ;************************************************************************** WriteCommon: CLR READ ;clrbit (READ); SWAP A ANL A,#0F0H ;value=value<<4; ANL P0,#7 ;P0&=0x07; ORL P0,A ;P0|=value; ACALL Delay1ms ;delay(1); SETB STROBE ;setbit(STROBE); ACALL Delay1ms ;delay(1); CLR STROBE ;clrbit(STROBE); ACALL Delay1ms ;delay(1); SETB READ ;setbit(READ); ACALL Delay1ms ;delay(1); RET ;********************************************************************* ; ; Routine: _MM51C_WDT ; ; Description: Sets a new WDT period ; ; Inputs: Accumulator contains new WDT period ; 0 - disables WDT ; 1..127 - specifies WDT period (in seconds) ; ; Returns: None ; ;********************************************************************* ;********************************************************************* ; ; Routine: _MM51C_PWM ; ; Description: Sets a new level of Vee (LCD contrast) ; ; Inputs: Accumulator contains new setting ; 0..15 - specifies Vee level ; ; Returns: None ; ;********************************************************************* ;********************************************************************* ; ; Routine: _MM51C ; ; Description: Services I2C communication to on-board PIC ; ; Inputs: Accumulator contains a value to be sent to PIC ; ; Returns: None ; ;********************************************************************* ;*************************************************************** ; Function: _MM51C_TRANSMIT ; ; Description: Transmits a byte to I2C device with ; most significant bit first. ; ; Inputs: A - Contains the byte to be transmitted. ; SCL and SDA should be low on entry. ; ; Returns: - Carry is set if I2C device can not acknowledge. ; - A is modified. ; ;**************************************************************** ;***************************************************************************** ; Function: _MM51C_START ; ; Description: Signals a Start which is defined as negative going ; transition of SDA while SCL is high. ; ; Inputs: None ; ; Returns: - Carry is set if bus is not available. ; - Carry is reset if success. ; - SCL and SDA are reset upon return. ; ;****************************************************************************** ;**************************************************************************** ; Function: _MM51C_STOP ; ; Description: Signals a Stop which is defined as positive going ; transition of SDA while SCL is high. ; ; Inputs: SCL should be reset on entry ; ; Returns: SCL and SDA are set upon return. ; ;**************************************************************************** ;*************************************************************************** ; ; Function: _MM51C_DELAY ; ; Description: Produces very small delay : ; Inputs: None ; ; Returns: None ; ;*************************************************************************** ;*************************************************************************** ; ; Function: Delay1ms ; ; Description: Produces 1ms delay ; ; Inputs: None ; ; Returns: None ; ;*************************************************************************** Delay1ms: MOV R3,#2 SJMP DelayEntry ;*************************************************************************** ; ; Function: Delay10ms ; ; Description: Produces 10ms delay ; ; Inputs: None ; ; Returns: None ;*************************************************************************** Delay10ms: MOV R3,#20 DelayEntry: MOV R4,#0 SJMP Delay ;*************************************************************************** ; ; Function: Delay ; ; Desription: Produces a delay via software timing loop ; R2 count is calculated as: (crystal-72000)/48000 ; ; Inputs: R3 - Low Counter ; R4 - High Counter ; ; Returns: None ; ;*************************************************************************** Delay CJNE R3,#0,Delay_0 ; Not zero CJNE R4,#0,Delay_0 ; Not zero RET Delay_0 MOV R2,#229 ; 1ms at 11059200Hz Delay_1ms NOP NOP ; Waste 2 cycles DJNZ R2,Delay_1ms ; Loop for 1-ms DEC R3 ; Reduce count CJNE R3,#-1,Delay ; No carry DEC R4 ; Reduce high SJMP Delay_0 ; And proceed ;*************************************************************************** END Câu hỏi 2: Nếu chuỗi ký tự muốn hiển thị dài hơn 24 ký tự thì điều gì sẽ xảy ra? Trả lời: ký tự thứ 25 trở đi không hiển thị ra màn hình LCD Câu hỏi 3: Thay chuổi LCD_MESSENGER0 bằng chuỗi LCD_MESSENGER1 và nạp lại chương trình. Từ đó rút ra kết luận đầy đủ cho câu 2. Trả lời: ký tự thứ 25 tới ký tự thứ 40 sẽ không hiển thị ra màn hình LCD. Màn hình LCD chỉ hiện thị 24 ký tự ở hàng đầu tiên Một hàng của LCD chứa tối đa 40 ký tự và chỉ hiện thị ký tự thứ 1 đến ký tự thứ 24, ký tự 25 tới 40 sẽ không hiển thị. Ký tự thứ 41 trở đi sẽ xuất hiện ở hàng 2 của LCD, và hàng 2 của LCD cũng chỉ hiện thị 24 ký tự ( tức là ký tự 41 đến ký tự 64 của hàng 1) Câu hỏi 4: Lệnh MOV R2,#229 ở nhãn DELAY_0 dùng để tạo trễ 1ms. Thực tế có đúng không? Tại sao? Trả lời: Câu hỏi 5: Viết lại chương trình hiển thị chuỗi “TON DUC THANG UNIVERSITY HAVE GOOD DAY!...”trên LCD như sau: TON DUC THANG UNIVERSITY HAVE A GOOD DAY!... ;************************************************************************** ; ; This module is presented here only to serve as a sample for ; 8051 program development on the MINI-MAX/51 or PRO-MAX/51 system. ; BiPOM Electronics does not guarantee its functionality ; with other micro-controller systems. ; Please e-mail any questions and suggestions to info@bipom.com. ; Visit BiPOM Electronics webpage at www.bipom.com for 8051 code examples. ; ; Module: LCDASM.ASM ; ; Revision: 1.01 ; ; Description: Subroutines to access an alphanumeric LCD ; ; InitLCD : Initializes the LCD ; WriteData : Writes the value to the data register ;WriteCtrl : Writes the value to the control register ;_MM51C_PWM : Sets a new level of Vee (LCD contrast) ; ; ; NOTE: The LCD is accessed in 4-bit mode to save port pins. ; ;************************************************************************* CTRL EQU P0.0 ;CONTROL BIT (CONTROL=RESET & DATA=SET) READ EQU P0.1 ;READ=SET & WRITE=RESET STROBE EQU P0.2 ;DATA STROBE (ENABLE) DATAPORT EQU P0 ;LCD DATA ( ONLY LOWER 4 BITS ARE USED ) ;*************** INTERRUPT HANDLERS *************************************** ORG 0H ;Reset vector SJMP main ;************************************************************************** ; Function: Main ; ; Description: Main program. ; Serves as an example of how to access peripherals ; on MINI-MAX/51. ; Never returns. ;************************************************************************** main: MOV R7,#40 ACALL InitLCD ;Initialize LCD MOV DPTR,#LCD_MESSAGE0 ;Assign pointer to LCD message PRINT: CLR A ;Clear offset MOVC A,@A+DPTR ;Read next char from string JZ EXIT ;If == 0 then exit ACALL WriteData ;Write next char to LCD INC DPTR ;Increase pointer ;SJMP PRINT ;Go to next char DJNZ R7,PRINT MOV DPTR,#LCD_MESSAGE0 ;Assign pointer to LCD message PRINT1: CLR A ;Clear offset MOVC A,@A+DPTR ;Read next char from string JZ EXIT ;If == 0 then exit ACALL WriteData ;Write next char to LCD INC DPTR ;Increase pointer SJMP PRINT1 ;Go to next char EXIT: SJMP $ ;Loop forever LCD_MESSAGE0: STRZ 'TON DUC THANG UNIVERSITY (16 cái tab) HAVE A GOOD DAY!... “ ;************************************************************************** ; Function: InitLCD ; ; Description: Initializes the LCD ; ; Inputs: None ; ; Returns: None ; ;************************************************************************** InitLCD: ;CTRL = READ = STROBE = 1 MOV P0,#7 ;Initialize the LCD to 4-bit mode MOV A,#3 ACALL WriteCtrl ;WriteCtrl(3) MOV R3,#50 MOV R4,#0 ACALL Delay ;delay(50); ; MOV A,#3 ACALL WriteCtrl ;WriteCtrl(3); ACALL Delay10ms ;delay(10); ; MOV A,#3 ACALL WriteCtrl ;WriteCtrl(3); ACALL Delay10ms ;delay(10); ; MOV A,#2 ACALL WriteCtrl ;WriteCtrl(2); ACALL Delay10ms ;delay(10); ; Function Set MOV A,#2 ACALL WriteCtrl ;WriteCtrl(2); ACALL Delay10ms ;delay(10); ; MOV A,#8 ACALL WriteCtrl ;WriteCtrl(8); ACALL Delay10ms ;delay(10); ; Display OFF CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#8 ACALL WriteCtrl ;WriteCtrl(8); ACALL Delay10ms ;delay(10); ; Display ON CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#0FH ACALL WriteCtrl ;WriteCtrl(0x0F); ACALL Delay10ms ;delay(10); ; ; Entry mode CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#6 ACALL WriteCtrl ;WriteCtrl(6); ACALL Delay10ms ;delay(10); ; Clear Screen CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#1 ACALL WriteCtrl ;WriteCtrl(1); MOV R3,#100 MOV R4,#0 ACALL Delay ;delay(100); ; Cursor home CLR A ACALL WriteCtrl ;WriteCtrl(0); ACALL Delay10ms ;delay(10); ; MOV A,#2 ACALL WriteCtrl ;WriteCtrl(2); MOV R3,#100 MOV R4,#0 ACALL Delay ;delay(100); ; RET ;*************************************************************************** ; Function: WriteCtrl ; ; Description: Writes the value to the control register ; ; Inputs: ACC = value ; ; Returns: None ; ;*************************************************************************** WriteCtrl: CLR CTRL ;select control register ACALL WriteCommon ;write value to control register RET ;*************************************************************************** ; Function: WriteData ; ; Description: Writes the value to the data register ; ; Inputs: ACC = value ; ; Returns: None ; ;*************************************************************************** WriteData: SETB CTRL ;select data register PUSH ACC ;store 4 low bits SWAP A ;ACC = value >> 4 ACALL WriteCommon ;write data to LCD POP ACC ;ACC = value ACALL WriteCommon ;write data to LCD RET ;*************************************************************************** ; Function: WriteCommon ; ; Description: Writes the value to LCD ; ; Inputs: ACC = value ; ; Returns: None ; ;************************************************************************** WriteCommon: CLR READ ;clrbit (READ); SWAP A ANL A,#0F0H ;value=value<<4; ANL P0,#7 ;P0&=0x07; ORL P0,A ;P0|=value; ACALL Delay1ms ;delay(1); SETB STROBE ;setbit(STROBE); ACALL Delay1ms ;delay(1); CLR STROBE ;clrbit(STROBE); ACALL Delay1ms ;delay(1); SETB READ ;setbit(READ); ACALL Delay1ms ;delay(1); RET ;********************************************************************* ; ; Routine: _MM51C_WDT ; ; Descrip

Các file đính kèm theo tài liệu này:

  • docALL BAO CAO VI XU LI.doc