AS11, an absolute assembler for Motorola MCU's, version 1.2e

                        *
                        * Lcd2.asm ---- New 16X2 LCD sample program for FOX11 board
                        *		with BUFFALO 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
                        *
d000                    	org	$D000
d000 7e d0 d6           	jmp	start
                        
d003                    delay_10ms:
d003 01                 	nop
d004 3c                 d10ms:  pshx
d005 ce 06 86           	ldx     #TEN_MS
d008 8d 0a                	bsr	del1
d00a 38                   	pulx
d00b 39                 	rts
d00c 3c                 d5ms:   pshx
d00d ce 03 43           	ldx     #FIVE_MS
d010 8d 02                	bsr	del1
d012 38                 	pulx
d013 39                 	rts
d014 09                 del1:	dex
d015 08                 	inx
d016 09                 	dex
d017 26 fb              	bne	del1
d019 39                 	rts
                        *
d01a                    lcd_ini:
d01a 4f                 	clra
d01b 97 01              	staa	pfimg
d01d b7 14 03           	staa	PORTF
d020 ce d0 36                  	ldx	#inidsp   	; point to init. codes.
d023 bd d0 4a                  	jsr    	sel_inst
d026 e6 00                     	ldab   	0,x
d028 08                        	inx
d029 a6 00              onext:	ldaa   	0,x
d02b bd d0 77                  	jsr    	wrt_nibble   	; initiate write pulse.
d02e 08                        	inx
d02f bd d0 0c           	jsr	d5ms
d032 5a                        	decb
d033 26 f4                     	bne    	onext
d035 39                    	rts
d036 0c                 inidsp: fcb	12		; number of high nibbles
                        *				; use high nibbles only, low nibbles are ignored
d037 30                 	fcb	$30		; 1st reset code, must delay 4.1ms after sending
d038 30                         fcb	$30		; 2nd reste code, must delay 100us after sending
                        
                        ; all following 10 nibbles must be delay 40us each after sending
d039 30                 	fcb     $30             ; 3rd reset code,
d03a 20                 	fcb	$20		; 4th reste code,
d03b 20                         fcb	$20   		; 4 bit mode, 2 line, 5X7 dot
d03c 80                 	fcb	$80   		; 4 bit mode, 2 line, 5X7 dot
d03d 00                         fcb	$00		; cursor increment, disable display shift
d03e 60                 	fcb	$60		; cursor increment, disable display shift
d03f 00                         fcb	$00		; display on, cursor off, no blinking
d040 c0                 	fcb	$C0		; display on, cursor off, no blinking
d041 00                 	fcb	$00		; clear display memory, set cursor to home pos
d042 10                 	fcb	$10		; clear display memory, set cursor to home pos
                        *
d043                    sel_data:
d043 36                 	psha
                        *	bset	LCD_RSimg REG_SEL	; select instruction
d044 96 01              	ldaa	LCD_RSimg
d046 8a 01              	oraa	#REG_SEL
d048 20 05              	bra	sel_i
d04a                    sel_inst:
d04a 36                 	psha
                        *	bclr	LCD_RSimg REG_SEL	; select instruction
d04b 96 01              	ldaa	LCD_RSimg
d04d 84 fe              	anda	#NOT_REG_SEL
d04f 97 01              sel_i:	staa	LCD_RSimg
d051 84 f7              	anda    #NOT_RESET              ; force bit3=0, no matter what happens
d053 b7 14 03           	staa	LCD_RS
d056 32                 	pula
d057 39                         rts
                        *
d058                    lcd_line1:
d058 c6 10              	ldab    #16
d05a bd d0 4a           	jsr    	sel_inst		; select instruction
d05d 86 80                     	ldaa   	#$80     		; starting address for line1
d05f 20 07              	bra	line3
d061                    lcd_line2:
d061 c6 10              	ldab    #16
d063 bd d0 4a           	jsr    	sel_inst
d066 86 c0                     	ldaa   	#$C0     		; starting address for line2
d068 8d 22              line3: 	bsr    	wrt_byte
                        *
d06a bd d0 43                  	jsr    	sel_data
                        
                        * at entry, x must point to the begining of the message,
                        *           b = number of characters to be sent out
                        *
d06d                    msg_out:
d06d a6 00              	ldaa   	0,x
d06f bd d0 8c                  	jsr    	wrt_byte
d072 08                        	inx
d073 5a                        	decb
d074 26 f7                     	bne    	msg_out
d076 39                 	rts
                        *
                        *       @ enter, high nibble of Accu A=data to be sent out
                        *     		 low nibble of Accu A is ignored
                        *
