Author Topic: 16X2 LCD Problem  (Read 2123 times)

0 Members and 1 Guest are viewing this topic.

Offline LesterwyattTopic starter

  • Regular Contributor
  • *
  • Posts: 73
  • Country: gb
    • My YouTube Channel
16X2 LCD Problem
« on: March 05, 2015, 05:57:36 pm »
Code: [Select]
Hello
I have a problem with my 16X2 LCD. I am trying to display a simple string of characters.
For the first 2 seconds of the program the display should display 'Voltmeter' then go into a continuous loop
displaying  mV = what ever voltage .
My problem is my LCD only displays the first character of the sting.
.i.e  'V' rather than 'Voltmeter'. and 'm' rather than 'mV'. However i can display the voltage reading just fine.
The display looks like this ' m  5000'
Rather than ' mV = 5000'
I am using Mikroc on a PIC18f45k22. I am uploading the HEX file from MPLAB IDE via PICKIT3.

Here is my code:

Thanks Lester

[code
 sbit LCD_RS at RB4_bit;
 sbit LCD_EN at RB5_bit;
 sbit LCD_D4 at RB0_bit;
 sbit LCD_D5 at RB1_bit;
 sbit LCD_D6 at RB2_bit;
 sbit LCD_D7 at RB3_bit;

 sbit LCD_RS_Direction at TRISB4_bit;
 sbit LCD_EN_Direction at TRISB5_bit;
 sbit LCD_D4_Direction at TRISB0_bit;
 sbit LCD_D5_Direction at TRISB1_bit;
 sbit LCD_D6_Direction at TRISB2_bit;
 sbit LCD_d7_Direction at TRISB3_bit;

void main() {
  unsigned long Vin, mV;
  unsigned char op[12];
  unsigned char i, j, lcd[5];

  char *str;
  ANSELB = 0;
  ANSELA = 1;
  TRISB = 0;
  TRISA = 1;

  Lcd_Init();
  Delay_ms(1);
  Lcd_cmd(_LCD_CLEAR);
   Delay_ms(1);
  Lcd_cmd(_LCD_CURSOR_OFF);
       Delay_ms(1);
  Lcd_Out (1,1,"VOLTMETER");
  Delay_ms(2000);

  ADCON1 = 0x80;

  for(;;)

  {
  Lcd_cmd(_LCD_CLEAR);
  Vin = Adc_Read(0);
  Lcd_Out(1,1,"mV = ");
  mV = (Vin * 5000) >> 10;
  LongToStr(mV,op);
  str = Ltrim(op);
  Lcd_Out(1,6,str);
  Delay_ms(1000);
  }
  }
]


 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: 16X2 LCD Problem
« Reply #1 on: March 09, 2015, 08:10:08 am »
This is a downside of using a 3rd party library. You don't really know how it works internally, and if it doesn't 'just work', you've a chunk of work on your hands.

The code you've posted just shows the library calls, not the code that's actually going wrong.

Nothing for it but to delve into the library, step through that, and compare what it's doing with the data sheet for the LCD controller.

Offline Towger

  • Super Contributor
  • ***
  • Posts: 1645
  • Country: ie
Re: 16X2 LCD Problem
« Reply #2 on: March 09, 2015, 08:46:52 am »
Without knowing anything about the library, my guess is that Lcd Out uses X, Y. Your 1, 6 is overwriting the first string at char 1 and line 6 just wraps around back to line 1.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf