interfacing lcd and pic with ccs compiler

Status
Not open for further replies.

chancelier

Junior Member level 1
Joined
Jan 26, 2010
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
tunisia
Activity points
1,433
hi all

i am trying to interface a 2*16 lcd with a PIC 18F4550
my programming language is CCS pic C compiler

how is that done???

is it done like this

#include<lcd.c>

void main()
{
lcd_init();
lcd_gotoxy(1,2);
lcd-putc("something");}
 

Did you this already ?

Are you getting an error ?
 

yes i have done this but i am getting an error

all instructions related to lcd (lcd_putc ,lcd_gotoxy .... ) are not accepted although i put at the beginning #include<lcd.c>


here is the compilation error message

undefined identifier lcd_putc
undefined identifier lcd_gotoxy
 


Try this.

#include<root\Drivers\lcd.c>

roor :- Your CCS compiler inst. path (eg:C:\Program Files\PICC\)
 

i tried that but that doesnt work


here is my code

Code:
#include <lcd.c>
#include <18F4550.h>
#include <kbd.c>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define LED_R PIN_C5
#define sonnerie PIN_C4
char cot[]={"\X22"};
char code[]={'1','2','3','4'};
int8 ft=1,cnt=0,flag,k,j,s;
int1 mouv=1;
int32 ms1,ms2;
/******************************************************************************/
lcd_init();

 
#int_ext
 void int_rb0()
{
 mouv=1;
 }
#int_timer2
void isr_timer2(void) {
     ms2++; 
  }
  #int_timer1
void isr_timer1(void) {
     ms1++; 
  }

//*********************************************************************************
/************Fonction that sends sms **********/
/******************************************************************************/
void send_sms() {
      
     
     ft=1;
     if(ft==1&&cnt==0)
     {
     
     output_high(LED_R);
     output_high(alarm);
     delay_ms(2000);
     printf("at+cmgf=1\r\n");    //mode texte
     delay_ms(1000);
     printf("AT+CMGS=%s92334936%s\r\n",cot,cot);  //selectionner le destinataire
     delay_ms(1000);
     printf("someone entered your house\X1A");   //ecrire les infos dans le msg
     delay_ms(2000);
    
     
     cnt=1;
     
     }
   

  }
//###############################################################################
#
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   ext_int_edge(H_TO_L);                        // init interrupts
   enable_interrupts(INT_EXT);
   setup_timer_2(T2_DIV_BY_4,78,16); 
    
   enable_interrupts(INT_TIMER2);
  
   enable_interrupts(GLOBAL);
   
   while(true)  {
   if (!input(pin_A0))
   {send_sms();flag=1;}
   if (!input(pin_A1))
   {
   
   k=1;ms2=0;flag=0;
   lcd_init();
   lcd_putc("/f");lcd_gotoxy(1,1);lcd_putc("donner le code");
   for (j=0,j<4,j++)
   {
   s=0;
   while ((s==0)&& (ms2<10000))
   { 
         s=kbd_getc();
   }
   
   
      if (code[j+1]!=s) 
                  k=0;
   lcd_gotoxy(j+1,2);
   lcd_putc(s);
   }
   if ((ms2>10000)||(k=0)) {send_sms();flag=1;}
   lcd_putc("/f");
   lcd_gotoxy(1,1);
   if (k=1) {lcd_putc("code correct")};
   else {lcd_putc("code incorrect");}
      }
      if (flag=1)
      {lcd_putc("/f");lcd_gotoxy(1,1);lcd_putc("donner le code");
      k=1;
        for (j=0,j<4,j++)
   {
   do { s=kbd_getc();}
   while (s==0) ;
      if (code[j+1]!=s) {k=0};
   lcd_gotoxy(j+1,2);
   lcd_putc(s);}
   lcd_putc("/f");
   lcd_gotoxy(1,1);
   if (k=1) {lcd_putc("code correct");
   output_low(led_R);
   output_low(alarm);}
   else
   {lcd_putc("code incorrect")}
      }}}



