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

Problems LCD16x02 with 74HC595.

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



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

Problems LCD16x02 with 74HC595.
PostPosted: Mon May 23, 2016 3:34 am     Reply with quote

Hi everybody.
Im redesign a project with LCD 16x02 (HD44780) followed this links:
http://www.electronics-lab.com/project/3-wire-serial-lcd-using-a-shift-register/
Because Im using 3.3V power supply for MCU, sothat I feed a 3.3V for 74HC595 and LCD power supply pin.
I read the datasheet of both LCD and 74HC595 can operatings with 3.3V.
I tried port code from MicroC to CCS, but the result LCD display not clear, I also tried tie VEE to GND, but LCD display not brightness.
If can, pls help me to solve this problem.
Thanks you.
* driver 74595_lcd_ex.c
Code:


#define lcd_en             PIN_B4
#define lcd_data_595       PIN_B5
#define lcd_clk_595        PIN_B6


void init_74595_lcd(void)
{
   output_low(lcd_data_595);
   output_low(lcd_clk_595);
}

void write_nibble_lcd(unsigned int data, unsigned int1 rs)
{
   unsigned int j=0, tmp=0;     
   output_high(lcd_en);
   delay_us(20);
   
   //------------ write RS ------------------
   output_bit(lcd_data_595,RS);
   output_low(lcd_clk_595);
   delay_us(10);
   output_high(lcd_clk_595);
   delay_us(10);
   output_low(lcd_clk_595);
   
   //-------------- write niblle --------------
   for(j=0;j<4;j++)
   {
      tmp= data&(0x08>>j);
      if(tmp==0)   output_low(lcd_data_595);
      else output_high(lcd_data_595);
      output_low(lcd_clk_595);
      delay_us(10);
      output_high(lcd_clk_595);
      delay_us(10);
      output_low(lcd_clk_595);
      delay_us(10);
   }
   
   //--------------- write lacth-----------------
   output_high(lcd_clk_595);
   delay_us(10);
   output_low(lcd_clk_595);
   delay_us(10);
   
   //--------------- reset signal----------------
   
   output_low(lcd_en);
   delay_ms(1);
   output_high(lcd_en);
   delay_ms(1);
   output_low(lcd_data_595);
}




void write_byte_lcd(unsigned int data, unsigned int1 RS)
{
   unsigned int hi_byte, lo_byte;   
   hi_byte= (data>>4)&0x0F;
   lo_byte= data&0x0F;
   write_nibble_lcd(hi_byte,RS);
   write_nibble_lcd(lo_byte,RS);
}


void init_lcd(void)
{
   init_74595_lcd();
   output_low(lcd_en);   
   delay_ms(100);
   
//!   write_byte_lcd(0x20,0); delay_ms(50);
   write_byte_lcd(0x20,0); delay_ms(50);
   write_byte_lcd(0x20,0); delay_ms(50);
   write_byte_lcd(0x20,0); delay_ms(50);
   
   write_byte_lcd(0x28,0); delay_ms(50);
   write_byte_lcd(0x0E,0); delay_ms(50);
   write_byte_lcd(0x06,0); delay_ms(50);
   write_byte_lcd(0x01,0); delay_ms(50);   
   
   delay_ms(1000);
   
}

void home_lcd(void)
{
   write_byte_lcd(0x02,0);
   delay_ms(10);   
}

void move_lcd(unsigned int y, unsigned int x)
{
   
   unsigned int addr;
   addr= 64*(y-1)+(x-1)+0x80;
   write_byte_lcd(addr,0);
}


void clr_lcd(void)
{
   write_byte_lcd(0x01,0);
   delay_ms(10);   
}

void putchar_lcd(unsigned char schar)
{
   write_byte_lcd(schar,1);
   delay_ms(1);
}

void putstring_lcd(char* str, unsigned char len)
{
   unsigned char i;
   for(i=0;i<len;i++)
   {
      if(str[i]>0) putchar_lcd(str[i]);
      else putchar_lcd(' ');
   }
}



