lcd_8.h

Sample project for SX28 that reads the temperature of a component I2C, the DS75, and posts it on a LCD (by B. Billy).



/******************************************************************************
 This program is an example how to use the C2C-Pic-Compiler

 Author: B. Billy
 Version 1.1
 Date: 26 jul 2003
 Comments and necessary improvment, please mail: billytch@yahoo.fr
 
 Required hardware: LCD-display 8bits data
 
 Description:
 This program shows how to use a Lcd-display
 
**********************************************************************************/
/*
void ecrit_ctl_lcd( void );
void put_lcd( char valeur ) {
void printf_lcd( const char* valeur );
void lcd_off(void);
void lcd_on(void);
void home_lcd( void );
void clr_lcd( void );
void dec2bin_lcd (char wr_byte);
void lcd_line2(void);
void lcd_shift_R(void);
*/

void ecrit_ctl_lcd( void ) {
   clear_bit(LCDCTL,E);
   clear_bit(LCDCTL,RS);
   clear_bit(LCDCTL,RW);
   delay_us(2);
    set_bit(LCDCTL,E);
   delay_us(2);
    clear_bit(LCDCTL,E);
   delay_us(40);
}

void put_lcd( char valeur ) {
   clear_bit(LCDCTL,E);
   clear_bit(LCDCTL,RS);
   clear_bit(LCDCTL,RW);
   delay_us(2);

   LCDDATA=valeur;

    clear_bit(LCDCTL,E);
   clear_bit(LCDCTL,RS);
   clear_bit(LCDCTL,RW);
   set_bit(LCDCTL,E);
    set_bit(LCDCTL,RS);
   delay_us(2);

    clear_bit(LCDCTL,E);
   delay_us(1);
    LCDDATA=0;
}

void printf_lcd( const char* valeur ) {
   char i=0;
   while( valeur[i] != 0)
   {
   clear_bit(LCDCTL,E);
   clear_bit(LCDCTL,RS);
   clear_bit(LCDCTL,RW);
   delay_us(2);

   LCDDATA=valeur[i++];
   clear_bit(LCDCTL,E);
   clear_bit(LCDCTL,RS);
   clear_bit(LCDCTL,RW);
    set_bit(LCDCTL,E);
    set_bit(LCDCTL,RS);

   delay_us(2);
   clear_bit(LCDCTL,E);
   delay_us(40);
   }
   clear_bit(LCDCTL,E);
   clear_bit(LCDCTL,RS);
   clear_bit(LCDCTL,RW);
}


void init_lcd(void) {
   //sequence for 2 lines
   delay_ms(50);
   LCDDATA=0x38;  /* 8-bit, 2 lines , 5*8 */
   ecrit_ctl_lcd();
   LCDDATA=0x0C;  /* Display on, Cursor off */
   ecrit_ctl_lcd();
   LCDDATA=0x06;  /* entry mode- Inc addr, no shift */
   ecrit_ctl_lcd();
   LCDDATA=0x01;     /* Clear Display */
   ecrit_ctl_lcd();
   LCDDATA=0x02;     /* return home*/
   ecrit_ctl_lcd();
   delay_ms(2);
}

void lcd_off(void) {
    LCDDATA=0x08;
   ecrit_ctl_lcd();
}

void lcd_on(void) {
    LCDDATA=0x0C;
   ecrit_ctl_lcd();
}

void home_lcd( void ) {
   LCDDATA=2;
   ecrit_ctl_lcd();
   delay_ms(2);
}

void clr_lcd( void ) {
   LCDDATA=1;
   ecrit_ctl_lcd();
   delay_ms(1);
}
void lcd_line2(void) {
   LCDDATA=0xC0;
   ecrit_ctl_lcd();
}

void lcd_shift_R(void) {
   LCDDATA=00011100b;
   ecrit_ctl_lcd();
}

void dec2bin_lcd (char wr_byte) {
   char i=0;
    while(i++<8) {   //1 OCTET
      if (wr_byte & 0x80 ) printf_lcd("1");
        else printf_lcd("0");
        wr_byte = wr_byte << 1;
     }
}



http://www.sourceboost.com/home.html

Copyright © 2002-2006 SourceBoost Technologies