d077                    wrt_nibble:
d077 84 f0                     	anda   	#$f0     		; mask out 4 low bits
d079 97 00                     	staa   	temp1 			; save high nibble
d07b 96 01                     	ldaa   	LCDimg    		; get LCD port image
d07d 84 0f                     	anda   	#$0f     		; need low 4 bits
d07f 9a 00                     	oraa   	temp1    		; add it with high nibble
d081 97 01                      staa   	LCDimg    		; save it
d083 84 f7                     	anda    #NOT_RESET              ; force bit3=0, no matter what happens
                        *      	                                ; to prevent system reset
d085 b7 14 03                  	staa   	LCD    			; output data to LCD port
d088 bd d0 bf                   jsr	enable_pulse
d08b 39                  	rts
                        *
                        *       @ enter, a=data to output
                        *
d08c                    wrt_byte:
d08c 3c                 	pshx
d08d 36                        	psha        			; save it tomporarily.
d08e 84 f0                     	anda   	#$f0     		; mask out 4 low bits.
d090 97 00                     	staa   	temp1 			; save nibble value.
d092 96 01                     	ldaa   	LCDimg    		; get LCD port image.
d094 84 0f                     	anda   	#$0f     		; need low 4 bits.
d096 9a 00                     	oraa   	temp1    		; add in low 4 bits.
d098 97 01                     	staa   	LCDimg    		; save it
d09a 84 f7                     	anda    #NOT_RESET              ; force bit3=0, no matter what happens
d09c b7 14 03                  	staa   	LCD    			; output data
d09f 8d 1e              	bsr	enable_pulse
                        
d0a1 32                 	pula
d0a2 48                  	asla            		; move low bits over.
d0a3 48                 	asla
d0a4 48                       	asla
d0a5 48                        	asla
d0a6 97 00                     	staa   	temp1			; store temporarily.
                        *
d0a8 96 01                     	ldaa   	LCDimg 			; get LCD port image.
d0aa 84 0f                     	anda   	#$0f   			; need low 4 bits.
d0ac 9a 00                     	oraa   	temp1  			; add in loiw 4 bits.
d0ae 97 01                     	staa   	LCDimg    		; save it
d0b0 84 f7                     	anda    #NOT_RESET              ; force bit3=0, no matter what happens
d0b2 b7 14 03           	staa   	LCD    			; output data
                        *
d0b5 8d 08              	bsr	enable_pulse
d0b7 ce 00 0f                   ldx     #d40us
d0ba bd d0 14             	jsr     del1
d0bd 38                         pulx
d0be 39                        	rts
                        *
d0bf                    enable_pulse:
                        *	bset	LCD_ENimg ENABLE	; ENABLE=high
d0bf 96 01              	ldaa	LCD_ENimg
d0c1 8a 02              	oraa	#ENABLE
d0c3 97 01              	staa	LCD_ENimg
d0c5 84 f7              	anda    #NOT_RESET              ; force bit3=0, no matter what happens
d0c7 b7 14 03           	staa	LCD_EN
                        *	bclr	LCD_ENimg ENABLE	; ENABLE=low
d0ca 96 01              	ldaa	LCD_ENimg
d0cc 84 fd              	anda	#NOT_ENABLE
d0ce 97 01              	staa	LCD_ENimg
d0d0 84 f7              	anda    #NOT_RESET              ; force bit3=0, no matter what happens
d0d2 b7 14 03           	staa	LCD_EN
d0d5 39                        	rts
                        *
d0d6 8e 8f ff           start:  lds	#STACK
d0d9 bd d0 03              	jsr	delay_10ms	; delay 20ms during power up
d0dc bd d0 03               	jsr	delay_10ms
d0df bd d0 1a               	jsr	lcd_ini		; initialize LCD
                                              	
d0e2 ce d0 ef           	ldx    	#MSG1		; MSG1 for line1, x points to MSG1
d0e5 bd d0 58                  	jsr	lcd_line1
                        *
d0e8 ce d0 ff               	ldx    	#MSG2		; MSG2 for line2, x points to MSG2
d0eb bd d0 61                   jsr	lcd_line2
d0ee 3f                   	swi                     ; go back to buffalo monitor
                        
                        
d0ef 20 59 4f 55 20 44  MSG1:   FCC     " YOU DESERVE A  "
     45 53 45 52 56 45
     20 41 20 20
d0ff 20 20 42 52 45 41  MSG2:   FCC     "  BREAK TODAY   "
     4b 20 54 4f 44 41
     59 20 20 20
                        
                               	end
                        
                        

Executed: Sat Dec 31 02:25:36 2005
Total cycles: 428, Total bytes: 271
Total errors: 0, Total warnings: 0
