AS11, an absolute assembler for Motorola MCU's, version 1.2e

                        *
                        * Lcd2.asm ---- 16X2 LCD sample program for FOX11 board
                        *		with Wytec Phantom Monitor, (c)2003, EVBplus.com
                        *		Written By Wayne Chu
                        *
                        *    Function:	This program displays a message on a 16X2 LCD display module
                        *		by calling sel_inst(instruction), sel_data, wrt_nibble and
                        *               wrt_byte subroutines. These subroutines can be used for
                        *               controlling many different types of LCD display.
                        *
                        *		The LCD driver source code is included in this example program
                        *
                        *  This sample program uses 4-bit transfer via port F:
                        ;  PF0 ------- RS ( register select, 0 = register transfer, 1 = data transfer).
                        ;  PF1 ------- Enable ( write pulse )
                        ;  PF4 ------- Data Bit 4 of LCD
                        ;  PF5 ------- Data Bit 5 of LCD
                        ;  PF6 ------- Data Bit 6 of LCD
                        ;  PF7 ------- Data Bit 7 of LCD
                        ;
                        ;
                        ; Timing of 4-bit data transfer is shown on page 11 of the Seiko LCD
                        ; application note on the distribution CD. The file name is Seikolcd.pdf
                        ;
                        *
0001                    DB0:		equ	1
0002                    DB1:		equ	2
                        *
                        
8fff                    STACK:		equ	$8FFF
                        
00a7                    ONE_MS		equ	167	; for 8 MHz    1000us/6us=167
0343                    FIVE_MS		equ	835
0686                    TEN_MS		equ	1670
                        
                        
1403                    PORTF   	equ	$1403
000f                    d40us:		equ	15	; 15x6us= 90 us, 60us ok
0001                    REG_SEL:	equ	DB0	; 0=reg, 1=data
0002                    ENABLE:		equ     DB1
00fe                    NOT_REG_SEL:	equ	$FE
00fd                    NOT_ENABLE:	equ     $FD
00f7                    NOT_RESET       equ     $F7     ; force bit 3 = 0
                        
0000                      		org	0
0000                    temp1:		rmb	1
0001                    pfimg:		rmb	1
                        
0001                    LCDimg:		equ	pfimg
0001                    LCD_RSimg:	equ	pfimg
0001                    LCD_ENimg:	equ	pfimg
                        
1403                    LCD:		equ	PORTF
1403                    LCD_RS:		equ	PORTF
1403                    LCD_EN:		equ	PORTF
                        *
f000                    	org	$F000
f000 7e f0 d6           	jmp	start
                        
f003                    delay_10ms:
f003 01                 	nop
f004 3c                 d10ms:  pshx
f005 ce 06 86           	ldx     #TEN_MS
f008 8d 0a                	bsr	del1
f00a 38                   	pulx
f00b 39                 	rts
f00c 3c                 d5ms:   pshx
f00d ce 03 43           	ldx     #FIVE_MS
f010 8d 02                	bsr	del1
f012 38                 	pulx
f013 39                 	rts
f014 09                 del1:	dex
f015 08                 	inx
f016 09                 	dex
f017 26 fb              	bne	del1
f019 39                 	rts
                        *
f01a                    lcd_ini:
f01a 4f                 	clra
f01b 97 01              	staa	pfimg
f01d b7 14 03           	staa	PORTF
f020 ce f0 36                  	ldx	#inidsp   	; point to init. codes.
f023 bd f0 4a                  	jsr    	sel_inst
f026 e6 00                     	ldab   	0,x
f028 08                        	inx
f029 a6 00              onext:	ldaa   	0,x
f02b bd f0 77                  	jsr    	wrt_nibble   	; initiate write pulse.
f02e 08                        	inx
f02f bd f0 0c           	jsr	d5ms
f032 5a                        	decb
f033 26 f4                     	bne    	onext
f035 39                    	rts
f036 0c                 inidsp: fcb	12		; number of high nibbles
                        *				; use high nibbles only, low nibbles are ignored
