Sensor cannot display on LCD

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

Re: Sensor cannot display on LCD

Postby ober » Tue Mar 13, 2012 12:23 pm

Try out the simplest program which you are sure it is working with LCD.

From there, slowly add in more function and verify every time you add in a function to minimize the scope you need to debug. As Allen pointed out, get back the code you confirm it works with LCD, from there, add in function and always verify the small portion of code you add it.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: Sensor cannot display on LCD

Postby Lam » Tue Mar 13, 2012 12:50 pm

I tried before of my previous coding, it works fine. I'm tried many many and many times to troubleshoot it! But still remain the same.... I'm solder and wrapping everything by my own.

Previous code display on LCD:

CODE: SELECT_ALL_CODE
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>

#define LCD_CPRT   PORTC
#define LCD_CDDR   DDRC
#define LCD_CPIN   PINC
#define LCD_APRT   PORTA
#define LCD_ADDR   DDRA
#define LCD_APIN   PINA
#define LCD_RS      5
#define LCD_RW      6
#define LCD_EN      7

void delay_us(unsigned int d)
{
   _delay_us(d);
}

void delay_ms(unsigned int d)
{
   _delay_ms(d);
}

void enable_pulse(void)
{
   LCD_APRT |= (1<<LCD_EN);
   delay_us(1);
   LCD_APRT &= ~(1<<LCD_EN);
   delay_us(100);
}

void lcdCommand(unsigned char cmnd)
{
   delay_us(100);
   LCD_CPRT = cmnd;
   LCD_APRT &= ~(1<<LCD_RS);
   LCD_APRT &= ~(1<<LCD_RW);
   enable_pulse();
}

void lcdData(unsigned char data)
{
   delay_us(100);
   LCD_CPRT = data;
   LCD_APRT |= (1<<LCD_RS);
   LCD_APRT &= ~(1<<LCD_RW);
   enable_pulse();
}

void lcd_init()
{
   delay_us(100);
   LCD_CDDR = 0xFF;
   LCD_ADDR = 0xFF;
   
   delay_us(2000);
   lcdCommand(0x38);
   lcdCommand(0x0C);
   lcdCommand(0x06);
   delay_us(2000);
   lcdCommand(0x01);
   delay_us(1000);
}

void lcd_gotoxy(unsigned char x, unsigned char y)
{
   unsigned char firstCharAdr[] = {0x80,0xC0,0x94,0xD4};
   lcdCommand(firstCharAdr[y-1] + x - 1);
   delay_us(100);
}

void lcd_print(char *str)
{
   unsigned char i=0;
   while(str[i]!=0)
   {
      lcdData(str[i]);
      i++;
   }
}

int main(void)
{
   lcd_init();
   lcd_gotoxy(1,1);
   lcd_print("   Hello World  ");
   lcd_gotoxy(1,2);
   lcd_print("Nice to meet you");
   
   while(1);
   return 0;
}
Lam
Novice
 
Posts: 22
Joined: Thu Jan 26, 2012 7:54 pm

Re: Sensor cannot display on LCD

Postby ABSF » Wed Mar 14, 2012 9:31 am

I compared the LCD sub-routines between your current project and the old project and found out the differences are in the delay_us() and delay_ms(). I dont know why you removed some of the delays in your current program. But may be that's the reason why the LCD display doesn't work.

LCDs are very slow devices and cannot cope with the high speed of the mcu. That's why a lot of delays were inserted in the sub-routines. Do put back all the missing delays and try to double the duration and see if it works. E.G. change delay_us(2000) to delay_us(4000), giving them plenty of tiem to do their job.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: Sensor cannot display on LCD

Postby yonghui » Wed Mar 14, 2012 12:42 pm

i think escpecially the reset and clr screen command to lcd needs more delays. else lcd wont be able to display properly.
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Sensor cannot display on LCD

Postby Lam » Wed Mar 14, 2012 1:07 pm

Thanks to everyone given a big advice to me!!!
My LCD finally display sensor's values under base decimal.

Solutions:
I'm used previously coding that's display my name, works!
Then I tried delete some characters, testing it 1 by 1 by deleted 1 by 1 coding, until last display 1 row of characters(such as "Hello").
Next, add on some ADC settings such as ADMUX ,ADCSRA and so on, display on LEDs, then display on LCD.
Surprising, it finally works clearly!
I don't know how to explain here, it's amazing and used me for 3weeks period!

My solution was solved, next I will proceed to display real temperature, humidity values...
Thanks to all of you very very much! ^^
Lam
Novice
 
Posts: 22
Joined: Thu Jan 26, 2012 7:54 pm

Re: Sensor cannot display on LCD

Postby yonghui » Wed Mar 14, 2012 1:40 pm

hi ,

great to hear that. and great effort to debug ur problem! :D
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Sensor cannot display on LCD

Postby ABSF » Wed Mar 14, 2012 2:44 pm

So at least to-night you can have a sound sleep without dreaming your problem again. :lol:

Hope you've gain some experience on how to trouble-shoot your mcu project. 8-)

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: Sensor cannot display on LCD

Postby robosang » Wed Mar 14, 2012 9:00 pm

Good to hear that, but I guess most possible is the bug pointed by Allen :twisted: Delay.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Sensor cannot display on LCD

Postby Lam » Thu Mar 15, 2012 1:00 am

Perhaps Allen was right.
I'm very appreciate for all helps from you all!
Next I will proceed to Zigbee module. In case I face problem again, I hope you guys can guide me. :D
Lam
Novice
 
Posts: 22
Joined: Thu Jan 26, 2012 7:54 pm

Re: Sensor cannot display on LCD

Postby robosang » Sat Mar 17, 2012 11:04 am

Hope to see some photos of your project, I feel satisfy when see what Malaysian can do, it make me proud ! ;)
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Previous

Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 31 guests