; Justice Unlimited Gadget Microcode
; (C) 2004 Nathan (Acorn) Pooley
;
; gout_par.inc
;
;@DOC@ code to interface to the display when using
;@DOC@ the parallel port
;
;
; functions for output to display - PARALLEL
;
;############################################
;############### DISABLE OUTPUT #############
;############################################
;
; turn off the display
;
output_disable:
bsf disab_light
btfss disab_display ; do not clear screen if already off
rcall putc_clr ; clear the display
bsf disab_display
setf TRISA ; PORTA all input
; (lower power)
return
;############################################
;############### ENABLE OUTPUT ##############
;############################################
;
; turn display on and initialize it
;
output_enable:
clrf PORTA ; PORTA all low
clrf TRISA ; PORTA output
bcf disab_display
;
; wait >30 msec (after display voltage applied) (according to spec)
;
movlw 250 ; 3*250 = 750 cyc = 91.5 msec
output_enable_wait1:
decfsz WREG
bra output_enable_wait1
;
; indicate that we will be using 4-bit I/O mode
;
movlw 0x22 ; data = 0x20
; bit 0-3 = 0x20 >> 4 = 0x02
; bit 4 = RS = 0 (control)
; bit 5 = E = 1
movwf PORTA ; write hi bits
nop
bcf PORTA,5 ; E=0 (latch in data)
;
; Send initializaton control code
;
; Function set = 001DNF00
; D = 0 (4 bit I/0 mode)
; N = 1 (2 line mode)
; F = 0 (5x8 dot characters)
movlw 0x28
rcall putc_ctrl
;
; wait for >=39 usec (each instruction takes 122 usec, so no need)
;
;
; send ON/OFF control code
;
; code = 00001DCB
; D = 1 (display on)
; C = 0 (cursor off)
; B = 0 (blinking square off)
;
movlw 0x0c
rcall putc_ctrl
;
; wait for >=39 usec (each instruction takes 122 usec, so no need)
;
;
; fall thru to clear screen (REQUIRED!!!)
;
;############################################
;############### CLEAR SCREEN ###############
;############################################
;
; clear the display screen
;
sc_clr:
putc_clr:
;
; send Display Clear control code
;
; code = 00000001
;
movlw 0x01
rcall putc_ctrl
;
; wait 1.53 msec for display clear
;
movlw 14 ; 3*14 = 42 cyc = 5.1 msec
output_enable_wait2:
decfsz WREG
bra output_enable_wait2
;
; send Entry Mode control code
;
; code = 000001DS
; D = 1 (increment mode)
; S = 0 (do not shift entire display)
;
movlw 0x06
rcall putc_ctrl
;
; send ON/OFF control code
;
; code = 00001DCB
; D = 1 (display on)
; C = 0 (cursor off)
; B = 0 (blinking square off)
;
movlw 0x0c
bra putc_ctrl
;############################################
;############### OUTPUT BACKSPACE ###########
;############################################
;
; output 1 backspace character
;
sc_bs:
putc_bs:
;
; send Cursor Shift control code
;
; code = 0001xx00
; xx = 00 (00 = shift cursor left
; 01 = shift cursor right
; 10 = shift display left
; 11 = shift display right)
;
movlw 0x10
bra putc_ctrl
;############################################
;############### OUTPUT CHARACTER ###########
;############################################
;
; send character in w (no check for special characters)
;
putc_raw:
movwf v_putc_save_w
bra putc_com
;
; send a character
; w = character to send
;
putc:
movwf v_putc_save_w
;
; is it a special character? (0x80 - 0x9f)
;
andlw 0xe0
addlw LOW -0x80
btfsc STATUS,Z
bra putc_special ; special character? (0x80-0x9f)
putc_com:
bsf PORTA,4 ; RS=1 (data - not control)
#if USE_PUTL
incf v_putc_cnt,f ; count characters
#endif
#if SIMULATE_SERIAL
movf v_putc_save_w,w
rcall sim_putc
#endif
#if PARANOID_PUTC
swapf v_putc_save_w,w ; hi bits first
bcf WREG,5 ; E=0 (bit 5)
bsf WREG,4 ; RS=1 (bit4)
movwf PORTA ; write hi bits
bsf PORTA,5 ; clock in data
movf v_putc_save_w,w ; lo bits next
bcf PORTA,5 ; latch in hi bits (E=0)
bcf WREG,5 ; E=0 (bit 5)
bsf WREG,4 ; RS=1 (bit4)
movwf PORTA ; write lo bits
bsf PORTA,5 ; clock in data
nop
bcf PORTA,5 ; latch in lo bits (E=0)
#else ; PARANOID_PUTC
swapf v_putc_save_w,w ; hi bits first
iorlw 0x30 ; E=1 (bit 5); RS=1 (bit4)
movwf PORTA ; write hi bits
movf v_putc_save_w,w ; lo bits next
bcf PORTA,5 ; latch in hi bits (E=0)
iorlw 0x30 ; E=1 (bit 5); RS=1 (bit4)
movwf PORTA ; write lo bits
nop
bcf PORTA,5 ; latch in lo bits (E=0)
#else
#endif ; PARANOID_PUTC
return
;
; put control character
; w = control byte to send
;
putc_ctrl:
bcf PORTA,4 ; RS=0 (control - not data)
movwf v_putc_save_w
#if SIMULATE_SERIAL
movlw 0xfe ; march control chars in buffer with 0xfe
rcall sim_putc
movf v_putc_save_w,w
rcall sim_putc
#endif
#if PARANOID_PUTC
swapf v_putc_save_w,w ; hi bits first
andlw 0x0f ; E=0 (bit 5) RS=0 (bit4)
movwf PORTA ; write hi bits
bsf PORTA,5 ; clock in data
movf v_putc_save_w,w ; lo bits next
bcf PORTA,5 ; latch in hi bits (E=0)
andlw 0x0f ; E=1 (bit 5) RS=0 (bit4)
movwf PORTA ; write lo bits
bsf PORTA,5 ; clock in data
nop
bcf PORTA,5 ; latch in lo bits (E=0)
#else ; PARANOID_PUTC
swapf v_putc_save_w,w ; hi bits first
iorlw 0x20 ; E=1 (bit 5)
bcf WREG,4 ; RS=0 (control data)
movwf PORTA ; write hi bits
movf v_putc_save_w,w ; lo bits next
bcf PORTA,5 ; latch in hi bits (E=0)
iorlw 0x20 ; E=1 (bit 5)
bcf WREG,4 ; RS=0 (control data)
movwf PORTA ; write lo bits
nop
bcf PORTA,5 ; latch in lo bits (E=0)
#endif ; PARANOID_PUTC
return
#if SIMULATE_SERIAL
sim_putc:
movff FSR0L, v_ss_save_fsr0l
movff FSR0H, v_ss_save_fsr0h
lfsr FSR0, BUF_SIMSERIAL
movff v_ssbuf_ptr,FSR0L
incf v_ssbuf_ptr,f
movwf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
setf INDF0
incf FSR0L,f
clrf INDF0
movff v_ss_save_fsr0l,FSR0L
movff v_ss_save_fsr0h,FSR0H
return
#endif
;############################################
;############### ENABLE VISIBLE CURSOR ######
;############################################
; turn on underscore cursor
;
sc_cursor_on:
putc_cursor_on:
;
; send ON/OFF control code
;
; code = 00001DCB
; D = 1 (display on)
; C = 1 (cursor off)
; B = 0 (blinking square off)
;
movlw 0x0e
bra putc_ctrl
; turn off blinking underscore cursor
;
sc_cursor_off:
putc_cursor_off:
;
; send ON/OFF control code
;
; code = 00001DCB
; D = 1 (display on)
; C = 0 (cursor off)
; B = 0 (blinkinf square off)
;
movlw 0x0c
bra putc_ctrl
;############################################
;############### POSITION CURSOR ############
;############################################
put_position_linestart:
;
; move cursor to start of line
; v_putl_linenum = xxxxxxx0 - line0
; xxxxxxx1 - line1
;
movlw 20
btfss v_putl_linenum,0
clrf WREG
; position cursor
; w should contain desired position (0-39)
;
put_position:
#if USE_PUTL
clrf v_putc_cnt
#endif
movwf v_cpos ; save curspor position
;
; send ON/OFF control code (this is to turn the cursor off)
;
; code = 00001DCB
; D = 1 (display on)
; C = 0 (cursor off)
; B = 0 (blinking square off)
;
movlw 0x0c
rcall putc_ctrl
;
; send Set DDRAM Address control code
;
; code = 1xxxxxxx
; xxxxxxx = display address
; 0x00 - 0x14 = line1
; 0x40 - 0x54 = line2
;
movf v_cpos,w
addlw LOW -20 ; first line?
btfss STATUS,N
addlw 0x40-20 ; line2 - correct address
addlw 20 ; add back the 20 we subtracted above
iorlw 0x80 ; set hi bit (so it is an Address Control Code)
bra putc_ctrl ; send it
;############################################
;############### BACKLIGHT ##################
;############################################
;
; this is called when button is held in for a while
;
light_toggle_held:
bcf v_bheld,7 ; clear held bit that caused this
;
; toggle light state
;
light_toggle:
btg b_light ; toggle light
;
; enable/disable light based on b_light bit
;
light_set:
btfss b_light
bra light_off
;
; turn light on (and remember that it is on)
;
sc_light_on:
light_stay_on:
bsf b_light
;
; turn light on (does not affect b_light bit)
;
lignt_on:
bcf disab_light
return
;
; set state of light to OFF
;
sc_light_off:
light_stay_off:
bcf b_light
;
; turn light off (does not affect b_light bit)
;
light_off:
bsf disab_light
return
;############################################
;############### DEFINE CHARACTER ###########
;############################################
sc_char_def:
rcall puts_nextc
rcall putc_ctrl ; send cgram address
movlw 8
movwf v_chdef_cnt
chardef_loop:
rcall puts_nextc
rcall putc
decfsz v_chdef_cnt
bra chardef_loop
;
; move cursor to start of line
;
bra put_position_linestart
|
This file Copyright (C) 2004 by Nathan (Acorn) Pooley
Go to DRUID Development page
Go to DRUID page
Go to JU Gadgets page
Go to Justice Unlimited homepage
Go to Acorn's personal webpage
Contact Acorn
See comments from others
Post your own comments
File created by do_doc at Wed Aug 4 17:55:21 2004