f037 30                 	fcb	$30		; 1st reset code, must delay 4.1ms after sending
f038 30                         fcb	$30		; 2nd reste code, must delay 100us after sending
                        
                        ; all following 10 nibbles must be delay 40us each after sending
f039 30                 	fcb     $30             ; 3rd reset code,
f03a 20                 	fcb	$20		; 4th reste code,
f03b 20                         fcb	$20   		; 4 bit mode, 2 line, 5X7 dot
f03c 80                 	fcb	$80   		; 4 bit mode, 2 line, 5X7 dot
f03d 00                         fcb	$00		; cursor increment, disable display shift
f03e 60                 	fcb	$60		; cursor increment, disable display shift
f03f 00                         fcb	$00		; display on, cursor off, no blinking
f040 c0                 	fcb	$C0		; display on, cursor off, no blinking
f041 00                 	fcb	$00		; clear display memory, set cursor to home pos
f042 10                 	fcb	$10		; clear display memory, set cursor to home pos
                        *
f043                    sel_data:
f043 36                 	psha
                        *	bset	LCD_RSimg REG_SEL	; select instruction
f044 96 01              	ldaa	LCD_RSimg
f046 8a 01              	oraa	#REG_SEL
f048 20 05              	bra	sel_i
f04a                    sel_inst:
f04a 36                 	psha
                        *	bclr	LCD_RSimg REG_SEL	; select instruction
f04b 96 01              	ldaa	LCD_RSimg
f04d 84 fe              	anda	#NOT_REG_SEL
f04f 97 01              sel_i:	staa	LCD_RSimg
f051 84 f7              	anda    #NOT_RESET              ; force bit3=0, no matter what happens
f053 b7 14 03           	staa	LCD_RS
f056 32                 	pula
f057 39                         rts
                        *
f058                    lcd_line1:
f058 c6 10              	ldab    #16
f05a bd f0 4a           	jsr    	sel_inst		; select instruction
f05d 86 80                     	ldaa   	#$80     		; starting address for line1
f05f 20 07              	bra	line3
f061                    lcd_line2:
f061 c6 10              	ldab    #16
f063 bd f0 4a           	jsr    	sel_inst
f066 86 c0                     	ldaa   	#$C0     		; starting address for line2
f068 8d 22              line3: 	bsr    	wrt_byte
                        *
f06a bd f0 43                  	jsr    	sel_data
                        
                        * at entry, x must point to the begining of the message,
                        *           b = number of characters to be sent out
                        *
f06d                    msg_out:
f06d a6 00              	ldaa   	0,x
f06f bd f0 8c                  	jsr    	wrt_byte
f072 08                        	inx
f073 5a                        	decb
f074 26 f7                     	bne    	msg_out
f076 39                 	rts
                        *
                        *       @ enter, high nibble of Accu A=data to be sent out
                        *     		 low nibble of Accu A is ignored
                        *
f077                    wrt_nibble:
f077 84 f0                     	anda   	#$f0     		; mask out 4 low bits
f079 97 00                     	staa   	temp1 			; save high nibble
f07b 96 01                     	ldaa   	LCDimg    		; get LCD port image
f07d 84 0f                     	anda   	#$0f     		; need low 4 bits
f07f 9a 00                     	oraa   	temp1    		; add it with high nibble
f081 97 01                      staa   	LCDimg    		; save it
f083 84 f7                     	anda    #NOT_RESET              ; force bit3=0, no matter what happens
                        *      	                                ; to prevent system reset
f085 b7 14 03                  	staa   	LCD    			; output data to LCD port
f088 bd f0 bf                   jsr	enable_pulse
f08b 39                  	rts
                        *
                        *       @ enter, a=data to output
                        *
