from a 16f628 to a pic18f1230 lcd code.

Status
Not open for further replies.

tracidfish

New Member
Hi
I am trying to drive an LCD in 4 bit mode using a pic18f1320.

I am satisifed that my hardware is correct, but I cannot get it to work. All I get is the balck squares. I have had a similar piece of code working on a pic 16 but would like to use in a pic 18.
I am trying to use an internal oscilator with no clock out and no mclr.

Can any one see where I have gone wrong?

thanks
Charlie


Code:
        include <P18F1320.INC>

;******************************************************************************
;Configuration bits

;      __CONFIG    _CONFIG1H, _IESO_OFF_1H & _FSCMEN_OFF_1H & _INTIO2_OSC_1H
;      __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_20_2L
      __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_32_2H                
      __CONFIG    _CONFIG3H, _MCLRE_OFF_3H
;      __CONFIG    _CONFIG4L, _BKBUG_OFF_4L & _LVP_OFF_4L & _STVR_OFF_4L
      __CONFIG    _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
      __CONFIG    _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
      __CONFIG    _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
      __CONFIG    _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
      __CONFIG    _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
      __CONFIG    _CONFIG7H, _EBTRB_OFF_7H

;******************************************************************************


        
		cblock	0x80			;start of general purpose registers
			count			;used in looping routines
			count1			;used in delay routine
			counta			;used in delay routine
			countb			;used in delay routine
			tmp1			;temporary storage
			tmp2
			tmp3
			templcd			;temp store for 4 bit mode
			templcd2
			offsetL			;table registers
			offsetH
			offsetL1		
			offsetH1
			seconds
			minutes
			hours						
				
		endc

LCD_PORT	Equ	PORTA
LCD_TRIS	Equ	TRISA
LCD_RS		Equ	0x04			;LCD handshake lines
LCD_RW		Equ	0x06
LCD_E		Equ	0x07



;****************************************************************************
;Reset Vector
;****************************************************************************
ResetVector     CODE    0x00
	
;Initialize I/O pins
        movlw   B'01110000'          ;Select 8MHz frequency  (B'01110000')PAGE 19
        movwf   OSCCON				 ;Select 4MHz frequency  (B'01100000')	

; ---------------- 
; INITIALIZE PORTS 
; ---------------- 
	

SetPorts	
		movlw	0x00			;make all pins outputs
		movwf	LCD_TRIS

		call	Delay100		;wait for LCD to settle
		call	Delay100		;wait for LCD to sett


		call	LCD_Init		;setup LCD



;****************************************************************************
;WELCOM
;****************************************************************************               

messgae
	
	call	LCD_Clr	
	

	call	LCD_Line1
	movlw	'W'
	call	LCD_Char
	movlw	'E'
	call	LCD_Char
	movlw	'L'
	call	LCD_Char
	movlw	'C'
	call	LCD_Char
	movlw	'O'
	call	LCD_Char
	movlw	'E'
	call	LCD_Char
	movlw	'.'
	call	LCD_Char
	movlw	'T'
	call	LCD_Char
	movlw	'O'
	call	LCD_Char

	call	LCD_Line2
	movlw	'D'
	call	LCD_Char
	movlw	'I'
	call	LCD_Char
	movlw	'V'
	call	LCD_Char
	movlw	'E'
	call	LCD_Char
	movlw	'.'
	call	LCD_Char
	movlw	'B'
	call	LCD_Char
	movlw	'U'
	call	LCD_Char
	movlw	'D'
	call	LCD_Char
	movlw	'Y'
	call	LCD_Char
	movlw	'Y'
	call	LCD_Char
	call	Delay255
	call	Delay255
	call	Delay255
	call	Delay255

goto messgae

;Initialise LCD
LCD_Init	movlw	0x20			;Set 4 bit mode
		call	LCD_Cmd

		movlw	0x28			;Set display shift
		call	LCD_Cmd

		movlw	0x06			;Set display character mode
		call	LCD_Cmd

		movlw	0x0d			;Set display on/off and cursor command
		call	LCD_Cmd

		call	LCD_Clr			;clear display

		retlw	0x00


; command set routine
LCD_Cmd		movwf	templcd
		swapf	templcd,	w	;send upper nibble
		andlw	0x0f			;clear upper 4 bits of W
		movwf	LCD_PORT
		bcf	LCD_PORT, LCD_RS	;RS line to 0
		call	Pulse_e			;Pulse the E line high

		movf	templcd,	w	;send lower nibble
		andlw	0x0f			;clear upper 4 bits of W
		movwf	LCD_PORT
		bcf	LCD_PORT, LCD_RS	;RS line to 0
		call	Pulse_e			;Pulse the E line high
		call 	Delay5
		retlw	0x00

LCD_CharD	addlw	0x30
LCD_Char	movwf	templcd
		swapf	templcd,	w	;send upper nibble
		andlw	0x0f			;clear upper 4 bits of W
		movwf	LCD_PORT
		bsf	LCD_PORT, LCD_RS	;RS line to 1
		call	Pulse_e			;Pulse the E line high
		movf	templcd,	w	;send lower nibble
		andlw	0x0f			;clear upper 4 bits of W
		movwf	LCD_PORT
		bsf	LCD_PORT, LCD_RS	;RS line to 1
		call	Pulse_e			;Pulse the E line high
		call 	Delay5
		retlw	0x00

LCD_Line1	movlw	0x80			;move to 1st row, first column
		call	LCD_Cmd
		retlw	0x00

LCD_Line2	movlw	0xc0			;move to 2nd row, first column
		call	LCD_Cmd
		retlw	0x00

LCD_Line1W	addlw	0x80			;move to 1st row, column W
		call	LCD_Cmd
		retlw	0x00

LCD_Line2W	addlw	0xc0			;move to 2nd row, column W
		call	LCD_Cmd
		retlw	0x00

LCD_CurOn	movlw	0x0d			;Set display on/off and cursor command
		call	LCD_Cmd
		retlw	0x00

LCD_CurOff	movlw	0x0c			;Set display on/off and cursor command
		call	LCD_Cmd
		retlw	0x00

LCD_Clr		movlw	0x01			;Clear display
		call	LCD_Cmd
		retlw	0x00


Delay255	movlw	0xff		;delay 255 mS
		goto	d0
Delay100	movlw	d'100'		;delay 100mS
		goto	d0
Delay50		movlw	d'50'		;delay 50mS
		goto	d0
Delay20		movlw	d'20'		;delay 20mS
		goto	d0
Delay5		movlw	0x05		;delay 5.000 ms (4 MHz clock)
d0		movwf	count1
d1		movlw	0xC7			;delay 1mS
		movwf	counta
		movlw	0x01
		movwf	countb
Delay_0
		decfsz	counta, f
		goto	$+2
		decfsz	countb, f
		goto	Delay_0

		decfsz	count1	,f
		goto	d1
		retlw	0x00

Pulse_e		bsf	LCD_PORT, LCD_E
		nop
		bcf	LCD_PORT, LCD_E
		retlw	0x00




	END
 
Last edited:
You don't appear to make portA digital. Try writing 0x7f to ADCON1.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…