is there something missing in my code??
something like lcd connections with the PIC
 

does the PICC folder contain the LCD.c file ??

put the include statement in this order
Code:
#include <18F4620.h>
#use delay(clock=8000000)
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,NOMCLR,NOCPD,NOBROWNOUT,NOLVP,NOPBADEN,NOIESO,NOFCMEN
#include <lcd.c>

the include should not be the first statement, and must be after the #use delay statement, as the lcd.c uses the delay_us() function, this function requires the clock to be defined.

change the order and it should work, I tried out a test project and it works perfectly without any errors
 

#include <lcd.c>
#include <18F4550.h>
#include <kbd.c>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
Always Describe MicroController Hex files and other settings first like that
#include <18F4550.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8 )
#include <lcd.c>
#include <kbd.c>

When i compile your code it showed me lot of errors.I have removed those errors,upload the following code in your ccs and check.
Code:
#include <18F4550.h> 
#fuses HS,NOWDT,NOPROTECT 
#use delay(clock=20000000) 
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) 
#include <lcd.c> 
#include <kbd.c> 

#define LED_R PIN_C5
#define sonnerie PIN_C4 
char cot[]={"\X22"}; 
char code[]={'1','2','3','4'}; 
int8 ft=1,cnt=0,flag,k,j,s; 
int1 mouv=1; 
int32 ms1,ms2; 
int alarm;
/******************************************************************************/
lcd_init(); 

  
#int_ext 
 void int_rb0() 
{ 
 mouv=1; 
 } 
#int_timer2 
void isr_timer2(void) { 
     ms2++; 
  } 
  #int_timer1 
void isr_timer1(void) { 
     ms1++; 
  } 

//********************************************************************************* 
/************Fonction that sends sms **********/ 
/******************************************************************************/ 
void send_sms() { 
      
      
     ft=1; 
     if(ft==1&&cnt==0) 
     { 
      
     output_high(LED_R); 
     output_high(alarm); 
     delay_ms(2000); 
     printf("at+cmgf=1\r\n");    //mode texte 
     delay_ms(1000); 
     printf("AT+CMGS=%s92334936%s\r\n",cot,cot);  //selectionner le destinataire 
     delay_ms(1000); 
     printf("someone entered your house\X1A");   //ecrire les infos dans le msg 
     delay_ms(2000); 
    
      
     cnt=1; 
      
     } 
    

  } 
//############################################################################### 
 
void main() 
{ 

   setup_adc_ports(NO_ANALOGS); 
   setup_adc(ADC_OFF); 
   ext_int_edge(H_TO_L);                        // init interrupts 
   enable_interrupts(INT_EXT); 
   setup_timer_2(T2_DIV_BY_4,78,16); 
    
   enable_interrupts(INT_TIMER2); 
  
   enable_interrupts(GLOBAL); 
    
   while(true)  { 
   if (!input(pin_A0)) 
   {send_sms();flag=1;} 
   if (!input(pin_A1)) 
   { 
    
   k=1;ms2=0;flag=0; 
   lcd_init(); 
   lcd_putc("/f");lcd_gotoxy(1,1);lcd_putc("donner le code"); 
   for (j=0;j<4;j++) 
   { 
   s=0; 
   while ((s==0)&& (ms2<10000)) 
   { 
         s=kbd_getc(); 
   } 
    
    
      if (code[j+1]!=s) 
                  k=0; 
   lcd_gotoxy(j+1,2); 
   lcd_putc(s); 
   } 
   if ((ms2>10000)||(k==0)) {send_sms();flag=1;} 
   lcd_putc("/f"); 
   lcd_gotoxy(1,1); 
   if (k==1)
   {
   lcd_putc("code correct");
   }
   else 
   {
   lcd_putc("code incorrect");
   }
   } 
      if (flag==1) 
      {lcd_putc("/f");lcd_gotoxy(1,1);lcd_putc("donner le code"); 
      k=1; 
        for (j=0;j<4;j++) 
   { 
   do { s=kbd_getc();} 
   while (s==0) ; 
      if (code[j+1]!=s) {k=0;} 
   lcd_gotoxy(j+1,2); 
   lcd_putc(s);} 
   lcd_putc("/f"); 
   lcd_gotoxy(1,1); 
   if (k==1) {lcd_putc("code correct"); 
   output_low(led_R); 
   output_low(alarm);} 
   else 
   {lcd_putc("code incorrect");} 
      }}}
 



