0
\$\begingroup\$

I have programmed a PIC before. The function of this PIC was to display Temperature based on an NTC, my little cousin yesterday messed with the wires and now it is not printing anything on the screen, i am trying just to get it to say hello world. It is working perfectly on Protoeus.

What i have tried before:

  1. Increase the delays of the LCD initilaization.
  2. Set different PORT to output to LCD
  3. Checked the connections like 30 times.

Here is my code:

/* 
 * File:   Tempreature_NTC.c
 * Author: Karam Jaber <Karam.Jaber at JK.org>
 *
 * Created on January 4, 2019, 9:59 AM
 */
#define _XTAL_FREQ 182476 

#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
#define Voltage_Divsion_R 10000.00
#define Beta_Coef 4096.00
#define Room_Temp 25.00

// CONFIG
#pragma config FOSC = EXTRC     // Oscillator Selection bits (RC oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config CP = OFF         // FLASH Program Memory Code Protection bits (Code protection off)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF        // Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EE Memory Code Protection (Code Protection off)
#pragma config WRT = OFF         // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)

#include <xc.h>
#include <math.h>

long NTC_Resistance;

void ADC_Initialize()
{
  TRISA = 0xff;  
  ADCON0 = 0b01000001; //ADC ON and Fosc/16 is selected
  ADCON1 = 0b11000000; // Internal reference voltage is selected
  ADRESH=0;           /*Flush ADC output Register*/
  ADRESL=0;  
}

unsigned int ADC_Read(unsigned char channel)
{
  ADCON0 &= 0b11000101; //Clearing the Channel Selection Bits
  ADCON0 |= channel<<3; //Setting the required Bits
  __delay_ms(1); //Acquisition time to charge hold capacitor
  GO_nDONE = 1; //Initializes A/D Conversion
  while(GO_nDONE); //Wait for A/D Conversion to complete
  return ((ADRESH<<8)+ADRESL); //Returns Result
}

//LCD Functions .
void Lcd_SetBit(char data_bit) //Based on the Hex value Set the Bits of the Data Lines
{
    if(data_bit& 1) 
        D4 = 1;
    else
        D4 = 0;

    if(data_bit& 2)
        D5 = 1;
    else
        D5 = 0;

    if(data_bit& 4)
        D6 = 1;
    else
        D6 = 0;

    if(data_bit& 8) 
        D7 = 1;
    else
        D7 = 0;
}

void Lcd_Cmd(char a)
{
    RS = 0;           
    Lcd_SetBit(a); //Incoming Hex value
    EN  = 1;         
        __delay_ms(4);
        EN  = 0;         
}

void Lcd_Clear()
{
    Lcd_Cmd(0); //Clear the LCD
    Lcd_Cmd(1); //Move the cursor to first position
}

void Lcd_Set_Cursor(char a, char b)
{
    char temp,z,y;
    if(a== 1)
    {
      temp = 0x80 + b - 1; //80H is used to move the curser
        z = temp>>4; //Lower 8-bits
        y = temp & 0x0F; //Upper 8-bits
        Lcd_Cmd(z); //Set Row
        Lcd_Cmd(y); //Set Column
    }
    else if(a== 2)
    {
        temp = 0xC0 + b - 1;
        z = temp>>4; //Lower 8-bits
        y = temp & 0x0F; //Upper 8-bits
        Lcd_Cmd(z); //Set Row
        Lcd_Cmd(y); //Set Column
    }
}

void Lcd_Start()
{
  Lcd_SetBit(0x00);
  for(int i=10244; i<=0; i--)  NOP();  
  Lcd_Cmd(0x03);
    __delay_ms(5);
  Lcd_Cmd(0x03);
    __delay_ms(11);
  Lcd_Cmd(0x03); 
  Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
  Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
  Lcd_Cmd(0x08); //Select Row 1
  Lcd_Cmd(0x00); //Clear Row 1 Display
  Lcd_Cmd(0x0C); //Select Row 2
  Lcd_Cmd(0x00); //Clear Row 2 Display
  Lcd_Cmd(0x06);
}

void Lcd_Print_Char(char data)  //Send 8-bits through 4-bit mode
{
   char Lower_Nibble,Upper_Nibble;
   Lower_Nibble = data&0x0F;
   Upper_Nibble = data&0xF0;
   RS = 1;             // => RS = 1
   Lcd_SetBit(Upper_Nibble>>4);             //Send upper half by shifting by 4
   EN = 1;
   for(int i=21303; i<=0; i--)  NOP(); 
   EN = 0;
   Lcd_SetBit(Lower_Nibble); //Send Lower half
   EN = 1;
   for(int i=21303; i<=0; i--)  NOP();
   EN = 0;
}

void Lcd_Print_String(char *a)
{
    int i;
    for(i=0;a[i]!='\0';i++)
       Lcd_Print_Char(a[i]);  //Split the string using pointers and call the Char function 
}


int main()
{

    Lcd_Start();

    while(1)
    {

        Lcd_Clear();
        Lcd_Print_String("HELLO 5awa!");

    }



    return 0;
}

enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ Get someone else to check the wires for you. Obviously, you're missing something. \$\endgroup\$ – Dave Tweed Jan 10 at 17:06
  • \$\begingroup\$ Hello Karam, What is the reasoning for the Relay switched LED? Is that a regular Green LED, or is it meant to represent some higher current device? \$\endgroup\$ – Clipboard_Waving_Enginerd Jan 10 at 18:12
1
\$\begingroup\$

Although your question isn't clear on this point, I'm assuming that your prototype hardware & software did work before your "little cousin yesterday messed with the wires and now it is not printing anything on the screen".

In that case, then there's no point in altering the program, or supplying the schematic etc. (since the schematic won't show what has changed physically). If the only change between "working" and "not working" was your cousin doing something physical to the board, then the fix will also be doing something physical.

Checked the connections like 30 times.

As Dave says, get help to check it (since you aren't seeing the problem(s)). Also consider the possibility that whatever your cousin did might (unfortunately) have damaged component(s) e.g. reverse power connection, connecting power supply to an MCU output pin etc.

You should, of course, make simple voltage measurements with a DVM to the standard places (e.g. power connections to the MCU). You can try adjusting the contrast potentiometer on your LCD display, and see if you can see (at least) "blocks" for each character, which indicates that the LCD module has got power, even if it isn't displaying your desired text.

It is difficult for readers here, who cannot see your board, cannot perform measurements ourselves, and cannot see how your cousin "messed with the wires", to tell you what is now broken.

Two alternative approaches you could take, instead of trying to "fix" your existing prototype, include:

  • Dismantle that prototype completely and rebuild the same design from scratch. That can sometimes be more successful than trying to fix an existing (but non-working) prototype e.g. it forces you to remove all the wires and perhaps find one(s) which were not plugged-in firmly etc.

  • Dismantle that prototype completely, and build a simpler design (e.g blink LED) from scratch, to try to test some components that you have. Since that simpler design will have fewer connections and fewer components, it allows you to build up confidence in a subset of components initially.

  • Try a different physical MCU (if you have one) in a simpler design, in case the one you are currently using has been electrically damaged by whatever your cousin did.

As always, there are several troubleshooting approaches, depending on which components, test equipment, time and skills you have. These are just a few...

\$\endgroup\$
0
\$\begingroup\$

You've got the cursor switched off.

In Lcd_Start()

Change Lcd_Cmd(0x0C); to Lcd_Cmd(0x0E);

also...

at the bottom of this routine you need to initialise the display and return the cursor to home.

so add

Lcd_Cmd(0x00);

Lcd_Cmd(0x01);

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.