⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.asm

📁 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without ev
💻 ASM
字号:
;+---------------------------------------------------------------------------+;|                                                                           |;| Copyright (C) 2002,  Tom De Rybel                                         |;|                      on1dcd@hotmail.com                                   |;|                                                                           |;| This program is free software; you can redistribute it and/or             |;| modify it under the terms of the GNU General Public License               |;| as published by the Free Software Foundation; either version 2            |;| of the License, or any later version.                                     |;|                                                                           |;| This program is distributed in the hope that it will be useful,           |;| but WITHOUT ANY WARRANTY; without even the implied warranty of            |;| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |;| GNU General Public License for more details.                              |;|                                                                           |;| You should have received a copy of the GNU General Public License         |;| along with this program; if not, write to the Free Software               |;| Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 |;|                                                                           |;|                                                                           |;+---------------------------------------------------------------------------+; LCD module test on the Cypress EZ-USB; Writes a bit of text on a Hitachi HD44780-based standard 4X16 LCD module.;; The module operates in dumb 8-bit mode (without busyflag checking).;; Connections:   D0-D7: PC0-PC7; ------------   RS:    PA4; 	 	 EN:    PA5; 		 R/#W:  GND;;; Written by: Tom De Rybel on1dcd@hotmail.com;; This program has all the elegance of a mortally wounded warthog,; so whatever you do, don't show this to anyone who knows how to code if you ; decide to actually use it in the first place ;-). It works though.	;+-------------------------------------+;| Declaration of the EZ-USB registers |;+-------------------------------------+;.equ DPL1,	0x84.equ DPH1,	0x85.equ DPS,	0x86.equ CKCON,	0x8E.equ SPC_FNC,	0x8F.equ EXIF,	0x91.equ MPAGE,	0x92.equ SCON1,	0xC0.equ SBUF1,	0xC1.equ EICON,	0xD8.equ EIE,	0xE8.equ EIP,	0xF8		.equ CPUCS,     0x7F92	.equ PORTACFG, 	0x7F93.equ PORTBCFG, 	0x7F94.equ PORTCCFG, 	0x7F95.equ OUTA,     	0x7F96	.equ OUTB,     	0x7F97.equ OUTC,     	0x7F98.equ PINSA,    	0x7F99.equ PINSB,    	0x7F9A.equ PINSC,    	0x7F9B.equ OEA,      	0x7F9C.equ OEB,      	0x7F9D.equ OEC,      	0x7F9E.equ I2CS,	0x7FA5.equ I2DAT,	0x7FA6.equ USBCS,	0x7FD6				;+--------------------+;| Some LCD constants |;+--------------------+; .equ LINE1,	0x00.equ LINE2,	0x40.equ LINE3,	0x10.equ LINE4, 	0x50;+-------------------+;| Interrupt vectors |;+-------------------+;;Reset Vector.org 0x0000ljmp init.org 0x0100;+-------------------------+;| Initialisation sequence |;+-------------------------+; init:	;;mov	0x92, #0x7F	; tc, allows movx Ri to access ez-usb memory	mov dptr, #PORTBCFG	; All pins are standard PB pins	mov a, #00000000b	movx @dptr, a		mov dptr, #OEB		; Pin PB4 is an output pin	mov a, #00010000b	movx @dptr, a	mov dptr, #PORTCCFG	; All pins are standard PC pins	mov a, #00000000b	movx @dptr, a		mov dptr, #OEC		; Port PC is output	mov a, #0xFF	movx @dptr, a		mov dptr, #PORTACFG	; All pins are standard PA pins	mov a, #00000000b	movx @dptr, a		mov dptr, #OEA		; Pins PA4 and PA5 are output	mov a, #00110000b		movx @dptr, a	lcall init_LCD		; Initialize LCD module;+--------------+;| Main program |;+--------------+; begin:				mov r0, #LINE1	mov dptr, #0x1000	lcall write_string		mov r0, #LINE2	mov dptr, #0x1011	lcall write_string		mov r0, #LINE3	mov dptr, #0x1022	lcall write_string		mov r0, #LINE4	mov dptr, #0x1033	lcall write_string    blink:	mov dptr, #OUTB	mov a, #00010000b	movx @dptr, a	lcall  Wait100msec	lcall  Wait100msec	lcall  Wait100msec		mov dptr, #OUTB	mov a, #00000000b	movx @dptr, a	lcall  Wait100msec	lcall  Wait100msec	lcall  Wait100msec	ljmp blink;+------------------------------------+;| High-level LCD routines            |;|                                    |;| R0 and DPTR are used and modified. |;+------------------------------------+; Store the LCD DD-RAM starting address for the line on which to write in R0.; Store the begin address of the string in the DPTR; The string must terminate with a '0'.;write_string:	push acc		; Move the accumulator on the stack	mov a, r0		; Build the correct command to write the string	orl a, #10000000b	; starting address for the LCD DD-RAM	mov r0, a	lcall send_command    loop_write_string:		    		mov a, #0x00		; Read the string from the code memory and 	movc a, @a+dptr 	; write to the display until a terminating	mov r0, a		; 0x00 is found	jz end_write_string		lcall send_data	inc dptr	sjmp loop_write_string    end_write_string:	pop acc			; Retrieve the accumulator from the stack 		ret;+--------------------------+;| Low-level LCD routines   |;|                          |;| R0 is used and modified. |;+--------------------------+; R0 carries the byte to be written to the display for both "send" routines;send_command:	push acc		; Move the accumulator on the stack	mov a, dpl		; Move the dptr on the stack	push acc		mov a, dph	push acc	mov dptr, #OUTA		; Set RS low	mov a, #00000000b	movx @dptr, a			mov dptr, #OUTC		; Write data to PC		mov a, r0		movx @dptr, a	mov dptr, #OUTA		; Set EN high	mov a, #00100000b	movx @dptr, a		mov r0, #0		; Kludge to fix R0 dependency in the delay	lcall Wait10usec	; routines		mov dptr, #OUTA		; Set EN low	mov a, #00000000b	movx @dptr, a	pop acc			; Retrieve datapointer form the stack		mov dph, a		; This and the RET give sufficient delay	pop acc			; to allow the display to process the data	mov dpl, a	pop acc			; Retrieve the accumulator from the stack 	ret		send_data:	push acc		; Move the accumulator on the stack	mov a, dpl		; Move the dptr on the stack	push acc		mov a, dph	push acc	mov dptr, #OUTA		; Set RS high	mov a, #00010000b	movx @dptr, a			mov dptr, #OUTC		; Write data to PC		mov a, r0		movx @dptr, a	mov dptr, #OUTA		; Set EN high	mov a, #00110000b	movx @dptr, a		mov r0, #0		; Kludge to fix R0 dependency in the delay	lcall Wait10usec	; routines		mov dptr, #OUTA		; Set EN low	mov a, #00010000b	movx @dptr, a	pop acc			; Retrieve datapointer form the stack		mov dph, a		; This and the RET give sufficient delay	pop acc			; to allow the display to process the data	mov dpl, a	pop acc			; Retrieve the accumulator from the stack 	ret	init_LCD:	lcall Wait100msec	; Power-up reset delay safety	mov r0, #00110000b	; Function set (8-bit interface)	lcall send_command			mov r0, #0		; Kludge to fix R0 dependency in the delay routines	lcall Wait1msec		; Wait for at least 4.1 ms (already 2 in the	lcall Wait1msec		; send_command routine)		mov r0, #00110000b	; Function set (8-bit interface)	lcall send_command			mov r0, #00110000b	; Function set (8-bit interface)	lcall send_command			mov r0, #00111000b	; Function set (8-bit interface, Dual(4) line,	lcall send_command	; Display font)		mov r0, #00001000b 	; Display off	lcall send_command		mov r0, #00000001b	; Display clear	lcall send_command		mov r0, #00000110b	; Entry mode set	lcall send_command		mov r0, #10000000b	; Line one, position one	lcall send_command		mov r0, #00001100b	; Display on	lcall send_command		ret		;+----------------------------------------------------------------------+;| Timing loops taken from the buttons and lights example in USB Design |;| by Example. These are needed by the LCD routines.                    |;|                                                                      |;| A, DPTR and R0 are used and modified.		                |;+----------------------------------------------------------------------+; Wait100msec:        mov     r0, #100Wait1msec:                      ; A delay loop        mov     dptr,#-1200More:   inc     dptr            ; 3 cycles        mov     a,dpl           ; + 2        orl     a,dph           ; + 2        jnz     More            ; + 3 = 10 cycles x 1200 = 1msec        djnz    r0, Wait1msec   ;         retWait50usec:	mov	r0, #5Wait10usec:				mov	dptr, #-12More2:	inc 	dptr	mov	a, dpl	orl	a, dph	jnz	More2		; 10 cycles x 12 = 10usec 	djnz	r0, Wait10usec		ret.org 	0x1000;+-------------------------------+;| Some text-strings for the LCD |;+-------------------------------+; .db 	"<VUB Cyclotron> ",0x00.db	"CombiLyse Mark I",0x00.db	"Firmware rev. 1 ",0x00.db     "Wolf Engineering",0x00	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -