The Godfather talking
You may crack software. How about me?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 04, 2016, 12:55:26 00:55


Login with username, password and session length


Pages: [1]
Print
Author Topic: Drive lcd 16x2 Hi-tech  (Read 3068 times)
0 Members and 1 Guest are viewing this topic.
Orcino Borges
Newbie
*
 Muted
Offline Offline

Posts: 23

Thank You
-Given: 13
-Receive: 18


« on: June 15, 2009, 01:07:04 13:07 »

Hi,  I need the drive for LCD 16X2 for Hi-tech compiler. Can anyone help ?

                     Thanks

                              Orcino
Logged
oldvan
V.I.P
Senior Member
*****
Offline Offline

Posts: 375

Thank You
-Given: 152
-Receive: 106


If the van is a Rockin'...


WWW
« Reply #1 on: June 15, 2009, 08:03:20 20:03 »

What processor do you plan to use?

Some notweorthy differences between 68XX, Z80, PIC, etc.

Did you try SEARCH?  I'm pretty sure there are plenty of examples to be found that way.
« Last Edit: June 15, 2009, 08:07:20 20:07 by oldvan » Logged

Give a man a fish and you feed him for a day.
Teach a man to fish and he will sit around in a boat drinking beer all day.
ALLPIC
V.I.P
Active Member
*****
Offline Offline

Posts: 113

Thank You
-Given: 64
-Receive: 72


« Reply #2 on: June 16, 2009, 07:52:09 07:52 »

very simple.....


#include "delay.h"
#include "always.h"


//LCD Port Definations

#define LCD_E      LATD5
#define LCD_E_TRIS   TRISD5

#define LCD_RS      LATD4
#define LCD_RS_TRIS   TRISD4

#define LCD_D4      LATB0
#define LCD_D4_TRIS   TRISB0

#define LCD_D5      LATB1   
#define LCD_D5_TRIS   TRISB1   

#define LCD_D6      LATB2   
#define LCD_D6_TRIS   TRISB2   

#define LCD_D7      LATB3   
#define LCD_D7_TRIS   TRISB3   




void lcd_write(unsigned char c);
void lcd_init(void);
void lcd_putch(const char s);
void lcd_goto(unsigned char y_pos,unsigned char x_pos);
void lcd_puts(const char *str);


/***********************************
function:- lcd_putch
returns:- Nothing
argument:- s :- require charature to show on lcd screen
************************************/

void lcd_putch(const char s)
{
    unsigned char a;
    a = s>>4;
    LCD_RS = 1;
    lcd_write(a);
    DelayUs(200);
    lcd_write(s);
    DelayUs(200);

}

/**********************************
Function:- lcd_puts
Return :- nothing (void)
argument :- requires pointer that should be in
            charactor format so that that will be print on LCD
***********************************/

void lcd_puts(const char *str)
{
    while(*str)
      lcd_putch(*str++);


}

/*********************************************
 write a byte to the LCD in 4 bit mode
 Return :- Nothing
 Argument :- Byte
*********************************************/

void lcd_write(unsigned char c)
{
    union chartype x;
    unsigned char p_data;
   
    x.byte= c;
    LCD_D4 = x.part.bit0;
    LCD_D5 = x.part.bit1;
    LCD_D6 = x.part.bit2;
    LCD_D7 = x.part.bit3;


    LCD_E = 1;
    DelayUs(200);
    LCD_E = 0;
    DelayUs(200);

}

/***************************************

 initialise the LCD - put into 4 bit mode
 Return :- Nothin
 Argument :- Nothing
 
 ****************************************/

void lcd_init(void)
{

   //iit Port Pins
   
   LCD_E = 0;   
   LCD_E_TRIS = 0;      
   
   LCD_RS = 0;         
   LCD_RS_TRIS = 0;      
   
   LCD_D4 = 0;         
   LCD_D4_TRIS = 0;      
   
   LCD_D5 = 0;         
   LCD_D5_TRIS = 0;      
   
   LCD_D6 = 0;         
   LCD_D6_TRIS = 0;      
   LCD_D7 = 0;         
   LCD_D7_TRIS    = 0;   

   //Start LCD

    LCD_E = 1;
    DelayMs(250);

    LCD_E = 0;
    DelayMs(250);

   // init LCD for 4 bit mode
   
    lcd_write(0x02);

    lcd_write(0x08);

    lcd_write(0x00);

    lcd_write(0x00);

    lcd_write(0x0e);

    lcd_write(0x00);

    lcd_write(0x06);



}








/***********************************
 *  Clear and home the LCD
 ************************************/

void lcd_clear(void)
{
    LCD_RS = 0;
    DelayMs(2);
    lcd_write(0x00);
    DelayMs(2);
    lcd_write(0x01);
    DelayMs(2);
}

/*********************************
 * Go to the specified position
postion should be starting from 1 and ending at 16.
Caution 0 will hang LCD
***********************************/

void lcd_goto(unsigned char y_pos,unsigned char x_pos)
{
    LCD_RS = 0;
    if(y_pos == 1)
        lcd_write(0x08);
    if(y_pos == 2)
        lcd_write(0x0c);
    lcd_write(0x00+x_pos);
    DelayUs(200);


}


this is for hitech picc

regards

Logged
arslanweb
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 1
-Receive: 3


« Reply #3 on: June 16, 2009, 09:37:19 09:37 »

Hi,

The code are not compet, it missing same code in lcd_write() function. It have sent one nibble, the oder nibble are not coded for sending o byte data.






Posted on: June 16, 2009, 09:31:48 09:31 - Automerged

hi,

