示例#1
0
文件: lcd.c 项目: nceruchalu/easypay
/*
 * LcdInit
 * Description: This initializes the LCD. This must be called before the LCD can
 *              be used.
 *              Thus this function has to be called before calling any other 
 *              LCD-interface functions.
 *              The LCD is set to the following specifications:
 *                8-bit mode, 4-line display, 5x8 font
 *                cursor INCs, display doesn't shift
 *                cursor visible, cursor blinking
 *
 * Argument:    None
 * Return:      None
 *
 * Input:       None
 * Output:      LCD
 *
 * Operation:   
 *   Really just follows standard initialization sequence. See sketch below
 *
 *   POWER ON
 *       |
 *       |  Wait time >40ms
 *      \|/
 *   FUNCTION SET (RS = 0, RW=0, DB = 0b0011NFXX) [BF cannot be checked b4 this]
 *       |
 *       |  Wait time >37us
 *      \|/
 *   FUNCTION SET (RS = 0, RW=0, DB = 0b0011NFXX) [BF cannot be checked b4 this]
 *       |
 *       |  Wait time >37us
 *      \|/
 *   DISPLAY ON/OFF control (RS = 0, RW=0, DB = 0b00001DCB)
 *       |
 *       |  Wait time >37us
 *      \|/
 *   DISPLAY Clear (RS=0, RW=0, DB=0b00000001)
 *       |
 *       |  Wait time >1.52ms
 *      \|/
 *   Entry Mode Set (RS=0, RW=0, DB=0b0000001{I/D}S)
 *       |
 *       |  Wait time >37us
 *      \|/
 *   Initialization End
 *
 * Revision History:
 *   Dec. 16, 2012      Nnoduka Eruchalu     Initial Revision
 */
void LcdInit(void)
{
  LCD_DATA_TRIS = 0x00;        /* setup LCD IO ports as outputs */
  LCD_E_TRIS = 0;
  LCD_RW_TRIS = 0;
  LCD_RS_TRIS = 0;
  
  LCD_DATA_LAT = 0;            /* clear IO lines*/
  CLEAR_RS(); CLEAR_RW(); CLEAR_E();
  
  __delay_ms(40);              
  
  LCD_DATA_LAT = LCD_FUNC_SET; /* FUNCTION SET, done manually to prevent a */
  LCD_STROBE();                /* BF check before next command */
  __delay_us(40);
  
  LcdCommand(LCD_FUNC_SET);    /* FUNCTION SET, again done manually */
  LCD_STROBE();
  __delay_us(40);
  
  LcdCommand(LCD_ON);          /* DISPLAY ON/OFF control: Turn display on */
  __delay_us(40);
  
  LcdCommand(LCD_CLEAR);        /* DISPLAY Clear */
  __delay_ms(2);
  
  LcdCommand(LCD_ENTRY_MD);     /* ENTRY mode set */
  
  GenSpecChars();               /* Now create some special characters */
}
示例#2
0
//-------------------------------
void lcd_cmd(int8u_t data, int16u_t loop)
{/* LCD ELEMENTARY COMMAND */
 HIGHBITS(data);
 LCD_STROBE(0);
 LOWBITS(data);
 LCD_STROBE(loop); // busy delay
}
示例#3
0
//-------------------------------
void lcd_cmd(int8u_t data)
{/* LCD ELEMENTARY COMMAND */
 HIGHBITS(data);
 LCD_STROBE(20);
 LOWBITS(data);
 LCD_STROBE(20); // busy delay
}
示例#4
0
//-------------------------------
void lcd_config(int8u_t param)
{/* CONFIGURE THE DISPLAY */
 HIGHBITS(param); // 4-bit, two lines, 5x8 pixel
  LCD_STROBE(0); // change 8-bit interface to 4-bit interface
  LCD_STROBE(0); // init 4-bit interface
 LOWBITS(param);
  LCD_STROBE(0);
}
示例#5
0
文件: lcd.c 项目: ruanpablom/Nadzoru
/* initialize the LCD */
void
lcd_init(unsigned char mode)
{
    char init_value;

    fourbit     = 0;
    if (mode == FOURBIT_MODE){
        fourbit = 1;
        init_value = 0x30;
    }else{
        init_value = 0x3F;
    }
    LCD_RS = 0;
    LCD_EN = 0;
    LCD_RW = 0;
    LCD_RS_TRIS    = OUTPUT_PIN;
    LCD_EN_TRIS    = OUTPUT_PIN;
    LCD_RW_TRIS    = OUTPUT_PIN;
    delay_ms(15);
    if(fourbit){
        LCD_DATA_TRIS  = OUTPUT_PIN;
        lcd_fourbit_cmd( init_value );
    } else {
        LCD_DATA_TRIS  = OUTPUT_PIN;
        LCD_DATA     = init_value;
        LCD_STROBE();
    }
    delay_ms(5);
    if(!fourbit){
        lcd_fourbit_cmd( init_value );
    } else {
        LCD_DATA     = init_value;
        LCD_STROBE();
    }
    delay_us(200);
    if(!fourbit){
        lcd_fourbit_cmd( init_value );
    } else {
        LCD_DATA     = init_value;
        LCD_STROBE();
    }

    if (fourbit){
        LCD_WAIT; //may check LCD busy flag, or just delay a little, depending on lcd.h
        lcd_fourbit_cmd( 0x20 );

        lcd_cmd(0x28); // Function Set
    }else{
        lcd_cmd(0x38);
    }
    lcd_cmd(0xF); //Display On, Cursor On, Cursor Blink
    lcd_cmd(0x1); //Display Clear
    lcd_cmd(0x6); //Entry Mode
    lcd_cmd(0x80); //Initialize DDRAM address to zero
}
/* Write a byte to the LCD in 4 bit mode */
void lcd_write(unsigned char c)
{	if(c & 0x80) LCD_D7=1; else LCD_D7=0;
	if(c & 0x40) LCD_D6=1; else LCD_D6=0;
	if(c & 0x20) LCD_D5=1; else LCD_D5=0;
	if(c & 0x10) LCD_D4=1; else LCD_D4=0;
	LCD_STROBE();
	if(c & 0x08) LCD_D7=1; else LCD_D7=0;
	if(c & 0x04) LCD_D6=1; else LCD_D6=0;
	if(c & 0x02) LCD_D5=1; else LCD_D5=0;
	if(c & 0x01) LCD_D4=1; else LCD_D4=0;
	LCD_STROBE();
	delay_50us();
}
/* send a command to the LCD */
void
lcd_cmd(unsigned char c)
{
	LCD_WAIT; // may check LCD busy flag, or just delay a little, depending on lcd.h

	if (fourbit) {
		LCD_DATA = ( c & 0xF0 );
		LCD_STROBE();
    		LCD_DATA =  ( ( c << 4 ) & 0xF0 );  
		LCD_STROBE();
	} else {
		LCD_DATA = c;
		LCD_STROBE();
	}
}
示例#8
0
文件: lcd.c 项目: nceruchalu/easypay
/*
 * LcdCommand
 * Description: This procedure simply writes a command byte to the LCD.
 *              It does not return until the LCD's busy flag is cleared.
 *
 * Argument:    c: command byte
 * Return:      None
 *
 * Input:       None
 * Output:      LCD
 * 
 * Operation:   Send the byte, then wait for the BF to be cleared.
 *
 * Revision History:
 *   Dec. 16, 2012      Nnoduka Eruchalu     Initial Revision
 */
