Page 1 of 1

LCD AND PIC16F877A

PostPosted: Fri Jun 10, 2016 5:55 pm
by mugishao
HI, i'm designing a telemetry to measure temperature and resistivity from a remote station using sensor LM35, PIC16F877A and LCD, but after connection and running my code i'm not getting any display on my LCD, I have attached my remote code please advice.

my remote code

#include "include.h"

// Configuration word for PIC16F877
//__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON
// & LVP_OFF & CPD_OFF & WRT_ON & DEBUG_OFF);

unsigned int voltage=0;
unsigned long int temperature=0;
unsigned long int resistivity=0;
unsigned int temp=0;
// Main Function
void main(void)
{

TRISB=0;
InitUART(9600);
ADC_Init();
//InitLCD();
Lcd4_Init();
// Intialize UART

// SendStringSerially("TELEMETRY"); // Send string on UART
//SendByteSerially('$');
GIE = 1; // Enable global interrupts
PEIE = 1; // Enable Peripheral Interrupts

while(1)
{
// Do nothing, as Received character is echoed back in the ISR
// If you decide to disable interrupts, then you can
// echo back characters by uncommenting the line below
// SendByteSerially(ReceiveByteSerially()); //Echo Back
temperature=ADC_Read(AN1);
Lcd4_Clear();
//ClearLCDScreen();
Lcd4_Set_Cursor(0,0);
Lcd4_Write_String("temp=");
//WriteStringToLCD("TEMP=");
__delay_ms(2);
SendByteSerially('$');
temperature= (temperature*500)>>10;
resistivity=( temperature+100)*3;

temp = temperature / 100;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);
//WriteDataToLCD(temp+48);


__delay_ms(5);
temp = (temperature / 10) % 10;
SendByteSerially(temp+48);
//WriteDataToLCD(temp+48);
Lcd4_Write_Char(temp+48);

__delay_ms(5);
temp = temperature % 10;
SendByteSerially(temp+48);
//WriteDataToLCD(temp+48);
Lcd4_Write_Char(temp+48);
Lcd4_Write_String("*C");
SendByteSerially(',');

__delay_ms(5);
////////////////////////////////////////////////////////////
Lcd4_Set_Cursor(2,0);
Lcd4_Write_String("Res=");
//SendByteSerially(',');
temp = resistivity / 1000;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);

__delay_ms(10);
temp = (resistivity / 100) % 100;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);
__delay_ms(10);
temp = (resistivity / 10) % 10;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);

__delay_ms(10);

temp = resistivity % 10;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);
Lcd4_Write_String(" U OHM");

//////////////////////////////////////////////////////////////////


SendByteSerially('#');
SendByteSerially('\r');
SendByteSerially('\n');
__delay_ms(5);



}
}

Re: LCD AND PIC16F877A

PostPosted: Fri Jun 10, 2016 10:12 pm
by drh
You haven't shown any of the LCD4xxx() routines. LCDs typically need a delay after power is applied to initialize themselves. Try delaying 250ms after powerup before calling LCD4Init();

Re: LCD AND PIC16F877A

PostPosted: Sat Jun 11, 2016 7:31 pm
by mugishao
REMOTE CODES
Code: Select all
#include "include.h"

// Configuration word for PIC16F877
//__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON
   //   & LVP_OFF & CPD_OFF & WRT_ON & DEBUG_OFF);