4 bit lcd working

Code:
#include<16f877a.h>
#device ADC=10
#fuses HS,NOPROTECT,NOWDT,NOLVP//NOBROWNOUT,NOWDT,NOPUT,NOWRT,NODEBUG,LVP,NOCPD
#use delay(clock=16000000)

int16 msb2,msb1,lsb2,lsb1,value;
//RD7---D7 OF LCD
//RD6---D6 OF LCD
//RD5---D5 OF LCD
//RD4---D4 OF LCD
//RD3---EN OF LCD
//RD2---RS OF LCD
//RA0 OR AN0--ANALOG CHANNEL
void convert(unsigned int16 i)
{
  
  msb2=(i/1000)+'0';
  msb1=((i%1000)/100)+'0';
  lsb2=((i%100)/10)+'0';
  lsb1=(i%10)+'0'; 
 
}


void lcd_reset()
{
   output_d(0xFF);
   delay_ms(20);
   output_d(0x30 + 0x08);
   output_d(0x30);
   delay_ms(20);
   output_d(0x30 + 0x08);
   output_d(0x30);
   delay_ms(20);
   output_d(0x30 + 0x08);
   output_d(0x30);
   delay_ms(20);
   output_d(0x20 + 0x08);
   output_d(0x20);
   delay_ms(20);
}
void lcdcmd(unsigned char cmd)
{
  
  output_d((cmd & 0xF0) + 0x08);    
  delay_ms(20);
  output_d(cmd & 0xF0);
  output_d(((cmd<<4) & 0xF0) + 0x08);
  delay_ms(20);
  output_d((cmd<<4) & 0xF0);
//return;
}
   
void lcddat(unsigned char dat)
{
  
  output_d((dat & 0xF0) + 0x0C);
  delay_ms(20);
  output_d((dat &  0xF0) + 0x04);
  output_d(((dat<<4) & 0xF0) + 0x0C);
  delay_ms(20);
  output_d(((dat<<4) & 0xF0) + 0x04);
}
  

void lcd_init()
{
  lcd_reset();
  lcdcmd(0x28);
  delay_ms(20);
  lcdcmd(0x0E);
  delay_ms(20);
  lcdcmd(0x01);
  delay_ms(20);
  lcdcmd(0x06);
 //while(1);
  delay_ms(20);
  lcdcmd(0x80);
//lcddat('A');
//delay_ms(20);
}
void lcd_putc(unsigned char c)
{
 switch(c)
   {
    case '\a':
      lcdcmd(0x80);
     
      break;
   
    case '\b':
       lcdcmd(0xc0);
     
       break;

    default:
       lcddat(c);
     
       break;
   }
}


void main()
{
   setup_adc_ports(RA0_RA1_RA3_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1); 
   
   lcd_init();
   lcd_putc("HELLO");
   set_adc_channel (0);
   while(1)
	{
         value = read_adc();
         convert(value);
  	 lcd_init();
 	 lcddat('T');
 	 lcddat('E');
 	 lcddat('M');
         lcddat('P');
 	 lcddat('=');
   	 lcddat(msb2);
   	 lcddat(msb1);
   	 lcddat(lsb2);
   	 lcddat(lsb1);
         lcddat('C');
  	 delay_ms(1000);
	} 

}
HAVE FUN
 
Last edited:

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…