void LcdCommand(unsigned char c)
{
  LCD_DATA_LAT = c;           /* put data on output port */
  CLEAR_RS();                 /* RS = 0: Command */
  CLEAR_RW();                 /* R/W = 0: Write */
  LCD_STROBE();
  LcdWaitBF();               /* dont exit until the LCD is no longer busy */
}
/* send data to the LCD */
void
lcd_data(unsigned char c) {
	LCD_WAIT; // may check LCD busy flag, or just delay a little, depending on lcd.h

	LCD_DATA = 0;
	LCD_RS = 1;
	if (fourbit) {
    	LCD_DATA = ( c & 0xF0 );
		LCD_STROBE();
		LCD_DATA &= 0x0F;
		LCD_DATA =  ( ( c << 4 ) & 0xF0 );  
		LCD_STROBE();
	} else {
		LCD_DATA = c;
		LCD_STROBE();
	}
	LCD_RS = 0;
}
示例#10
0
/* Initialise the LCD - put into 4 bit mode */
void lcd_init(void)
{	LCD_RS = 0;	
	LCD_EN = 0;
	delay_100ms();			// Wait 100ms after power applied
	LCD_D4 = 1;		
	LCD_D5 = 1; 
	LCD_STROBE();	
	delay_2ms();			// Wait 6ms
	delay_2ms();
	delay_2ms();
	LCD_STROBE();	
	delay_2ms();
	LCD_STROBE();	
	delay_2ms();
	LCD_D4 = 0;				// Set 4 bit mode
	LCD_STROBE();	
	delay_50us();	
	lcd_cmd(0b00101000);	// Set interface length 4-bit, 2-line, 5x8 dots display
	lcd_cmd(0b00001100);	// Display On, Cursor OFF, Cursor Blink OFF
	lcd_cmd(0b00000110);	// Set entry Mode
	lcd_clear();			// Clear screen
}
示例#11
0
文件: lcd.c 项目: ruanpablom/Nadzoru
void lcd_fourbit_cmd(unsigned char c){
    LCD_DATA = ( c & 0xF0 ) | ( LCD_DATA & 0x0F );
    LCD_STROBE();
}