No displayin lcd 16x2 using with pic18f452 mcu

Status
Not open for further replies.

Anand Kr. Singh

Newbie level 4
Joined
Jul 30, 2014
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
43
At First,i have used pic16f877a every thing is working fine

code:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<16f877a.h>
#include<string.h>
 
 
#use delay(clock=4000000)
#fuses NOLVP,NOWDT,NOPROTECT,HS
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, BITS=8, PARITY=N,stream=PUMP,ERRORS) 
 
#bit   LCD_RS = 0x8.2   //RD2
#bit   LCD_RW = 0x8.0   //RD0
#bit   LCD_EN = 0x8.3   //RD3
 
#bit   RELAY1 = 0x5.0   //RA1
#bit   RELAY2 = 0x5.1   //RA2
#bit   RELAY3 = 0x5.2   //RA3
#bit   RELAY4 = 0x5.3   //RA4
 
#byte  LCD_DATA = 8   
#define LCD_STROBE()  (( LCD_EN = 1),(LCD_EN=0))

but now i have use pic18f452...but the lcd display is not show ..i thick there will be in declaration of hex...please help me. i m use ccs compiler and pickit2.

code for 18f452:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<18f452.h>
#include<string.h>
 
 
#use delay(clock=4000000)
#fuses NOLVP,NOWDT,NOPROTECT,HS
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, BITS=8, PARITY=N,stream=PUMP,ERRORS) 
//#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,BITS=8,PARITY=N,stream=PUMP,FORCE_SW,RESTART_WDT)
 
#bit   LCD_RS = 0x83.2 //PORTDbits.RD2   //RD2
#bit   LCD_RW = 0x83.0  //0xF83.0   //RD0
#bit   LCD_EN = 0x83.3 //0xF83.3   //RD3
 
#bit   RELAY1 = 0xF80.0   //RA1
#bit   RELAY2 = 0xF80.1   //RA2
#bit   RELAY3 = 0xF80.2   //RA3
#bit   RELAY4 = 0xF80.3   //RA4
 
#byte  LCD_DATA = 8   
#define LCD_STROBE()  (( LCD_EN = 1),(LCD_EN=0))


please reply soon....
 
Last edited by a moderator:

I don't understand your question. You have no actual code controlling the LCD, just some defines.
 

[Moved]Display problem with pic18f452

using Pic18f452 with mplab and proteus..
file and snap shot of proteus is attached

code:
Code:
#include <P18f452.h>

#define ldata PORTD

#define rs PORTBbits.RB0
#define rw PORTBbits.RB1
#define en PORTBbits.RB2


void MSDelay(unsigned int itime);
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);

void main()
{
 TRISD=0;
 TRISB=0;
 en=1;
 MSDelay(250);
 lcdcmd(0x38);
 MSDelay(250);
 lcdcmd(0x0E);
 MSDelay(15);
 lcdcmd(0x01);
 MSDelay(15);
 lcdcmd(0x06);
 MSDelay(15);
 lcdcmd(0x86);
 MSDelay(15);
 lcddata('M');
 MSDelay(15);
 lcddata('S');
while(1);
 }
 
 void lcdcmd(unsigned char value)
  {
   unsigned char ldata = value;
   rs = 0;
   rw =0 ;
   en = 1;
   MSDelay(1);
   en=0;
   }
   void lcddata(unsigned char value)
   {
   unsigned char ldata = value;
   rs = 1;
   rw =0 ;
   en = 1;
   MSDelay(1);
   en=0;
   }
   void MSDelay(unsigned int itime)
   { 
   unsigned int i,j;
    for(i=0;i<itime;i++)
       for(j=0;j<135;j++);
    }
 
Last edited by a moderator:

Besides other possible problems, your LCD-routines are for 8-bit interface, but you only connected 4 data lines. Can't work.
 

I don't understand your question. You have no actual code controlling the LCD, just some defines.
i have but i think the main problem is with the defines...
..
ok
i will post the full code also..... this is working fine with pic16f877a...

Code:
include<18f452.h>
#include<string.h>

#use delay(clock=4000000)
#fuses NOLVP,NOWDT,NOPROTECT,HS
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, BITS=8, PARITY=N,stream=PUMP,ERRORS) 
//#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,BITS=8,PARITY=N,stream=PUMP,FORCE_SW,RESTART_WDT)

#bit   LCD_RS = 0x8.2   //RD2
#bit   LCD_RW = 0x8.0   //RD0
#bit   LCD_EN = 0x8.3   //RD3

#bit   RELAY1 = 0x5.0   //RA1
#bit   RELAY2 = 0x5.1   //RA2
#bit   RELAY3 = 0x5.2   //RA3
#bit   RELAY4 = 0x5.3   //RA4

#byte  LCD_DATA = 8   
#define   LCD_STROBE()   ((LCD_EN = 1),(LCD_EN=0))

unsigned char buffer[35],response_flag = 0,Pulse_Count,ch,m,i,j;
int1 relay1_flag,int0_flag;
int16 UNITS;
int16 int_unit[5],t_unit,l_unit,r_unit;
unsigned char num[11];
//rb
//int16 uc1,uc2;
//unsigned int8 old_portb=0,port_b;
//int1 change,ca,ne;

void lcd_string(char * s);
void lcd_write(unsigned char c);
void lcd_clear(void);
void lcd_string(char * s);
void lcd_character(char c);
void lcd_char(unsigned char c);
void lcd_init();

void recharge();

void Read_response();
void char_inte(unsigned char a,b,c);

void send_cmgf(unsigned char *str);
void lcd_numdsply();
void clear_1stline();
void clear_2ndline();
void calc_units(int16 num);
void calc_rs(int16 num);
void get_unit(int16 unit[]);
void char_unit(unsigned char unit[]);

void TX_data(int16 no);

void rs_disp(unsigned int num );
 

unsigned char str22[16]="---WELCOME TO--";
unsigned char str23[17]="NOC Meter";


#INT_EXT
void Pulse_isr()
{
   Pulse_Count++;
   
   if(Pulse_Count == 16)//in place of 10 unit change on 18-7-2014 -32 in naturetech
   {
      Pulse_Count++;
      int0_flag = 1;
      Pulse_Count = 0;
      UNITS++;
   }
}
void calc_units(int16 num)
{  
  int16 unit_buff[5],x1,x2,x3,x4;
   x1 = num/100;
   x1 = x1+0x30;
   unit_buff[1] = x1;
   
 num = num%100;
   num = num*10;
   x2 = num/100;
   x2 = x2+0x30;
   unit_buff[2] = x2;

   num = num%100;
   num = num*10;
   x3 = num/100;
   x3 = x3+0x30;
   unit_buff[3] = x3;
   
   num = num%100;
   num = num*10;
   x4 = num/100;
   x4 = x4+0x30;
   unit_buff[4] = x4;
  
   lcd_char(unit_buff[1]);
   lcd_char(unit_buff[2]);
   lcd_char(unit_buff[3]);
   lcd_char(unit_buff[4]);
   lcd_char(' ');
}
void char_inte(unsigned char a,b,c)
{
unsigned char new[3];
new[0]=a;
new[1]=b;
new[2]=c;
for(int i=0;i<3;i++)//for reading the buffer unit and save it to int
{
if(new[i]=='1')
   int_unit[i]=1;
   
if(new[i]=='2')
   int_unit[i]=2;
   
if(new[i]=='3')
   int_unit[i]=3;
   
if(new[i]=='4')
   int_unit[i]=4;
   
if(new[i]=='5')
   int_unit[i]=5;
   
if(new[i]=='6')
   int_unit[i]=6;
   
if(new[i]=='7')
   int_unit[i]=7;
   
if(new[i]=='8')
   int_unit[i]=8;
   
if(new[i]=='9')
   int_unit[i]=9;
   
if(new[i]=='0')
   int_unit[i]=0;
}
int16 a1=0,b1=0,c1=0;
 a1=int_unit[0] * 100;
   b1=int_unit[1] * 10;
   c1=int_unit[2];
   a1= a1+b1+c1;
   r_unit=a1;      
}

