CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with LCD with PICDEM 2 PLUS demo board

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
spanska
Guest







Problem with LCD with PICDEM 2 PLUS demo board
PostPosted: Mon Mar 06, 2006 9:12 am     Reply with quote

Hi!

I'm trying to write something on the LCD of that demo board but I have a strange bug. After I plug the power, I just see very light squares on the first line of the LCD. I have to push the reset button to see the "Heelllo!" message on it. Why is it acting that way? SOMETIMES it does show the message just after I put the power but it's quite rare.

Thank you!

Code:

#include <18f452.h>

#fuses XT,NOWDT,PUT,NOPROTECT,BROWNOUT,NOLVP,NOCPD,NOWRT

#use delay (clock = 4000000)

#define LCD_EN       PIN_A1
#define LCD_RS       PIN_A3
#define LCD_D4       PIN_D0
#define LCD_D5       PIN_D1
#define LCD_D6       PIN_D2
#define LCD_D7       PIN_D3

#define CLEAR_LCD    0x01
#define LINE_1       0x00
#define LINE_2       0x40

void toggle_E()
{
   output_high(LCD_EN);
   delay_ms(5);
   output_low(LCD_EN);
   delay_ms(5);
}

void lcd_setdata4bit(unsigned int DX)
{
   output_bit(LCD_D4, DX & 0x01);
   output_bit(LCD_D5, DX & 0x02);
   output_bit(LCD_D6, DX & 0x04);
   output_bit(LCD_D7, DX & 0x08);
}

void lcd_init(void)
{
   lcd_setdata4bit(0x00);
   output_low(LCD_RS);
   output_low(LCD_EN);
   delay_ms(200);          // wait enough time after Vdd rise

   lcd_setdata4bit(0x02); toggle_E();

   lcd_setdata4bit(0x02); toggle_E(); // function set
   lcd_setdata4bit(0x08); toggle_E();

   lcd_setdata4bit(0x00); toggle_E(); // cursor settings
   lcd_setdata4bit(0x0F); toggle_E();

   lcd_setdata4bit(0x00); toggle_E(); // entry mode set
   lcd_setdata4bit(0x06); toggle_E();

   delay_ms(10);

   lcd_setdata4bit(0x00); toggle_E(); // clear display
   lcd_setdata4bit(0x01); toggle_E();

   delay_ms(10);

}

void lcd_putchar(unsigned int DX)
{
   output_high(LCD_RS);
   lcd_setdata4bit(swap(DX));     // send high nibble
   toggle_E();
   lcd_setdata4bit(swap(DX));     // send low nibble
   toggle_E();
   output_low(LCD_RS);
}

void main(void)
{

   delay_ms(1000);

   set_tris_a(0b00000000);
   set_tris_b(0b00000000);
   set_tris_d(0b00000000);

   setup_adc(ADC_OFF);
   setup_adc_ports(NO_ANALOGS);

   lcd_init();
   printf(lcd_putchar, "Heelllo!");           // display message

   while (1)
   {
      output_high(PIN_B0);
      delay_ms(1000);
      output_low(PIN_B0);
      delay_ms(1000);
   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 06, 2006 12:39 pm     Reply with quote

There are two LCD drivers in the Code Library that work
with the PicDem2-Plus board. Try one of them.

http://www.ccsinfo.com/forum/viewtopic.php?t=20182

http://www.ccsinfo.com/forum/viewtopic.php?t=24661
spanska



Joined: 06 Mar 2006
Posts: 2

View user's profile Send private message

PostPosted: Mon Mar 06, 2006 1:49 pm     Reply with quote

Thank you for your reply!

I was actually wondering why mine wasn't working 100% of the time. I worked on it several hours to fix other problems but I still cannot understand why it's acting like that. It's working but why is it doing that right after I put the power and why do I have to use the reset button are questions that'll stay unless I find the problem with it.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 06, 2006 1:52 pm     Reply with quote

Quote:
why do I have to use the reset button

Do you still have that problem if you use one of the drivers that I
recommended ?
spanska



Joined: 06 Mar 2006
Posts: 2

View user's profile Send private message

PostPosted: Mon Mar 06, 2006 4:51 pm     Reply with quote

It works fine with your code. Seems like I made a mistake somewhere in mine!

Thank you for your help Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group