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.

PIC18F4520 LCD problem

Status
Not open for further replies.

eiphan

Member level 3
Joined
Oct 16, 2010
Messages
59
Helped
9
Reputation
18
Reaction score
9
Trophy points
1,288
Location
Singapore
Activity points
1,579
Hi

I have problem in PIC18F4520 lcd DISPLAY.
(1) The physical set up with PCI18F4520 and LCD is using PORTDbits.RD4 and RD5 as RS and Enable. RW pin is connected to ground.
(2) I use MPLAB V8.9 and C18 compiler. 4-bit mode LCD data using PORTD.
(3) The problem is I use PICkit2 to program and use Vdd from kit2. It works fine. But after I remove PICkit2 and put back again or use external power supply, the lcd display disappeared. But when I reflash program with PICkit2 and if it is still connected,it works fine.
(4) That means the coding is ok.
(5) Then I use MikroC IDE and pro compiler. It works fine whether PICkit2 connected or not.


To conclude this, can I say MPLAB IDE has problem? Or PORTD for LCD has problem? Any idea? Thank you so much.
 

Hi,

How is pin 1 Mclre wired when not connected to the Pk2 or Mplab ?

What option have you got Mclre set to in the config bits ?
 

Hi the code is still messy as follow:

PHP:
#include<P18F4520.h>


#pragma config OSC = HS
#pragma config WDT=OFF, LVP=OFF, MCLRE = OFF

#define RS PORTDbits.RD4
#define E PORTDbits.RD5
#define LCDdata PORTD


char msg[] = "Hello";

void DelayFor18TCY( void )
{
 Delay10TCYx(2);        // 5us delay
 return;
}
void DelayPORXLCD (void)
{
  Delay1KTCYx(75); // Delay of 15ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (15ms * 20MHz) / 4
                   // Cycles = 75,000
  return;
}
void DelayXLCD (void)
{
  Delay1KTCYx(25); // Delay of 5ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (5ms * 20MHz) / 4
                   // Cycles = 25,000
  return;
}

void SendLCDdata(char data,char rs)
{
	LCDdata=data>>4;
	RS = rs;
	E = 1;
	E = 0;
	Delay10TCYx(20);        // 50us delay
	LCDdata = data&0x0F;
	RS = rs;
	E = 1;
	E = 0;
	Delay10TCYx(20);  
}
void InitLCD(void)
{
	char a;
	Delay1KTCYx(100);		//20ms
	for(a=0;a<3;a++)
	{
		SendLCDdata(0x20,0);
		Delay1KTCYx(30);		//5ms
	}
	SendLCDdata(0x28,0);
	SendLCDdata(0x01,0);
	Delay1KTCYx(10);		//2ms
	SendLCDdata(0x0C,0);
	SendLCDdata(0x06,0);

}
void String(char *str, char position)
{
	int ptr = 0;
	SendLCDdata(position,0);
	while(str[ptr]!=0)
		SendLCDdata(str[ptr++],1);
}

void main(void)
{
	TRISA = 0xFF;
	TRISB = 0x0F;
    	TRISC = 0x00;
	TRISD = 0x00;
	TRISE = 0;
	PORTA = 0;
	PORTB = 0;
	PORTC = 0;
	PORTD = 0;
	PORTE = 0;
	InitLCD();	
	while(1)
	{
		String(msg,0x80);
		Delay10TCYx(20);  
				
	}	

}
MCLR is connected to Pin 1 of PICkit2 and 10kOhm pull up to VCC. I have never encountered this kind of situation before. It is really wired. I try with another set up for LCD display and LED blink. As PICkit2 is connected, it works as I expected but if I removed PICkit2 and use external power supply, only led blink is working. LCD is not working.
 

Hi,

Don't do C but it looks like the last delay after the string is so short you do not 'see' it on the display before it loops around and the display is cleared by the lcd init ??
 

Hi,

Don't do C but it looks like the last delay after the string is so short you do not 'see' it on the display before it loops around and the display is cleared by the lcd init ??

Thank you for your suggestion. but I can see display when PICkit2 is just flashed and connected. But if I take out PICkit2 and reconnect again. LED blinking is working but not LCD. My suspect is config or PORTD.
 

Use this code


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
void String(char *str, char position)
{
    int ptr = 0;
    SendLCDdata(position,0);
    while(*str)
        SendLCDdata(*str++,1);
}
 
 
 
String(&msg,0x80);

 

Use this code


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
void String(char *str, char position)
{
    int ptr = 0;
    SendLCDdata(position,0);
    while(*str)
        SendLCDdata(*str++,1);
}
 
 
 
String(&msg,0x80);

Thank you jaya. But it does not work either.
 

Sorry, I was wrong. Use this code and it will work fine.


Code C - [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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<P18F4520.h>
 
 
#pragma config OSC = HS
#pragma config WDT=OFF, LVP=OFF, MCLRE = OFF
 
#define RS PORTDbits.RD4
#define E PORTDbits.RD5
#define LCDdata PORTD
 
 
char msg[] = "Hello";
 
void DelayFor18TCY( void )
{
 Delay10TCYx(2);        // 5us delay
 return;
}
void DelayPORXLCD (void)
{
  Delay1KTCYx(75); // Delay of 15ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (15ms * 20MHz) / 4
                   // Cycles = 75,000
  return;
}
void DelayXLCD (void)
{
  Delay1KTCYx(25); // Delay of 5ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (5ms * 20MHz) / 4
                   // Cycles = 25,000
  return;
}
 
void SendLCDdata(char data,char rs)
{
    LCDdata=data>>4;
    RS = rs;
    E = 1;
    E = 0;
    Delay10TCYx(20);        // 50us delay
    LCDdata = data&0x0F;
    RS = rs;
    E = 1;
    E = 0;
    Delay10TCYx(20);  
}
void InitLCD(void)
{
    char a;
    Delay1KTCYx(100);        //20ms
    for(a=0;a<3;a++)
    {
        SendLCDdata(0x20,0);
        Delay1KTCYx(30);        //5ms
    }
    SendLCDdata(0x28,0);
    SendLCDdata(0x01,0);
    Delay1KTCYx(10);        //2ms
    SendLCDdata(0x0C,0);
    SendLCDdata(0x06,0);
 
}
 
void String(char *str, char position)
{
        
    while(*str)
        SendLCDdata(*str++,0);  
    
}
 
void main(void)
{
    TRISA = 0xFF;
    TRISB = 0x0F;
        TRISC = 0x00;
    TRISD = 0x00;
    TRISE = 0;
    PORTA = 0;
    PORTB = 0;
    PORTC = 0;
    PORTD = 0;
    PORTE = 0;
    InitLCD();    
    while(1)
    {
        String(&msg,1);
        Delay10TCYx(20);  
                
    }    
 
}

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top