void calc_rs(int16 num)
{
   int16 unit_buff[4],x1,x2,x3;
   x1 = num/100;
   x1 = x1+0x30;
   unit_buff[1] = x1;
   
 num = num%100;
   num = num*10;
   x2 = num/100;
   x2 = x2+0x30;
   unit_buff[2] = x2;

   num = num%100;
   num = num*10;
   x3 = num/100;
   x3 = x3+0x30;
   unit_buff[3] = x3;

   lcd_char(unit_buff[1]);
   lcd_char(unit_buff[2]);
   lcd_char(unit_buff[3]);
}

void main()
{
   set_tris_d(0x00);
   set_tris_a(0x00);
   set_tris_c(0x80);
   
   Pulse_Count = 0;
   UNITS = 0;
   r_unit=0;
   t_unit=0;
   l_unit=0;
    lcd_init(); 
      
   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_EXT);
   ext_int_edge(H_TO_L);

lcd_clear();
   lcd_write(0x80);
   lcd_string(str22);
   lcd_write(0xc0);
   lcd_string(str23);

 while(TRUE)
 {
       lcd_clear();        
             calc_rs(UNITS);
            delay_ms(2000);
            
   }
}



void send_cmgf(unsigned char *str)
{
  //unsigned char t;
    while(*str!='\0')
{
   putchar(*str);
        str++;
}
  putchar(0x0d);
while(getchar()!='K');
   
}


void lcd_write(unsigned char c)
{
   delay_us(40);
   LCD_DATA = ((c & 0xf0));
   LCD_STROBE();
   LCD_DATA = ( ( c << 4 ) & 0xf0 );
   LCD_STROBE();
}
void lcd_char(unsigned char c)
{
   delay_us(40);
   LCD_DATA = ((c & 0xf0));
   LCD_RS = 1;
   LCD_STROBE();
   LCD_DATA = ( ( c << 4 ) & 0xf0 );
   LCD_RS = 1;
   LCD_STROBE();
}
void clear_1stline()
{
   lcd_write(0x80);
   for(m=0;m<16;m++)
   {
      lcd_char(' ');
   }
}
void clear_2ndline()
{
   lcd_write(0xc0);
   for(m=0;m<16;m++)
   {
      lcd_char(' ');
   }
}

void lcd_clear(void)
{
   LCD_RS = 0;
   lcd_write(0x01);
   delay_ms(2);
}

/* write a string of chars to the LCD */

void lcd_string(char * s)
{
   LCD_RS = 1;   // write characters
   while(*s)
      lcd_char(*s++);
}

/* write one character to the LCD */

void lcd_character(char c)
{
   LCD_RS = 1;   // write characters
   lcd_char( c );
}
void lcd_init()
{
   char init_value;

//   ADCON1 = 0x06;   // Disable analog pins on PORTA

   init_value = 0x30; //0x03;
   set_tris_a(0x00);
   set_tris_d(0x00);
   LCD_RS = 0;
   LCD_EN = 0;
   LCD_RW = 0;
   
   delay_ms(15);   // wait 15mSec after power applied,
   LCD_DATA = init_value;
   LCD_STROBE();
   delay_ms(5);
   LCD_STROBE();
   delay_us(200);
   LCD_STROBE();
   delay_us(200);
   LCD_DATA = 0x20; //0x02;   // Four bit mode
   LCD_STROBE();

   lcd_write(0x28); // Set interface length
   lcd_write(0x0c); // Display On, Cursor On, Cursor Blink
   lcd_clear();   // Clear screen
   lcd_write(0x06); // Set entry Mode
}




void recharge()
{
if(t_unit > 0)
        {
            RELAY1 = 0;              //on while recharge
             relay1_flag = 1;
             clear_1stline();
   lcd_write(0x80);
  
    lcd_write(0x89);
   calc_rs(t_unit);
         } 
}
 
Last edited by a moderator:

You are posting completely different LCD routines now. Do you understand the difference regarding interface bit width?
 

You are posting completely different LCD routines now. Do you understand the difference regarding interface bit width?

the 1st example ....i have also tried but not work..:-(

last one is the full code i have tiring to solve the display problem.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…