//Project: HkLCD.c //LCD Use Port(DATA): PORTC Write //LCD Use Port(Control):PORTA Write(pin5,6,7) //CPU Type: Atmel AVR8535,8515,103 //Clock Frequency: 4.9152Mhz //Comfiler: AvrEdit3.1(AVRGCC) //Date: 2001/08/05 //Author: hwang hae kwon #include <io.h> void delay( int del); #define PortA_In_Out DDRA //A 입출력 설정 #define PortC_In_Out DDRC //C 입출력 설정 #define LCD_PORT_OUT_Bit PORTA #define LCD_PORT_OUT PORTC #define LCD_PORT_INPUT PINA #define LCD_PORT_INPUT PINC #define LCD_RS 5 // PORT C LCD 4 #define LCD_RW 6 // PORT C LCD 5 #define LCD_E 7 // PORT C LCD 6 #define PORT_IN 0x00 //포트 입력 #define PORT_OUT 0xff //포트 출력 //---------------------- #include <lcd2_16.h> //---------------------- void delay( int del) { while ( del--); } //----------------------- void port_init(void) { outp(PORT_OUT,PortA_In_Out); //A PORT모두 출력 outp(PORT_OUT,PortC_In_Out); // 모두 출력 } //-------------------------- void main(void) { port_init(); lcd_init(); lcd_clr(); lcd_string_out(0,0,"HWANG HAE KWON"); lcd_string_out(0,1," AvrEdit Test "); } |
//Project: LCD2*16.h
//LCD Use Port(DATA): PORTC Write
//LCD Use Port(Control):PORTA Write(pin5,6,7)
//CPU Type: Atmel AVR8535,8515,103
//Clock Frequency: 4.9152Mhz
//Comfiler: AvrEdit3.1(AVRGCC)
//Date: 2001/08/05
//Author: hwang hae kwon
void lcd_busy_check(void)// lcdd Busy Check Routine
{
unsigned char busy_data;
outp(PORT_IN,PortC_In_Out);
sbi(LCD_PORT_OUT_Bit,LCD_E);
do
{
cbi(LCD_PORT_OUT_Bit,LCD_RS);
sbi(LCD_PORT_OUT_Bit,LCD_RW);
busy_data=LCD_PORT_INPUT;
}
while(busy_data & 0x80);
cbi(LCD_PORT_OUT_Bit,LCD_E);
outp(PORT_OUT,PortC_In_Out);
}
//-------------------------------------------------
void lcd_instructionset(unsigned char value)
{ //1000 0000=bysy 0X80
//0000 0000=write ok 0X00
lcd_busy_check();
cbi(LCD_PORT_OUT_Bit,LCD_RW);
cbi(LCD_PORT_OUT_Bit,LCD_RS);
sbi(LCD_PORT_OUT_Bit,LCD_E);
delay(10);
outp(value,LCD_PORT_OUT);
//LCD_PORT_OUT=value
delay(10);
cbi(LCD_PORT_OUT_Bit,LCD_RW);
cbi(LCD_PORT_OUT_Bit,LCD_RS);
cbi(LCD_PORT_OUT_Bit,LCD_E);
delay(10);
}
//-----------------------------------------------
void lcd_clr(void)
{
lcd_instructionset(0x01);
}
//----------------------------------------------
void lcd_init(void)
{
lcd_instructionset(0x38);
lcd_instructionset(0x0c);
lcd_instructionset(0x0e);
lcd_instructionset(0x0f);
lcd_instructionset(0x04);
lcd_instructionset(0x06);
lcd_instructionset(0x02);
lcd_instructionset(0x01);
}
//---------------------------------------------
void LCD_home(void)
{
lcd_instructionset(0x03);
}
void LCD_clear(void)
{
lcd_instructionset(0x01);
}
void LCD_curse_leftt(void)
{
lcd_instructionset(0x10);
}
void LCD_curse_right(void)
{
lcd_instructionset(0x14);
}
void LCD_curse_ON(void)
{
lcd_instructionset(0x0f);
}
void LCD_curse_OFF(void)
{
lcd_instructionset(0x0d);
}
//-------------------------------------------------
void password_char( int i,unsigned char pass)
{
lcd_instructionset(i);
cbi(LCD_PORT_OUT_Bit,LCD_RW);
sbi(LCD_PORT_OUT_Bit,LCD_RS);
sbi(LCD_PORT_OUT_Bit,LCD_E);
delay(50);
//LCD_PORT_OUT=pass;
outp(pass,LCD_PORT_OUT);
delay(50);
cbi(LCD_PORT_OUT_Bit,LCD_RW);
sbi(LCD_PORT_OUT_Bit,LCD_RS);
cbi(LCD_PORT_OUT_Bit,LCD_E);
delay(50);
}
//---------------------------------------------------
void lcd_char_position(char x, char y)
{
unsigned char position;
if(y>1)y=1;
if(x>15)x=15;
position=y?x+0xc0:x+0x80;
lcd_instructionset(position);
}
//-------------------------------------------------
void lcd_out(unsigned char ch)
{
//lcd_busy_check();
cbi(LCD_PORT_OUT_Bit,LCD_RW);
sbi(LCD_PORT_OUT_Bit,LCD_RS);
sbi(LCD_PORT_OUT_Bit,LCD_E);
delay(50);
//LCD_PORT_OUT=ch;
outp(ch,LCD_PORT_OUT);
delay(50);
cbi(LCD_PORT_OUT_Bit,LCD_RW);
sbi(LCD_PORT_OUT_Bit,LCD_RS);
cbi(LCD_PORT_OUT_Bit,LCD_E);
delay(50);
}
//-----------------------------------------------
void lcd_char_out(char x1, char y1, unsigned char text1)
{
lcd_char_position(x1,y1);
lcd_out(text1);
}
//----------------------------------------------
void lcd_string_out(char x, char y, unsigned char *text)
{
lcd_char_position(x,y);
while(*text)
{
lcd_out(*(text++));
}
}
//---------------------------------------------
void lcd_Lne1_clr(void)
{
unsigned int i;
for(i=0;i<16;i++)
{ //x, y
lcd_char_out(i,0, ' ');
}
}
//--------------------------------------------
void lcd_Line2_clr(void)
{
unsigned int i;
for(i=0;i<16;i++)
{
lcd_char_out(i,1, ' ');
}
}
//--------------------------------------------
void lcd_user_clear(char x, char y)
{
lcd_char_out(x,y, ' ');
}