반응형
- 시뮬레이터 -> 프로테우스 8.1 VSM
- 컴파일러 -> 코드비전 2.05
"Download" Proteus File - [Proteus] C_LCD_4Bit.zip
#include <mega128.h> #include <delay.h> #define LCD_PORT_DIR DDRB #define LCD_PORT PORTB #define ENABLE PORTB |= 0x04 #define DISABLE PORTB &= ~0x04 void ToggleEpinOfLCD(void) { ENABLE; delay_us(100); DISABLE; delay_us(100); } //명령어 쓰기 함수 void instruction_out(unsigned char b) { // 상위 4BIT 출력 LCD_PORT = b & 0xF0; ENABLE; //E = 1 DISABLE; //E = 0 //하위 4BIT 출력 LCD_PORT = (b << 4) & 0xF0; ENABLE; //E = 1 DISABLE; //E = 0 delay_ms(30); } //LCD에 한문자 출력 함수 void char_out(unsigned char b) { LCD_PORT = (b & 0xF0) | 0x01; ENABLE; //E = 1 DISABLE; //E = 0 LCD_PORT = ((b << 4) & 0xF0) | 0x01; ENABLE; //E = 1 DISABLE; //E = 0 delay_ms(30); } //문자열 출력 함수 void string_out(unsigned char b, char *str) { unsigned int i = 0; //LCD 위치 지정 instruction_out(b); //NULL 문자를 만날 때 까지 캐릭터 출력 do{ char_out(str[i]); } while(str[++i]!='\0'); } // PORT 초기화 void Port_Init(void) { //PORTB 출력 LCD_PORT_DIR = 0xFF; //초기 값 LCD_PORT = 0x00; } // LCD초기화 void init_LCD(void) { delay_ms(40); LCD_PORT &= 0x0F; LCD_PORT |= 0x30; ToggleEpinOfLCD(); // 펄스 delay_ms(6); LCD_PORT &= 0x0F; LCD_PORT |= 0x30; ToggleEpinOfLCD(); // 펄스 delay_us(300); LCD_PORT &= 0x0F; LCD_PORT |= 0x30; ToggleEpinOfLCD(); // 펄스 delay_ms(2); LCD_PORT &= 0x0F; LCD_PORT |= 0x20; ToggleEpinOfLCD(); // 펄스 delay_ms(2); instruction_out(0x28); instruction_out(0x0C); instruction_out(0x01); instruction_out(0x06); } void main(void) { delay_ms(100); // 포트 초기화 Port_Init(); delay_ms(500); // LCD 초기화 init_LCD(); // 출력문자열 string_out(0x80, "Hello World!"); string_out(0xC0, "--Lcd Display!--"); while(1) { ; } }
반응형
'마이컴 & 프로테우스 VSM > ATmega128' 카테고리의 다른 글
- [Codevision] 그래픽 LCD ("KS0108" 128 x 64) (4) | 2016.04.04 |
---|---|
- [Codevision] 그래픽 LCD ("T6963C" 240 x 128) (0) | 2016.03.29 |
- [Codevision] 캐릭터 LCD 4비트 제어 ("sprintf" 사용) (0) | 2016.03.21 |
- [Codevision] 캐릭터 LCD 커스텀폰트 ("lcd.h" 사용) (0) | 2016.03.17 |
- [Codevision] 캐릭터 LCD 4비트 제어 ("lcd.h" 사용) (0) | 2016.03.17 |