unsigned int voltage=0;
unsigned long int  temperature=0;
unsigned long int resistivity=0;
unsigned int temp=0;
// Main Function
void main(void)
{

TRISB=0;
   InitUART(9600);
ADC_Init();
//InitLCD();
Lcd4_Init();
                     // Intialize UART
   
   // SendStringSerially("TELEMETRY");   // Send string on UART
//SendByteSerially('$');
   GIE  = 1;                       // Enable global interrupts
    PEIE = 1;                       // Enable Peripheral Interrupts

   while(1)
   {
      // Do nothing, as Received character is echoed back in the ISR
      // If you decide to disable interrupts, then you can
      // echo back characters by uncommenting the line below
      // SendByteSerially(ReceiveByteSerially());  //Echo Back
temperature=ADC_Read(AN1);
 Lcd4_Clear();
//ClearLCDScreen();
Lcd4_Set_Cursor(0,0);
Lcd4_Write_String("temp=");
//WriteStringToLCD("TEMP=");
__delay_ms(2);
SendByteSerially('$');
temperature= (temperature*500)>>10;
resistivity=( temperature+100)*3;

temp = temperature / 100;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);
//WriteDataToLCD(temp+48);


__delay_ms(5);
temp = (temperature / 10) % 10;
SendByteSerially(temp+48);
//WriteDataToLCD(temp+48);
Lcd4_Write_Char(temp+48);

__delay_ms(5);
temp = temperature % 10;
SendByteSerially(temp+48);
//WriteDataToLCD(temp+48);
Lcd4_Write_Char(temp+48);
Lcd4_Write_String("*C");
SendByteSerially(',');

__delay_ms(5);
////////////////////////////////////////////////////////////
Lcd4_Set_Cursor(2,0);
Lcd4_Write_String("Res=");
//SendByteSerially(',');
temp = resistivity / 1000;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);

__delay_ms(10);
temp = (resistivity / 100) % 100;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);
__delay_ms(10);
temp = (resistivity / 10) % 10;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);

__delay_ms(10);

temp = resistivity % 10;
SendByteSerially(temp+48);
Lcd4_Write_Char(temp+48);
Lcd4_Write_String(" U OHM");

//////////////////////////////////////////////////////////////////


SendByteSerially('#');
SendByteSerially('\r');
SendByteSerially('\n');
__delay_ms(5);



   }
}

BASE STATION CODE

Code: Select all
#include "include.h"

// Configuration word for PIC16F877
//__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON
   //   & LVP_OFF & CPD_OFF & WRT_ON & DEBUG_OFF);
extern char USART1BUFFER[20],RECVFlag;
extern char HASHFlag;
 char axbuff[7];
unsigned  int resistivity ;
unsigned int temp;

unsigned char ch;
// Main Function
void main(void)
{
int i=0;
int j=0;
TRISB=0;

InitUART(9600);
ADC_Init();
Lcd4_Init();
                     // Intialize UART
   
    SendStringSerially("TELEMETRY");   // Send string on UART

   GIE  = 1;                       // Enable global interrupts
    PEIE = 1; 
RCIE = 1;                     // Enable Peripheral Interrupts

   while(1)
   {
/////////////////////////////////////////////////   

int i=0;
if(HASHFlag==1)
{
HASHFlag=0;
Lcd4_Set_Cursor(1,0);
Lcd4_Write_String("Temp=");
Lcd4_Write_Char(USART1BUFFER[1]);
    __delay_ms(5);
Lcd4_Write_Char(USART1BUFFER[2]);
    __delay_ms(5);
Lcd4_Write_Char(USART1BUFFER[3]);
    __delay_ms(5);
Lcd4_Write_String("*C");
Lcd4_Set_Cursor(2,0);
Lcd4_Write_String("R=");
    __delay_ms(5);
Lcd4_Write_Char(USART1BUFFER[5]);
    __delay_ms(5);
Lcd4_Write_Char(USART1BUFFER[6]);
    __delay_ms(5);
Lcd4_Write_Char(USART1BUFFER[7]);
    __delay_ms(5);
Lcd4_Write_Char(USART1BUFFER[8]);
    __delay_ms(5);
Lcd4_Write_String(" u OHM");
     __delay_ms(5);
}

}
}
////////////////////////////////////////////////////////////////////

Re: LCD AND PIC16F877A

PostPosted: Sat Jun 11, 2016 10:26 pm
by drh
I'm done.

Re: LCD AND PIC16F877A

PostPosted: Sun Jun 12, 2016 8:30 am
by ric
mugishao, please use "code" tags when you post code on a forum. I have edited your second post to show you how.
You have already been asked once about your routines which communicate twith the LCD, and you have not shown.
Are they something supplied by your compiler? You have not mentioned WHICH C compiler you are using.