Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Defining LCD data lines

Status
Not open for further replies.

bryan1

Well-Known Member
Hiya guy's,
I'm having a heap of trouble working out how to define portB pins 4-7 as lcd data lines. I'm using Nigel's tutorial the 16 bit counter one for testing it out. Now when i use rb0-4 as the data it works fine but for the life of me no matter what I try all I get is blocks on the first line. The main reason I want to use the higher pins for the data is I want rb0 free to use for the interrupt feature. I'm using the 16f876a with a bootloader so changing the code is a breeze. I'll really appreciate some help with this.

Cheers Bryan ;)
 
bryan1 said:
Hiya guy's,
I'm having a heap of trouble working out how to define portB pins 4-7 as lcd data lines. I'm using Nigel's tutorial the 16 bit counter one for testing it out. Now when i use rb0-4 as the data it works fine but for the life of me no matter what I try all I get is blocks on the first line. The main reason I want to use the higher pins for the data is I want rb0 free to use for the interrupt feature. I'm using the 16f876a with a bootloader so changing the code is a breeze. I'll really appreciate some help with this.

Cheers Bryan ;)

G'day Bryan,
Can you post the defines and header of your version?

Eric
 
Hiya Eric,
Below is how i've defined the lcd and now i've tried swapping the data lines ie: the 4 port lines swapped and I still get the blasted solid blocks.


Code:
LCD_PORT Equ PORTB
LCD_TRIS Equ TRISB
LCD_RS Equ 0x01   
LCD_RW Equ 0x02
LCD_E Equ 0x03
 
Hi,
the routines used to write to an LCD module using the upper nibble of a port are different to those that use the lower nibble. could you post you code.
 
hi Bryan,
As Nigel points out the LCD WR subrs are written to suit the lower nibble.

I would suggest you try the free/trial version of the PIC Simulator from
www.oshonsoft.com it supports many PIC's including the 16F876A.


Eric
 
bryan1 said:
I'm having a heap of trouble working out how to define portB pins 4-7 as lcd data lines.

Few changes are required. When you send a command to the LCD, you have to invert the order in which the nibbles are sent. Always send the 4 most significant bits.
Also, in your case be sure that you don't change other bits of PORTB.
 
Last edited:
Can you do this?
Code:
LCD_Cmd		movwf	templcd
		andlw	0xf0			
		movwf	LCD_PORT
		bcf	LCD_PORT, LCD_RS	;RS line to 0
		call	Pulse_e			;Pulse the E line high

		swapf	templcd,	w
		andlw	0xf0	
		movwf	LCD_PORT
		bcf	LCD_PORT, LCD_RS	;RS line to 0
		call	Pulse_e			;Pulse the E line high
		call 	Delay5
		retlw	0x00
See whether this helping you or not (maybe not :D)
I am learning from Nigel's site too, and I use the lower bits of the port.
 
hi Bryan,

A test for your LCD, using PORTB, with PORTB.0 reserved for your Intr.
Runs OK on my Sim, havn't got a 16F876A on the bench to try.
Converted one of my 16F877 asm's.

Lets know how it goes.

Eric
 
Last edited:
Hiya Guy's,
Firstly thank you Eric for that asm file that file has opened my eyes up to some different ways on programming. Anyway I've been playing around working out how to swap the nibbles and finally got there.:D Below is a snippet of what I did for anyone that wants to use the lcd as I am doing. To cut down on the program I just used Nigel's first tutorial .

Code:
;LCD text demo - 4 bit mode
;Nigel Goodwin 2002
 LIST p=16F876a;tell assembler what chip we are using
 include "P16F876a.inc"  ;include the defaults for the chip
 ERRORLEVEL 0, -302 ;suppress bank selection messages
 __config 0x3F31   ;sets the configuration settings (oscillator type etc.)
 
 
  cblock 0x20   ;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
   templcd   ;temp store for 4 bit mode
   templcd2 
  endc
LCD_PORT Equ PORTB
LCD_TRIS Equ TRISB
LCD_RS  Equ 0x01   ;LCD handshake lines
LCD_RW  Equ 0x02
LCD_E  Equ 0x03
  org 0x0004
  goto  Initialise
 
 
 banksel ADCON1
Initialise  movlw 0x06
    movwf ADCON1   
    clrf count
    clrf PORTA
    clrf PORTB
    clrf PORTC
 
SetPorts bsf  STATUS,  RP0 ;select bank 1
  movlw 0x00   ;make all pins outputs
  movwf LCD_TRIS
  bcf  STATUS,  RP0 ;select bank 0
  call Delay100  ;wait for LCD to settle
 
  call LCD_Init  ;setup LCD
 
  clrf count   ;set counter register to zero
Message  movf count, w  ;put counter value in W
  call Text   ;get a character from the text table
  xorlw 0x00   ;is it a zero?
  btfsc STATUS, Z
  goto NextMessage
  call LCD_Char
  call Delay255
  incf count, f
  goto Message
NextMessage call LCD_Line2  ;move to 2nd row, first column
  clrf count   ;set counter register to zero
Message2 movf count, w  ;put counter value in W
  call Text2   ;get a character from the text table
  xorlw 0x00   ;is it a zero?
  btfsc STATUS, Z
  goto EndMessage
  call LCD_Char
  incf count, f
  goto Message2
EndMessage 
 
Stop  goto Stop   ;endless loop
 
 
;Subroutines and text tables
;LCD routines
;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 ( [U]commented out this line[/U])
  andlw 0xf0   ;                                 ([U]swapped 0x0f with 0xf0[/U])
  movwf LCD_PORT
  bcf LCD_PORT, LCD_RS ;RS line to 0
  call Pulse_e   ;Pulse the E line high
  swapf templcd, w ;                        ([U]inserted swapf here[/U])
  andlw 0xf0   ;                               ([U]swapped 0x0f with 0xf0[/U])
  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  ;                         ( [U]commented out this line[/U])
  andlw 0xf0   ;                                 ([U]swapped 0x0f with 0xf0[/U])
  movwf LCD_PORT
  bsf LCD_PORT, LCD_RS ;RS line to 1
  call Pulse_e   ;Pulse the E line high
  swapf templcd, w ;                          ([U]inserted swapf here[/U])
  andlw 0xf0   ;                                 ([U]swapped 0x0f with 0xf0[/U])
  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
LCD_HEX  movwf tmp1
  ;swapf tmp1, w
  andlw 0x0f
  call HEX_Table
  call LCD_Char
  swapf tmp1, w
  andlw 0x0f
  call HEX_Table
  call LCD_Char
  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 of LCD routines
HEX_Table   ADDWF   PCL       , f
             RETLW   0x30
             RETLW   0x31
             RETLW   0x32
             RETLW   0x33
             RETLW   0x34
             RETLW   0x35
             RETLW   0x36
             RETLW   0x37
             RETLW   0x38
             RETLW   0x39
             RETLW   0x41
             RETLW   0x42
             RETLW   0x43
             RETLW   0x44
             RETLW   0x45
             RETLW   0x46
 
Text  addwf PCL, f
  retlw 'H'
  retlw 'e'
  retlw 'l'
  retlw 'l'
  retlw 'o'
  retlw 0x00
Text2  ADDWF   PCL, f
             RETLW   'R'
             RETLW   'e'
             RETLW   'a'
             RETLW   'd'
             RETLW   'y'
             RETLW   '.'
             RETLW   '.'
             RETLW   '.'
             RETLW   0x00
 
  end


And viola it worked :D :D :D

Cheers Bryan ;)
 
Status
Not open for further replies.

Latest threads

Back
Top