I use this code from PICmicros cd to interface an LCD. The code is written for PORTB but i want to change to PORTC. I make the suitable changes like initialiase PORTC in the start for output etc. but the code doesn't work. I also try all the other ports with no success, only in PORTB is working and the lcd shows tha message. Does anyone knows what i am making wrong?
the code:
Code: Select all
; TUTA29.ASM 27SEP07
; illustrating use of Timer and LCD set up
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Configuration data
; PICmicro MCU type: 16F88
; Oscillator: XTAL mode, FAST, VR1 - your choice of setting
; LCD display: on
; 7-segment display: off
; Version 3 board settings: J14 links: Digital
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
; The following lines embed configuration data into the PICmicro
LIST P=16F88
__CONFIG H'2007', H'3F6A' ; HS mode
__CONFIG H'2008', H'3FFC' ; Clock Fail-Safe disabled
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#DEFINE PAGE0 BCF STATUS,5
#DEFINE PAGE1 BSF STATUS,5
OPSHUN EQU H'81'
PCL EQU H'02'
STATUS EQU H'03'
PORTA EQU H'05'
TRISA EQU H'85'
PORTB EQU H'06'
PORTC EQU H'07'
TRISB EQU H'86'
TRISC EQU H'87'
INTCON EQU H'0B'
LOOP EQU H'20' ;loop counter 1 - general
LOOPA EQU H'21' ;loop counter 2 - LCD use only
CLKCNT EQU H'22' ;125 secs counter
STORE EQU H'27' ;general store
RSLINE EQU H'2F' ;bit 4 RS line flag for LCD
W EQU 0
F EQU 1
ORG 0 ; Reset vector
GOTO 5 ; Goto start of program
ORG 4 ; Interrupt vector
GOTO 5 ; Goto start of program
ORG 5 ; Start of program memory
CLRF PORTA
CLRF PORTB
PAGE1 ; PAGE1
CLRF H'9B' ; Clear the ANSEL register
CLRF TRISA ;Port A0-A4 as output
CLRF TRISB ;Port B0-B7 as output
MOVLW B'00000110' ;set timer ratio 1:128
MOVWF OPSHUN
PAGE0 ; PAGE0
GOTO SETUP ;bypass table
TABLCD ADDWF PCL,F ;LCD initialisation table
RETLW B'00110011' ;initialise lcd - first byte
RETLW B'00110011' ;2nd byte (repeat of first)
RETLW B'00110010' ;set for 4-bit operation
RETLW B'00101100' ;set for 2 lines
RETLW B'00000110' ;set entry mode to increment each address
RETLW B'00001100' ;set display on, cursor off, blink off
RETLW B'00000001' ;clear display
RETLW B'00000010' ;return home, cursor & RAM to zero
;end initialisation table
MESSAG ADDWF PCL,F
RETLW 'G'
RETLW 'R'
RETLW 'E'
RETLW 'E'
RETLW 'T'
RETLW 'I'
RETLW 'N'
RETLW 'G'
SETUP CALL PAUSIT ;perform first 1/5th sec delay
LCDSET CLRF LOOP ;clr LCD set-up loop
CLRF RSLINE ;clear RS line for instruction send
LCDST2 MOVF LOOP,W ;get table address
CALL TABLCD ;get set-up instruction
CALL LCDOUT ;perform it
INCF LOOP,F ;inc loop
BTFSS LOOP,3 ;has last LCD set-up instruction now been done?
GOTO LCDST2 ;no
CALL PAUSIT ;yes, perform second 1/5th sec delay
;to allow final LCD command to occur
;(it takes longer than the rest)
LCDMSG CLRF LOOP ;clear loop
BSF RSLINE,4 ;set RS for data send
LCDMS2 MOVF LOOP,W ;get table address
CALL MESSAG ;get message letter
CALL LCDOUT ;show it
INCF LOOP,F ;inc loop
BTFSS LOOP,3 ;has last LCD letter been sent?
GOTO LCDMS2 ;no, so repeat for next one
NOMORE GOTO NOMORE ;yes, so hold here ad infinitum!
LCDOUT MOVWF STORE ;temp store data
MOVLW D'250' ;set minimum time between sending full bytes to
MOVWF LOOPA ;LCD - value of 250 seems OK for this prog with
DELAY DECFSZ LOOPA,F ;XTAL clk of upto 20MHz
GOTO DELAY ;keep decrementing LOOPA until zero
CALL SENDIT ;send MSB
CALL SENDIT ;send LSB
RETURN
SENDIT SWAPF STORE,F ;swap data nibbles
MOVF STORE,W ;get data byte
ANDLW H'0F' ;get nibble from byte (LSB)
IORWF RSLINE,W ;OR the RS bit
MOVWF PORTA ;output the byte
BSF PORTA,5 ;set E line high
BCF PORTA,5 ;set E line low
RETURN
PAUSIT MOVLW D'30' ;set delay counter to 30
MOVWF CLKCNT ;(for 1/150th sec x 30)
CLRF INTCON ;clear interupt flag
PAUSE ;initial 1/5th sec wait before setting up LCD
BTFSS INTCON,2 ;has a timer time-out been detected?
GOTO PAUSE ;no
BCF INTCON,2 ;yes
DECFSZ CLKCNT,F ;dec counter, is it zero?
GOTO PAUSE ;no
RETURN ;yes
END ;final line