i give a sample code



#define   LCD_EN RB7
#define   LCD_RS RB6

#define   LCD_DB4 RA0
#define   LCD_DB5 RA3
#define   LCD_DB6 RA1
#define   LCD_DB7 RA2

/////////////////////////////

#define   TRIS_EN      TRISA3
#define   TRIS_RS    TRISA2

#define   TRIS_DB4    TRISA7
#define   TRIS_DB5    TRISA6
#define   TRIS_DB6    TRISA1
#define   TRIS_DB7    TRISA0


#define   LCD_STROBE()   ((LCD_EN = 1),(LCD_EN=0))




/* write a byte to the LCD in 4 bit mode */

void
lcd_write(unsigned char c)
{
   DelayUs(40);
   
   //LCD_DATA = ( ( c >> 4 ) & 0x0F );
   if ( c & 0b00010000 )
      LCD_DB4 = 1;
   else
      LCD_DB4 = 0;

   if ( c & 0b00100000 )
      LCD_DB5 = 1;
   else
      LCD_DB5 = 0;

   if ( c & 0b01000000 )
      LCD_DB6 = 1;
   else
      LCD_DB6 = 0;

   if ( c & 0b10000000 )
      LCD_DB7 = 1;
   else
      LCD_DB7 = 0;
      
   
   LCD_STROBE();
   
   //LCD_DATA = ( c & 0x0F );
   if ( c & 0b00000001 )
      LCD_DB4 = 1;
   else
      LCD_DB4 = 0;

   if ( c & 0b00000010 )
      LCD_DB5 = 1;
   else
      LCD_DB5 = 0;

   if ( c & 0b00000100 )
      LCD_DB6 = 1;
   else
      LCD_DB6 = 0;

   if ( c & 0b00001000 )
      LCD_DB7 = 1;
   else
      LCD_DB7 = 0;
   
   
   LCD_STROBE();
}

Logged
ALLPIC
V.I.P
Active Member
*****
Offline Offline

Posts: 113

Thank You
-Given: 64
-Receive: 72


« Reply #4 on: June 16, 2009, 01:10:55 13:10 »

Dear My Friend arslanweb
last 3 years I am useing this code and working perfectly without no problems what so ever

I think you are not aware of always.h given by hitech that's why you can't able to understand a code.....

best regards
Logged
sam_des
Active Member
***
Offline Offline

Posts: 221

Thank You
-Given: 47
-Receive: 111


« Reply #5 on: June 16, 2009, 07:22:39 19:22 »

Hi,

@ALLPIC,

Code:
write a byte to the LCD in 4 bit mode
 Return :- Nothing
 Argument :- Byte
*********************************************/
void lcd_write(unsigned char c)
{
    union chartype x;
    unsigned char p_data;
    
    x.byte= c;
    LCD_D4 = x.part.bit0;
    LCD_D5 = x.part.bit1;
    LCD_D6 = x.part.bit2;
    LCD_D7 = x.part.bit3;

    LCD_E = 1;
    DelayUs(200);
    LCD_E = 0;
    DelayUs(200);
}
Yes, you seem to writing only lower nibble of the byte received. Then all your code calls the lcd_write() function twice, once for upper nibble & then for lower nibble. It is ok, no doubt, but is little inefficient in terms of code & speed  Wink

We can write the same function as,
Code:
#define LCD_DATA_PORT      LATB
#define LCD_DATA_MASK     0b11110000                // Lower 4-bits as DB7-DB4
#define LCD_DATA              1
#define LCD_CMD                0

void lcd_write_nibble( unsigned char nib )
{
  LCD_DATA_PORT &= LCD_DATA_MASK;                // Make sure data lines are clear
  LCD_DATA_PORT |= nib;                                   // Writing nibble
  LCD_E = 1;
  NOP();
  NOP();
  LCD_E = 0;                                                     // Strobe EN line
  DelayUs( 200 );                                               // Inter-nibble delay
}

void lcd_write( bool mode, unsigned char c )
{
  if( LCD_CMD == mode ) {                                   // Command
    LCD_RS = 0;
  } else {                                                          // Data
    LCD_RS = 1;
  }
  lcd_write_nibble( c >> 4 );                                // Upper nibble first
  lcd_write_nibble( c & 0x0f );                              // Lower nibble now
  DelayUs( 200 );                                               // Inter-byte delay
}

Now you can easily call this from anywhere, whether you're writing command or data.
e.g. For clearing LCD, lcd_write( LCD_CMD, 0x01 ) or
      For printing a char, lcd_write( LCD_DATA, 'c' )

I also suggest you that take another look at your code,there are few other bits of code which can be optimized. In my opinion a good code, is the one which passes through the compiler with all optimizations on & comes out without getting much optimized because you've written code in optimized way in the first place.

Hope that helps,
sam_des
« Last Edit: June 16, 2009, 07:27:50 19:27 by sam_des » Logged

Never be afraid to do something new. Remember Amateurs built the Ark, Professionals built the Titanic !
ALLPIC
V.I.P
Active Member
*****
Offline Offline

Posts: 113

Thank You
-Given: 64
-Receive: 72


« Reply #6 on: June 17, 2009, 06:47:48 06:47 »

Hi sam_des
                Really thanks for suggestion I really like this Idea.

Yes I am useing this for my older version where I am putting direct port to LCD but now a days like PIC16F886 or PIC16F887 if I need to use lot of ADC then there will be very less chances of gating all port dedicated to LCD so that I am useing this method. I know this will be slower side.

If you can please tell me for such case how I can make code more faster that really going to help me

regards


 
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC