원래 링크의 카페는 막혀있어서
회로 구성이라던가 이런걸 알 수 없지만 참고용으로 링크 저장
데이터시트 상으로는 ns 급으로 쉬어주어야 하지만
AVR ATmega128 16MHz라고 해도
명령어 처리에 10ns 급 정도의 딜레이는 가볍게 생기니까
그런건 무시하고 바로바로 포트에 값을 넣어 주는 듯 하다.
[링크 : http://blog.daum.net/irobotavr/668278] 8bit 통신
4bit 통신예제. PORTB로 되어있음. 하지만.. 작동이 안되네?
[링크 : http://www.avrprojects.net/.../avr-c-programming-tutorials/112-4-bit-lcd-interface] 4bit 통신
---
PORTC 에
7654(DATA) 2(E) 1(RW) 0(RS) 로 회로가 구성된 경우로 포팅한 녀석.
이 소스는 문자가 무언가는 나오지만 제대로 나오지 않는 문제가 있다.
하지만 이 소스를 통해 CLCD를 초기화할 경우 제대로 되기에 초기화 부분을 분석해서 내 소스에 적용하게 됨.
            
                    
                    
  
    
				
							
				
				
				
				
				
				
				
			회로 구성이라던가 이런걸 알 수 없지만 참고용으로 링크 저장
데이터시트 상으로는 ns 급으로 쉬어주어야 하지만
AVR ATmega128 16MHz라고 해도
명령어 처리에 10ns 급 정도의 딜레이는 가볍게 생기니까
그런건 무시하고 바로바로 포트에 값을 넣어 주는 듯 하다.
[링크 : http://blog.daum.net/irobotavr/668278] 8bit 통신
4bit 통신예제. PORTB로 되어있음. 하지만.. 작동이 안되네?
| // used pins on port B 
#define LCD_DB4 0    // PORTB.0  
#define LCD_DB5 1    // PORTB.1 
#define LCD_DB6 2    // PORTB.2  
#define LCD_DB7 3    // PORTB.3 
#define LCD_E  6     // PORTB.6 Enable  
#define LCD_RS 7     // PORTB.7 Register Select 
 | 
---
PORTC 에
7654(DATA) 2(E) 1(RW) 0(RS) 로 회로가 구성된 경우로 포팅한 녀석.
이 소스는 문자가 무언가는 나오지만 제대로 나오지 않는 문제가 있다.
하지만 이 소스를 통해 CLCD를 초기화할 경우 제대로 되기에 초기화 부분을 분석해서 내 소스에 적용하게 됨.
// used pins on port B
#define LCD_DB4 4    // PORTB.0 
#define LCD_DB5 5    // PORTB.1
#define LCD_DB6 6    // PORTB.2 
#define LCD_DB7 7    // PORTB.3
#define LCD_E  2     // PORTB.6 Enable 
#define LCD_RS 0     // PORTB.7 Register Select
//LCD commands
#define LCD_CLR 		0x01    // clear display
#define LCD_HOME 		0x02    // return home
#define LCD_INC 		0x06    // Increment, display freeze
#define LCD_MOV 		0x10    // Cursor move, not shift
#define LCD_OFF         0x08    // lcd off
#define LCD_ON          0x0C    // lcd on             
#define LCD_BLINK_ON	0x0D    // blink on              
#define LCD_CURSOR_ON	0x0E    // cursor on               
#define LCD_ALL_ON	    0x0F    // cursor on /  blink on
#define LCD_LINE1  		0x80    // cursor Pos on line 1 (or with column)
#define LCD_LINE2  		0xC0    // cursor Pos on line 2 (or with column)
unsigned char chr,data,pos;
// writes a char to the LCD
void LCD_char(unsigned char data)
{
	PORTC = data & 0b11110000; //high nibble
	PORTC |= 1 << LCD_RS;
	PORTC |= 1 << LCD_E;
	_delay_ms(2);
	PORTC &= ~(1 << LCD_E);
	_delay_ms(2);
	PORTC = (data << 4) & 0b11110000; //low nibble
	PORTC |= 1 << LCD_RS;
	PORTC |= 1 << LCD_E;
	_delay_ms(2);
	PORTC &= ~(1 << LCD_E);
	_delay_ms(2);
}
// writes a instruction to the LCD
void LCD_inst(unsigned char inst)
{	
	PORTC = (inst & 0b11110000); //send high nibble
	PORTC &= ~(1 << LCD_RS); // set RS to instructions
	PORTC |= 1 << LCD_E;
	_delay_ms(2);
	PORTC &= ~(1 << LCD_E);
	_delay_ms(2);
	PORTC = (inst << 4) & 0b11110000; //send low nibble
	PORTC |= 1 << LCD_E;
	_delay_ms(2);
	PORTC &= ~(1 << LCD_E);
	_delay_ms(2);	
}
// clear display
void LCDclr(void)
{
	LCD_inst (LCD_CLR);
}
// return home
void LCDhome(void)
{
	LCD_inst (LCD_HOME);
}
// LCD off
void LCDoff(void)
{
	LCD_inst (LCD_OFF);
}
// LCD on
void LCDon(void)
{
	LCD_inst (LCD_ON);
}
// cursor on
void LCDcursor(void)
{
	LCD_inst (LCD_CURSOR_ON);
}
// blink on
void LCDblink(void)
{
	LCD_inst (LCD_BLINK_ON);
}
// cursor all on
void LCDall(void)
{
	LCD_inst (LCD_ALL_ON);
}
//go to first line
void LCDline1 (void)
{
	LCD_inst (0b10000000);
}
//go to second line
void LCDline2 (void)
{
	LCD_inst (0b11000000);
}
// goto position x,y
void LCDgoto (char x,char y)
{
	if (y == 0)			pos = 0b00000000 + x;
	else if (y == 1)	pos = 0b01000000 + x;
	LCD_inst (0b10000000 | pos);
}
//write text to the LCD
void LCDtext(char *data)
{
	while (*data)
	{
		LCD_char(*data);
		data++;
	}
}
// init LCD
void LCD_init(void)
{
	DDRC = 0xFF;  // PORTC as output
	_delay_ms(40);
	// set 4-bit mode
	PORTC = 1 << 2;
	PORTC |= 1 << LCD_E;
	_delay_ms(1);
	PORTC &= ~(1 << LCD_E);
	_delay_ms(1);
	PORTC = 1<< 2;
	PORTC |= 1 << LCD_E;
	_delay_ms(1);
	PORTC &= ~(1 << LCD_E);
	_delay_ms(1);
	PORTC = 1 << 2;
	PORTC |= 1 << LCD_E;
	_delay_ms(1);
	PORTC &= ~(1 << LCD_E);
	_delay_ms(1);
	//set 4-bit mode and 2-line
	//LCD_inst (0b00101000);
	LCD_inst (0b00101000);
	//turn on display and cursor
	LCD_inst (0b00001100);
	//clr display
	LCD_inst (LCD_CLR);
}
int main( void )
{
	LCD_init();
	LCDtext (">AVR LCD DEMO<");
	LCDgoto (2,1);
	LCDtext("Hello World!");
	LCDall();
	LCDhome();
}
'embeded > AVR (ATmega,ATtiny)' 카테고리의 다른 글
| ATmega128 + LC1628 제어하기 2 (0) | 2013.12.24 | 
|---|---|
| ATmega128 + LC1628 제어하기 1 (0) | 2013.12.24 | 
| Atmega8 으앙 쥬금!!! ㅠㅠ (0) | 2013.12.20 | 
| avr pud(pull up disable) (0) | 2013.12.19 | 
| AVR-GCC Program space (0) | 2013.12.19 | 
