Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Serial LCD Problem, text prints slowly

Status
Not open for further replies.
Joined
Dec 4, 2012
Messages
4,280
Helped
822
Reputation
1,654
Reaction score
791
Trophy points
1,393
Location
Bangalore, India
Activity points
0
I have written a Serial LCD Code which uses 2 wires. The problem is the characters display one after the other and it is very slow. Why does the character print so slowly? I want it to display characters just like 4-bit non serial LCD prints i.e., I need it to print data fast so that it appears as if each line is printed as a whole.

I am attaching my project files and Proteus files.
 

Attachments

  • SLCDCD4094.rar
    46.7 KB · Views: 36

Remove waitUs.

Try modified code in attachment.


:wink:
 

Attachments

  • updated-faster.rar
    1.9 KB · Views: 41

Thanks tpetar. It is much better now. I still modified the code. See below piece of code. I commented out the 2 delays in the for loop. I want to know is it ok to remove the delays in the for loop or is it necessary to have them? I tested it on Proteus after removing the 2 delays in the for loop and it is working perfectly.

I am attaching the new file.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
for ( i=8;i>0;i=i>>1)
        {
                if(d & i)
                        {
                                data_ =1;
                        }
                        else
                        {
                                data_ =0;
                        }
                //waitUs(10);
                clk = 1;
                //waitUs(10);
                clk = 0;
        }

 

Attachments

  • SLCDCD4094 v2.rar
    60.3 KB · Views: 36

It should be ok. Thats the problem with Proteus simulator you never know whether it will work or not on real hardware, that's why I always say nothing can replace developing board or protoboard with real hardware. Proteus is good as cheap variant if you dont have hardware, but it may be a waste of time.

Additional you can run uC on faster speed, try 16MHz, existing configuration is for 4MHz. :wink:
 

Why it is slow when 4 MHz is used? All my C code is around 210 lines and if it is assumed that the assembly equivalent code will have around 2000 line code and each assembly instruction will take 6 clocks then total clock needed is 12000 clocks. 1 sec = 4000000 clocks, 12000 clocks = 3 ms. Even if it takes 3 ms then text should appear instantly.
 

Why it is slow when 4 MHz is used?

Because your 'waitUs' function is bad (it is the same as the 'waitLcd') :

Code:
void waitUs(int x) {
   unsigned char i ;
   
   for (x ;x>1;x--) 
       for (i=0;i<=10;i++);
}

So the waitUs(10) is much more than 10 us: outer (x) loop runs 10 times, but the intern loop (i) itself longer than 40 us at 4 Mhz.
See the asm output...
 

Attachments

  • 2wire_lcd.zip
    51.2 KB · Views: 37
Last edited:

Thank you zuisti.

Can somebody explain this piece of asm code.


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
_waitUs:
 
;slcd.c,346 ::                 void waitUs(int x)
;slcd.c,349 ::                 for (x ;x>1;x--);
L_waitUs14:
        MOVLW      128
        MOVWF      R0+0
        MOVLW      128
        XORWF      FARG_waitUs_x+1, 0
        SUBWF      R0+0, 0
        BTFSS      STATUS+0, 2
        GOTO       L__waitUs32
        MOVF       FARG_waitUs_x+0, 0
        SUBLW      1
L__waitUs32:
        BTFSC      STATUS+0, 0
        GOTO       L_waitUs15
        MOVLW      1
        SUBWF      FARG_waitUs_x+0, 1
        BTFSS      STATUS+0, 0
        DECF       FARG_waitUs_x+1, 1
        GOTO       L_waitUs14
L_waitUs15:
;slcd.c,353 ::                 }
L_end_waitUs:
        RETURN
; end of _waitUs

 

Can somebody explain this piece of asm code.
Code:
_waitUs:

;slcd.c,346 ::                 void waitUs(int x)  //[COLOR="#FF0000"]unfortunately (and unnecessarily)
                                                    // the parameter x is a signed int !![/COLOR]

;slcd.c,349 ::                 for (x ;x>1;x--);   //[COLOR="#FF0000"]line 349 in the C source[/COLOR]
L_waitUs14:
        MOVLW      128
        MOVWF      R0+0
        MOVLW      128
        XORWF      FARG_waitUs_x+1, 0 //[COLOR="#FF0000"]the signed 'x > 1' examining is such complicated :-([/COLOR]
        SUBWF      R0+0, 0
        BTFSS      STATUS+0, 2
        GOTO       L__waitUs32
        MOVF       FARG_waitUs_x+0, 0  //[COLOR="#FF0000"]the 'FARG_waitUs_x+0 (and  +1) is the parameter x (2 bytes) [/COLOR]
        SUBLW      1
L__waitUs32:
        BTFSC      STATUS+0, 0           //[COLOR="#FF0000"]if carry then end else continue[/COLOR]
        GOTO       L_waitUs15
        MOVLW      1
        SUBWF      FARG_waitUs_x+0, 1   //[COLOR="#FF0000"]the 'x--' is also such complicated :-([/COLOR]
        BTFSS      STATUS+0, 0
        DECF       FARG_waitUs_x+1, 1
        GOTO       L_waitUs14
L_waitUs15:
;slcd.c,353 ::                 }
L_end_waitUs:
        RETURN
; end of _waitUs

So use here an (unsigned) char parameter!
 

Ok. Thanks zuisti.

I tried but if I use 10us delay it works upto MCU clock 16 MHz. For 20 MHz LCD display is blank. If I use 20us delay then it works at 20 MHz also.
 

Serial LCD working at 20 MHz.

90491d1367605690-photo0121.jpg
 

Attachments

  • Photo0121.jpg
    Photo0121.jpg
    949.4 KB · Views: 60

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top