* Main code
Code:

                                                                                                                                         
#include <18F2520.h>
#fuses   HS
#fuses   PUT
#fuses   NOFCMEN
#fuses   NOIESO
#fuses   NOPBADEN
#fuses   MCLR
#fuses   NOSTVREN
#fuses   NOXINST
#fuses   NODEBUG
#fuses   PROTECT
#fuses   NOLVP
#fuses   NOWDT
#fuses   NOBROWNOUT
#fuses   NOXINST
#use     delay(clock=16000000)



//!#include "lcd16x2.c"
#include "74595_role.c"
#include "74595_lcd_ex.c"

void main(void)
{
      Delay_ms(1000);
      set_tris_b(0);
     
      output_high(PIN_B7);
     
      output_toggle(PIN_B2);
      delay_ms(200);
      output_toggle(PIN_B2);
      delay_ms(200);
      output_toggle(PIN_B2);
      delay_ms(200);
      output_toggle(PIN_B2);
      delay_ms(200);     
     
      init_lcd();
      clr_lcd();
      putchar_lcd('A');
      putchar_lcd('A');
      putchar_lcd('A');
      putchar_lcd('A');
   while(1)
   {
   }
}


_________________
Begin Begin Begin !!!
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon May 23, 2016 5:21 am     Reply with quote

A couple of points...

I just opened the 18F2520 datasheet, looked at chapter 26, 'electrical characteristics', figure 26-1 and the lowest Vdd is 4.2 volts NOT '3 volts'.
Now if you're using the 18LF2520, that will run at 3 volts.

If you need to run at 3 volts you WILL need the 'L' version of that PIC or an F version designed to run at 3 volts( few do but 18F46K22 is one !)
...however you have another problem..

Most ( all ?) common 16x2 LCD module require to be run from 5 volts. 3 volt rated ones are few and expensive !
I have a simple hardware solution that WILL allow you to run a 5 volt LCD module from 3 volts though. It's been benched tested for the past 3 months and is stable.The required hardware consists of 2 diodes and 2 capacitors, to form a voltage doubler and one PIC I/O pin. Software consists of using the timer associated with that pin. The program simply sets up the timer to run at a few KHz, 50% duty cycle..more or less.

In my case it runs a 20x4 LCD module to display 4 BIG digits for a tachometer project. Of course now that planting season is here,I'm out there not 'playing with PICs.

Jay
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Mon May 23, 2016 7:51 pm     Reply with quote

temtronic wrote:
A couple of points...

I just opened the 18F2520 datasheet, looked at chapter 26, 'electrical characteristics', figure 26-1 and the lowest Vdd is 4.2 volts NOT '3 volts'.
Now if you're using the 18LF2520, that will run at 3 volts.

If you need to run at 3 volts you WILL need the 'L' version of that PIC or an F version designed to run at 3 volts( few do but 18F46K22 is one !)
...however you have another problem..

Most ( all ?) common 16x2 LCD module require to be run from 5 volts. 3 volt rated ones are few and expensive !
I have a simple hardware solution that WILL allow you to run a 5 volt LCD module from 3 volts though. It's been benched tested for the past 3 months and is stable.The required hardware consists of 2 diodes and 2 capacitors, to form a voltage doubler and one PIC I/O pin. Software consists of using the timer associated with that pin. The program simply sets up the timer to run at a few KHz, 50% duty cycle..more or less.

In my case it runs a 20x4 LCD module to display 4 BIG digits for a tachometer project. Of course now that planting season is here,I'm out there not 'playing with PICs.

Jay

Hi.
Thanks for your helping.
Because in my project using BLE RN4020 module to interface with MCU sothat I choosing a 3.3V is power supply.
In last time, I tried connected LCD direct with PIC18F97J60 with 3.3V and it run ok, so i think when i change to this design, adding 74HC595IC to reduce pin MCU, the result not good.
Im very happy if you can share me more about your design above.
And I think I change to LCD 3.3 to tried it before.
Thanks you.
_________________
Begin Begin Begin !!!
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