lcd.c DC Powersupply

/**
******************************************************************************
* @file main.c
* @author hoangnv.3i@ggmail.com
* @version V1.0
* @date 19/5/2018
* @brief example1
******************************************************************************
**/

#include “lcd1602.h”

void LCD_Delay_US( uint8_t num)
{
uint8_t index = 0;

for(index = (5 * num); index != 0; index–)
{
}
}
//————————-
//————————-

void LCD_STROBE(void)
{
GPIO_WriteHigh(LCD_EN_GPIO,LCD_EN);
LCD_Delay_US(30);
GPIO_WriteLow(LCD_EN_GPIO,LCD_EN);
LCD_Delay_US(30);
}
//————————-
void LCD_DATA(u8 cX )
{
if((cX&0x01)>=1)
{
GPIO_WriteHigh(LCD_D4_GPIO, LCD_D4);
}
else
{
GPIO_WriteLow(LCD_D4_GPIO, LCD_D4);
};
//——-
if((cX&0x02)>=1)
{
GPIO_WriteHigh(LCD_D5_GPIO, LCD_D5);
}
else
{
GPIO_WriteLow(LCD_D5_GPIO, LCD_D5);
};
//——-
if((cX&0x04)>=1)
{
GPIO_WriteHigh(LCD_D6_GPIO, LCD_D6);
}
else
{
GPIO_WriteLow(LCD_D6_GPIO, LCD_D6);
};
//——-
if((cX&0x08)>=1)
{
GPIO_WriteHigh(LCD_D7_GPIO, LCD_D7);
}
else
{
GPIO_WriteLow(LCD_D7_GPIO, LCD_D7);
};

}
//————————–
void lcd_write(u8 c)
{
//LCD_Delay_US(10);
LCD_DATA( c >> 4 );
LCD_STROBE();
LCD_DATA( c );
LCD_STROBE();
}
//————————–
void lcd_clear(void)
{
GPIO_WriteLow(LCD_RS_GPIO,LCD_RS);
lcd_write(0x01);
LCD_Delay_US(2000);
}

//—————————
void lcd_putchar(u8 c)
{
// write characters
GPIO_WriteHigh(LCD_RS_GPIO,LCD_RS);
lcd_write( c );
}
//—————————
void lcd_puts(char *c)
{
// write characters
while( *c != 0 )
{
GPIO_WriteHigh(LCD_RS_GPIO,LCD_RS);
lcd_write( *c );
c++ ;
};
}

//—————————
void lcd_gotoxy(u8 row,u8 col)
{
GPIO_WriteLow(LCD_RS_GPIO,LCD_RS);

switch(row)
{
case 0 : lcd_write( 0x80 + col ) ;
break ;
case 1 : lcd_write( 0xC0 + col ) ;
break ;
case 2 : lcd_write( 0x94 + col ) ;
break ;
case 3 : lcd_write( 0xD4 + col ) ;
break ;
};
}
//————————–

/* initialise the LCD – put into 4 bit mode */
void lcd_init(void)
{
uint16_t i;

for(i=0;i<10000;i++)
{
LCD_Delay_US(1500); // wait 15mSec after power applied,
};

GPIO_WriteLow(LCD_RS_GPIO,LCD_RS);
GPIO_WriteLow(LCD_EN_GPIO,LCD_EN);

LCD_Delay_US(1500); // wait 15mSec after power applied,
LCD_DATA(0x03);
LCD_STROBE();
LCD_Delay_US(5000);
LCD_STROBE();
LCD_Delay_US(200);
LCD_STROBE();
LCD_Delay_US(200);
LCD_DATA(2); // Four bit mode
LCD_STROBE();

lcd_write(0x28); // Set interface length
lcd_write(0x0C); // Display On, Cursor On, Cursor Blink
lcd_clear(); // Clear screen
lcd_write(0x6); // Set entry Mode

for(i=0;i<10000;i++)
{
LCD_Delay_US(1500); // wait 15mSec after power applied,
};
}

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *