LCD- Problem

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, i have used the ATMEGA32 chip to control a 1-line 16 character LCD. The problem is that only the first 8 characters work. The LCD spec is at http://www.everbouquet.com.tw/Ge....

And the code is attatched, any advice would be greatly apreciated.

Thanks

Daniel Roberts

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

daniel2335 wrote:
Hello, i have used the ATMEGA32 chip to control a 1-line 16 character LCD. The problem is that only the first 8 characters work. The LCD spec is at http://www.everbouquet.com.tw/Ge....

And the code is attatched, any advice would be greatly apreciated.

Thanks

Daniel Roberts

How about, who makes the LCD? What chip set does it use? And, as I'm just too lazt to deal with the process of changing the file extension from asm to txt, how about posting the code for the initialization and pertenent driver functions.

In addition, there is a request for help with LCDs about twice a week. so, every possible angle has surely been covered...

Did you do a search of the forum on the subject?

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The LCD is made by everbouquet and it uses the HD44780U chip set, i have done a brief search of the forums yes.

Code is:

.include "m32def.inc"

.def temp =r16

.def Data =r17
.def lcdstat =r19
.def choice =r22

;-------delay items----
.def counter =r20
.def timeout =r21
.equ Limit =250

;---control pins-----
.equ RSpin =PA5
.equ RWpin =PA6
.equ Epin =PA7

.org $000 ;Interrupt vectors
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;
rjmp RESET ;

RESET: ldi temp, low(RAMEND) ;Set the stack
out spl, temp ;
ldi temp, high(RAMEND);
out sph, temp ;

cli ;Disable global interrupts.

ldi temp, $ff ;Set portB to output
out DDRB, temp ;

ldi temp, (1<<RSpin)|(1<<RWpin)|(1<<Epin) ;set PA0 -PA2 outputs.
out DDRA, temp ;

rcall LCD_init ;initialise the display

rjmp MAIN ;go to main code block

;------------------------------------------------------------------------------------------------
;---------------------LCD CODE PORTB = DATA, PA5=RS , PA6=RW , PA7=E ---------------------------
;------------------------------------------------------------------------------------------------

;---------------- 1000 clock ticks at 8Mhz = 125us ----------------------------------------------

Delay_Short:clr counter ;Clear the counter
cnt: inc counter ;Increment counter
cpi counter, Limit ;Compare with limit
brne cnt ;
ret ;

;---------------------------delays for timeout value X 125us-------------------------------------

Delay_Long: cpi timeout,$00 ;
breq return ;check if anymore cycles are remaining
rcall delay_short ;delay for 125us
dec timeout ;reduce number of cycles remaining
rjmp delay_long ;
return: ret ;return

;-------------------------erase all previous setting and display---------------------------------

LCD_clr_disp: ;rcall LCD_idle_wait ; wait till not busy

ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;e=0,rw=0, rs=0
out PortA, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(1<<Epin) ;set Enable
out PortA, temp ;

ldi temp, (1<<PB0) ;clear display command
out PortB, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;clr Enable
out PortA, temp ;

ret ;

;---------------------set display to 1 line,7X5 matrix with 8 bit data input---------------------

LCD_Funct_set: ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;e=0,rw=0, rs=0
out PortA, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(1<<Epin) ;set Enable
out PortA, temp ;

ldi temp, (1<<PB5)|(1<<PB4)|(0<<PB3)|(0<<PB2) ;set 1-line, 7x5 matrix, data input 8-bits
out PortB, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;clr Enable
out PortA, temp ;

ret ;

;------------------turn the display on, cursor on and blinking mode off--------------------------

LCD_on: ;rcall LCD_idle_wait ; wait till not busy

ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;e=0,rw=0, rs=0
out PortA, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(1<<Epin) ;set Enable
out PortA, temp ;

ldi temp, (1<<PB3)|(1<<PB2)|(1<<PB1)|(0<<PB0) ;set display on, cursor on, blink off
out PortB, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;clr Enable
out PortA, temp ;

ret ;

;------------------turn the display off, cursor off and blinking mode off--------------------------

LCD_off: ;rcall LCD_idle_wait ; wait till not busy

ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;e=0,rw=0, rs=0
out PortA, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(1<<Epin) ;set Enable
out PortA, temp ;

ldi temp, (1<<PB3)|(0<<PB2)|(0<<PB1)|(0<<PB0);set display off, cursor off, blink off
out PortB, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;clr Enable
out PortA, temp ;

ret ;

;------------------------------- Waiting until the lcd isnt busy---------------------------------

LCD_idle_wait: clr temp ;clear port before turning to input
out PortB,temp ;

ldi temp,$00 ; set data port to input;
out DDRB,temp ;

query: ldi temp,(0<<RSpin)|(1<<RWpin)|(0<<Epin) ;e=0,rw=1, rs=0
out PortA, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(1<<RWpin)|(1<<Epin) ;set to enable
out PortA, temp ;

nop ;125ns delay

in lcdstat,PINB ; get response from lcd

ldi temp,(0<<RSpin)|(1<<RWpin)|(0<<Epin) ;clear enable
out PortA, temp ;

sbrc lcdstat, 7 ;check the busy flag
rjmp query ;loop until not busy

ldi temp,$FF ;set data port back to output
out DDRB,temp ;

ret ;

;-------------------------- outputs character in R0 register ---------------------------------

LCD_Output: rcall LCD_idle_wait ;wait till not busy

ldi temp,(1<<RSpin)|(0<<RWpin)|(0<<Epin) ;e=0,rw=0, rs=1
out PortA, temp ;

nop ;125ns delay

ldi temp,(1<<RSpin)|(0<<RWpin)|(1<<Epin) ;set Enable
out PortA, temp ;

mov temp, r0 ;load r0 into temp
out PortB, temp ;output the char

nop ;125ns delay

ldi temp,(1<<RSpin)|(0<<RWpin)|(0<<Epin) ;clr Enable
out PortA, temp ;

ret ;

;------------------------------------ sets entry mode --------------------------------------------

Entry_mode: ;rcall LCD_idle_wait ; wait till not busy

ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;e=0,rw=0, rs=0
out PortA, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(1<<Epin) ;set Enable
out PortA, temp ;

ldi temp, (1<<PB2)|(1<<PB1)|(0<<PB0) ;sets to increment when writen to, display does not shift
out PortB, temp ;

nop ;125ns delay

ldi temp,(0<<RSpin)|(0<<RWpin)|(0<<Epin) ;clr Enable
out PortA, temp ;

ret ;

;----------------------------------Initialise the LCD-------------------------------------------

LCD_Init: ldi timeout,250 ;set 160 cycles
rcall delay_long ;delay for 20ms (spec = 15ms)
rcall LCD_Funct_set ;

ldi timeout,120 ;set 48 cycles
rcall delay_long ;delay for 7.5ms (spec = 4.125ms)
rcall LCD_Funct_set ;

ldi timeout,6 ;set 3 cycles
rcall delay_long ;delay for 375us (spec = 100us)
rcall LCD_Funct_set ;

ldi timeout,250 ;set 160 cycles
rcall delay_long ;delay for 20ms (spec = 15ms)
rcall LCD_Funct_set ;

ldi timeout,250 ;set 160 cycles
rcall delay_long ;delay for 20ms (spec = 15ms)
rcall LCD_off ;turn the lcd off

ldi timeout,250 ;set 160 cycles
rcall delay_long ;delay for 20ms (spec = 15ms)
rcall LCD_clr_disp ;clear the display

ldi timeout,250 ;set 160 cycles
rcall delay_long ;delay for 20ms (spec = 15ms)
rcall Entry_mode ;set the movement mode

ldi timeout,250 ;set 160 cycles
rcall delay_long ;delay for 20ms (spec = 15ms)
rcall LCD_on ;turn the lcd off

ldi timeout,250 ;set 160 cycles
rcall delay_long ;delay for 20ms (spec = 15ms)

ret ;

;--------------------------- loads a message -------------------------------------------------

Load_Message:
lpm ; Load byte from program memory into r0

tst r0 ; loop until at the end of the message
breq return3 ;

rcall LCD_Output ; output current char rom r0

adiw ZL,1 ; Increase Z registers
rjmp Load_Message;

return3: ret ;return

;---------------------------------------- MAIN code block-----------------------------------------

MAIN:
---------- Output message 1 --------------
rcall LCD_clr_disp ;clear the lcd
ldi ZH, high(2*message1) ;load the high byte of the address
ldi ZL, low(2*message1) ;load the low byte of the address
rcall Load_Message ;

rjmp Loop_forever ;loop forever

Loop_forever:
rjmp Loop_forever ;

Message1:
.db "Hi Tom!!hhtthgg",0 ;message 1 which can be printed to the lcd

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I didn't want to digest the attached code, but you seem to have most of everthing right, i.e., you can display a eight char line.
I had a similar issue yesterday. After plugging away I came up with the following init
values that work for a 2 line 16 char display.

0x03 (do three times using the delay’s required)
0x02 (I am using 4 bit mode)
0x02 (function set)
0x0a (display off)
0x01 (clear display)
0x06 (entry mode set)
0x0e (display and cursor on)
0x01 (set cursor to start of Line #1)

These values worked just fine on my 4 bit mode using the same chip as you are.
I noticed that some LCD modules may only support 8 char’s.
I am posting these values as you appartently have everything else working if you can display the 8 char line.
Compare the init values with the one's you are using.
Hope this helps.

I'll believe corporations
are people when Texas executes one.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since you're using porta, do you have AVCC wired? This powers porta even if you don't use the ADC.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah its powered, i do get the first 8 characters of the message. i have also noticed when you ground the contrast pin on the LCD it makes the entire display go black but on the first 8 go black, its not that the lcd is faulty i have tried with other lcds and gotten the same result.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a Optrex document covering their line of character LCD displays(Optrex is, or was, one of the dominating manufacturers of LCD displays). They have one 1x16 display about which they say

Quote:
In order to properly address these modules, they must be operated as 8 character x 2 line displays where the first 8 characters represent line 1 and the last 8 represent line 2.

All the evidence (only first 8 character showing, contrst affects only first 8 positions) suggests that your display behaves the same. In fact I'd bet a good beer (i.e. a Guinness) that this is so.

If you need to address the individual positions in CGRAM then the 16 characters have the following addresses (hex):

00 01 02 03 04 05 06 07 40 41 41 42 43 44 45 46 47

Did you try to set the display to two lines? The N bit in the Function Set instruction should be 1.

Let us know if it works!

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This method was sucessful, what i did was breakt the message in two and enter a change address command after the 8th character and by changing the number of line to 2 in the function set. Thank you for your help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Great! Your LCD is working, and I've got a beer coming! :wink:

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your beer is in the post.