LCD AND PIC16F877A

LCD AND PIC16F877A

Postby mugishao » Fri Jun 10, 2016 5:55 pm

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);



}
}
mugishao
 
Posts: 2
Joined: Fri Jun 10, 2016 5:44 pm

Re: LCD AND PIC16F877A

Postby drh » Fri Jun 10, 2016 10:12 pm

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();
User avatar
drh
Verified identity
 
Posts: 55
Joined: Tue May 27, 2014 3:31 pm
Location: Hemet, Calif.
PIC experience: Professional 5+ years with MCHP products

Re: LCD AND PIC16F877A

Postby mugishao » Sat Jun 11, 2016 7:31 pm

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);
}

}
}
////////////////////////////////////////////////////////////////////
Last edited by ric on Sun Jun 12, 2016 8:28 am, edited 1 time in total.
Reason: Edited to add "code" tags around the code.
mugishao
 
Posts: 2
Joined: Fri Jun 10, 2016 5:44 pm

Re: LCD AND PIC16F877A

Postby drh » Sat Jun 11, 2016 10:26 pm

I'm done.
User avatar
drh
Verified identity
 
Posts: 55
Joined: Tue May 27, 2014 3:31 pm
Location: Hemet, Calif.
PIC experience: Professional 5+ years with MCHP products

Re: LCD AND PIC16F877A

Postby ric » Sun Jun 12, 2016 8:30 am

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.
My new leslie-special website (for fans of The Great Race) :)
User avatar
ric
Verified identity
 
Posts: 393
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to FAQs

Who is online

Users browsing this forum: No registered users and 1 guest