f08c                    wrt_byte:
f08c 3c                 	pshx
f08d 36                        	psha        			; save it tomporarily.
f08e 84 f0                     	anda   	#$f0     		; mask out 4 low bits.
f090 97 00                     	staa   	temp1 			; save nibble value.
f092 96 01                     	ldaa   	LCDimg    		; get LCD port image.
f094 84 0f                     	anda   	#$0f     		; need low 4 bits.
f096 9a 00                     	oraa   	temp1    		; add in low 4 bits.
f098 97 01                     	staa   	LCDimg    		; save it
f09a 84 f7                     	anda    #NOT_RESET              ; force bit3=0, no matter what happens
f09c b7 14 03                  	staa   	LCD    			; output data
f09f 8d 1e              	bsr	enable_pulse
                        
f0a1 32                 	pula
f0a2 48                  	asla            		; move low bits over.
f0a3 48                 	asla
f0a4 48                       	asla
f0a5 48                        	asla
f0a6 97 00                     	staa   	temp1			; store temporarily.
                        *
f0a8 96 01                     	ldaa   	LCDimg 			; get LCD port image.
f0aa 84 0f                     	anda   	#$0f   			; need low 4 bits.
f0ac 9a 00                     	oraa   	temp1  			; add in loiw 4 bits.
f0ae 97 01                     	staa   	LCDimg    		; save it
f0b0 84 f7                     	anda    #NOT_RESET              ; force bit3=0, no matter what happens
f0b2 b7 14 03           	staa   	LCD    			; output data
                        *
f0b5 8d 08              	bsr	enable_pulse
f0b7 ce 00 0f                   ldx     #d40us
f0ba bd f0 14             	jsr     del1
f0bd 38                         pulx
f0be 39                        	rts
                        *
f0bf                    enable_pulse:
                        *	bset	LCD_ENimg ENABLE	; ENABLE=high
f0bf 96 01              	ldaa	LCD_ENimg
f0c1 8a 02              	oraa	#ENABLE
f0c3 97 01              	staa	LCD_ENimg
f0c5 84 f7              	anda    #NOT_RESET              ; force bit3=0, no matter what happens
f0c7 b7 14 03           	staa	LCD_EN
                        *	bclr	LCD_ENimg ENABLE	; ENABLE=low
f0ca 96 01              	ldaa	LCD_ENimg
f0cc 84 fd              	anda	#NOT_ENABLE
f0ce 97 01              	staa	LCD_ENimg
f0d0 84 f7              	anda    #NOT_RESET              ; force bit3=0, no matter what happens
f0d2 b7 14 03           	staa	LCD_EN
f0d5 39                        	rts
                        *
f0d6 8e 8f ff           start:  lds	#STACK
f0d9 bd f0 03              	jsr	delay_10ms	; delay 20ms during power up
f0dc bd f0 03               	jsr	delay_10ms
f0df bd f0 1a               	jsr	lcd_ini		; initialize LCD
                                              	
f0e2 ce f0 f1           	ldx    	#MSG1		; MSG1 for line1, x points to MSG1
f0e5 bd f0 58                  	jsr	lcd_line1
                        *
f0e8 ce f1 01               	ldx    	#MSG2		; MSG2 for line2, x points to MSG2
f0eb bd f0 61                   jsr	lcd_line2
                        
f0ee 7e f0 ee           self:  	jmp     self
                        
f0f1 20 59 4f 55 20 44  MSG1:   FCC     " YOU DESERVE A  "
     45 53 45 52 56 45
     20 41 20 20
f101 20 20 42 52 45 41  MSG2:   FCC     "  BREAK TODAY   "
     4b 20 54 4f 44 41
     59 20 20 20
fffe                     	org     $FFFE
fffe f0 d6              	FDB     start
                               	end
                        
                        

Executed: Sat Dec 31 02:27:37 2005
Total cycles: 417, Total bytes: 275
Total errors: 0, Total warnings: 0
