Problem with lcd and ports.

For E-blocks user to discuss using E-blocks and programming for them.

Moderators: Benj, Mods

Post Reply
limbonic
Posts: 3
Joined: Tue Mar 19, 2013 10:19 am

Problem with lcd and ports.

Post by limbonic »

Hello,

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
Last edited by limbonic on Tue Mar 19, 2013 10:44 am, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Problem with lcd and ports.

Post by Benj »

Hello,

What device are you using? The assembler refers to a 16F88 which only has PortA and PortB.

limbonic
Posts: 3
Joined: Tue Mar 19, 2013 10:19 am

Re: Problem with lcd and ports.

Post by limbonic »

Sorry, i make a mistake and upload the wrong code. The eblocks that i buy has an 16F88 onboard and in this device i try PORTA. But i have also a PIC16F877a and with this PIC i try every other port. I changed the configuration bits of course and the include and list directive for the PIC16F877a, but why the the code doesn't work for 16f88 device?

The code for 16f877a:

Code: Select all


LIST P=16F877A
include "P16F877A.INC"
__CONFIG _RC_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF & _BODEN_ON & _LVP_OFF  & _CPD_OFF & _DEBUG_OFF;
ERRORLEVEL -302
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::      
PCL      EQU   H'02'      
STATUS   EQU   H'03'      
PORTA   EQU   H'05'      
TRISA   EQU   H'85'      
PORTB   EQU   H'06'      
TRISB   EQU   H'86'   
PORTC	equ		H'07'
TRISC	EQU		H'87'
PORTD	EQU		H'08'
TRISD	EQU		H'88'   
INTCON   EQU   H'0B'
ADCON1	EQU		H'9F'
 
         
LOOP   EQU   H'20'      ;loop counter 1 - general
LOOPA   EQU   H'21'      ;loop counter 2 - LCD use only
STORE   EQU   H'27'      ;general store
d1		equ		h'28'
d2		equ		h'29'
d3		equ		h'2a'
RSLINE   EQU   H'2F'      ;bit 4 RS line flag for LCD
           
   W   EQU   0      
    F   EQU   1      
            
   ORG   0x00      ; Reset vector
   nop
   GOTO   main      ; Goto start of program




main
	CALL	initialization_port
	CALL	initialization_lcd
	CALL	LCD_MESSAGE
	GOTO 	NOMORE

initialization_port
	BCF		STATUS,5
	BCF		STATUS,6
	CLRF 	PORTA
	CLRF	PORTB
	CLRF	PORTC
	CLRF	PORTD
	BSF		STATUS,5
	MOVLW	0x06
	MOVWF	ADCON1
	CLRF	TRISA
	CLRF	TRISB
	CLRF	TRISC
        BCF   STATUS,5         ; PAGE0
RETURN
	
     
            
initialization_lcd
   CALL   DELAY1     ;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   DELAY1      ;yes, perform second 1/5th sec delay
            ;to allow final LCD command to occur
            ;(it takes longer than the rest)
RETURN


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




LCD_MESSAGE              
   CLRF   LOOP      ;clear loop
   BSF   RSLINE,4      ;set RS for data send
msg1   
   MOVF   LOOP,W      ;get table address
   CALL   MESSAG      ;get message letter
   CALL   LCDOUT      ;show it
   INCF   LOOP,F      ;inc loop
   BTFSS   LOOP,4      ;has last LCD letter been sent?
   GOTO   msg1      ;no, so repeat for next one
return
	
            
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   PORTC      ;output the byte
   BSF   PORTC,5      ;set E line high
   BCF   PORTC,5      ;set E line low
   RETURN         
           

DELAY1
			;1499993 cycles
	movlw	0x0C
	movwf	d1
	movlw	0x46
	movwf	d2
	movlw	0x04
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return


MESSAG   
   ADDWF   PCL,F      
   RETLW   'h'      
   RETLW   'e'      
   RETLW   'l'      
   RETLW   'l'      
   RETLW   'o'      
   RETLW   ' '      
   RETLW   'w'      
   RETLW   'o'
   RETLW   'r'      
   RETLW   'l'      
   RETLW   'd'      
   RETLW   ' '      
   RETLW   ' '      
   RETLW   ' '   
   RETLW   ' '      
   RETLW   ' '   
 

NOMORE   GOTO   NOMORE      ;yes, so hold here ad infinitum!

   END         ;final line



limbonic
Posts: 3
Joined: Tue Mar 19, 2013 10:19 am

Re: Problem with lcd and ports.

Post by limbonic »

I try everything. I dont find what is going wrong. Anyone that can help me?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Problem with lcd and ports.

Post by Benj »

Hello,

The LCDs are sensitive to specific timings. As you are using your program in RC oscillator mode ensure that the oscillator switch on the EB006 is set to RC and Fast.

If this still isn't working then you may have to dig out the datasheet for your specific display and ensure all your timings are correct. Our Flowcode software is designed to help eliminate issues like this.

Post Reply