마이컴 & 프로테우스 VSM/ATmega128
- [Codevision] 캐릭터 LCD 8비트 제어
메가아재
2016. 4. 7. 10:24
반응형
- 시뮬레이터 -> 프로테우스 8.1 VSM
- 컴파일러 -> 코드비전 2.05
"Download" Proteus File - [Proteus] C_LCD_8Bit.zip
"Download" Source Code - [Codevision] C_LCD_8Bit.zip
<Proteus Circuit>
<Source Code>
#include <mega128.h> #include <delay.h> #define LCD_RW PORTB.1 #define LCD_RS PORTB.0 #define LCD_E PORTB.2 #define LCD_EN {PORTB.2 = 0; PORTB.2 = 1;} #define DATA PORTE void Port_Init(void) { DDRB = 0xFF; PORTB = 0x00; DDRE = 0xFF; PORTB = 0x00; } void E_Pulse(void) { LCD_E = 1; delay_ms(5); LCD_E = 0; } void LCD_DATA(unsigned char data) { DATA = data; LCD_EN; } void Func_set(void) { LCD_RW = 0; LCD_RS = 0; LCD_DATA(0x38); E_Pulse(); } void Init_LCD(void) { LCD_E = 0; delay_ms(15); Func_set(); delay_ms(10); Func_set(); delay_us(150); Func_set(); LCD_DATA(0x0F); E_Pulse(); LCD_DATA(0x06); E_Pulse(); } void lcd_char(char s) { LCD_RS = 1; LCD_DATA(s); E_Pulse(); } void lcd_disp(char x, char y) { LCD_RS = 0; LCD_RW = 0; switch(y) { case 0 : LCD_DATA(x + 0x80); break; case 1 : LCD_DATA(x + 0xC0); break; case 2 : LCD_DATA(x + 0x80 + 20); break; case 3 : LCD_DATA(x + 0xC0 + 20); break; } E_Pulse(); } void String_Out(char x, char y, char *str) { unsigned char i = 0; lcd_disp(x, y); do{ lcd_char(str[i]); } while(str[++i]!='\0'); } void main(void) { Port_Init(); Init_LCD(); String_Out(0, 0, "Character LCD"); String_Out(0, 1, "8 Bit Control"); while(1) { ; } }
반응형