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.

pic18f452 lcd interfacing problem

Status
Not open for further replies.

sherluck007

Newbie level 5
Joined
Mar 16, 2016
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
83
everyone , iam d.a.e student and i prepared for the final year small project called lcd interfacing with pic microcontroller i have write the program and tested in proteus the program work fine but when iam burn it to microcontroller the lcd not show anything can you please check my code and tell me where iam mistaken i use mikroc for pic for program plz replay fast thanxx....


here is my program...


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
// LCD module baðlantýlarý
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
 
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module baðlantýlarý
    char i;                              // Loop variable
 
void Move_Delay() {                  // Function used for text moving
  Delay_ms(50);                     // You can change the moving speed here
}
 
void main(){
 
   ADCON1 |= 0x0F;
 
   Lcd_Init();
   Lcd_Cmd(_LCD_CURSOR_OFF);
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Out(1, 16, "WELCOME TO");
   Lcd_Out(2, 16, "MY PROJECT");

 
Last edited by a moderator:

add 'while(1);' at the end and check configuration, especially oscillator section
By the way, it is not 'your' code. You did simply copied it from example.
 
Assuming that the circuit was correctly assembled as well as you have not problem in hardware ( e.g contrast pin of LCD not properly biased ), the next step should you add directives to preset on code the configuration bits exactly as you defined on Proteus.
 
Your code is not complete; Go to Mikro C help and you'll find the lcd interfacing code example.
 
thanx for all for fast reply iam A bit confused can someone tell me which oscillator i should used for pic18f during burn hex file ,,,iam using picpgm tool for burn but when i goes to configuration bit tab there are more then one oscillator OPTIONS which i don' understand that which one i have to use in configuration bit tab of picpgm tool. plz tell me which one i have to use


RC oscillator
HS OSCILLATOR
XT OSCILLATOR



WHICH OSCILLATOR I SHOULD USED xt ,,hs,, or rc

- - - Updated - - -

thanx sir can you check my code and tell me where i mistaken actualy sir i have left just one week to complete my project and i can't understand why it's not working please help me....

Code:
// LCD module baðlantýlarý
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module baðlantýlarý
    char i;                              // Loop variable

void Move_Delay() {                  // Function used for text moving
  Delay_ms(50);                     // You can change the moving speed here
}

void main(){

   ADCON1 |= 0x0F;

   Lcd_Init();
   Lcd_Cmd(_LCD_CURSOR_OFF);
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Out(1, 16, "WELCOME TO");
   Lcd_Out(2, 16, "MY PROJECT");
   
   while(1) {                         // Endless loop
    for(i=0; i<15; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();}
      Delay_ms(500);
      
       while(1) {                         // Endless loop
    for(i=0; i<15; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();}
      
      
      Lcd_Cmd(_LCD_CLEAR);
      
   Lcd_Out(1, 1, "PREPARED BY");
   Lcd_Out(2, 1, "SCIENTIST GROUP");

   Delay_ms(1000);
   // Moving text
  for(i=0; i<17; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
    Move_Delay();
  }
   Delay_ms(50);
   Lcd_Cmd(_LCD_CLEAR);

   Lcd_Out(1, 1, "SAJID SALEEM");
   Lcd_Out(2, 1, "NADEEM SULEMAN");
    Delay_ms(300);
   LCD_CMD(_LCD_TURN_OFF);
   Delay_ms(100);
   LCD_CMD(_LCD_TURN_ON);
   Delay_ms(100);
   LCD_CMD(_LCD_TURN_OFF);
   Delay_ms(100);
   LCD_CMD(_LCD_TURN_OFF);
   Delay_ms(100);
   LCD_CMD(_LCD_TURN_ON);
   Delay_ms(100);
   
   LCD_CMD(_LCD_TURN_OFF);
   Delay_ms(100);
   LCD_CMD(_LCD_TURN_ON);

   Delay_ms(2000);
  // Moving text
  for(i=0; i<16; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
    Move_Delay();
  }
   Lcd_Cmd(_LCD_CLEAR);
   
   
   Lcd_Out(1, 16, "SPECIAL THANX TO...");
    while(1) {                         // Endless loop
    for(i=0; i<34; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();}
      
    Lcd_Cmd(_LCD_CLEAR);
   
   Lcd_out(1,16, "Junaid Zaheer &");
   Lcd_out(2,16, "MY ALL TEACHERS");
    while(1) {                         // Endless loop
    for(i=0; i<15; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();}
      Delay_ms(2000);
      
      while(1) {                         // Endless loop
    for(i=0; i<15; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();}
      Lcd_Cmd(_LCD_CLEAR);
      
      Lcd_out(1,1, "THANKS FOR");
      Lcd_out(2,1, "WATCHING.......");
      Delay_ms(2000);
      
      while(1) {                         // Endless loop
    for(i=0; i<17; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();}
      Lcd_Cmd(_LCD_CLEAR);
      
    Lcd_out(1,16, "CODE IS WRITTEN BY.....");
      
       while(1) {                         // Endless loop
     for(i=0; i<35; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();}
      Lcd_Cmd(_LCD_CLEAR);
  
      
 
}}}}}} }  }
 
Last edited by a moderator:

Use RC if you are using an external resistor and capacitor to set the clock frequency - not accurate but cheap.
Use XT for quartz crystals or ceramic resonators up to about 4MHZ.
Use HS for higher frequency crystals and resonators.

The only difference between XT and HS is the gain of the amplifier in the intenal oscillator is changed so there is an area of say 3.5MHz to 4.5MHz where both modes will work equally well.

Brian.
 

Ensure the MCLR pin is tied or pulled high
Ensure that the configuration bits are set correctly (watch dog timer set to off)
Ensure that the LCD contrast pin is initially connected to ground
Ensure that you have decoupling capacitors across the supply rails (0.1uf ceramic as close as possible to PIC power connections)
Check that the oscillator is running.
 

yes i did and can someone tell me is this not the oscillator problem i used 20MHZ crystal in proteus simulation and then in the hardware i used 12mhz crystal,,,the question is what will happend if i use lower or greater oscillator ?
 

A lower frequency oscillator will make the PIC run slower but will make the circuit more likely to work i.e. timings become less critical and the oscillator is more likely to start up. Below 3-4 Mhz you will have to change the oscillator type in the config bits. In a non working circuit like this it is a good idea to run the PIC very slowly to eliminate timing problems (say 1Mhz).
 
Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top