◆◆ ATmega128 : LCD 제어, CG ROM 문자코드 출력 ◆◆
/*
LCD lcd.lib 이용
CG ROM 문자코드 출력 (p.257)
0311A_LCD_CG_ROM.c
*/
#include <mega128.h>
// 어셈블리
#asm
.equ __lcd_port = 0x12 ; PORTD
#endasm
#include <lcd.h>
//int ABC[] = { 0001, 0010,};
void main(void)
{
DDRD = 0xff;
PORTD = 0xff;
lcd_init(16);
lcd_putchar(0b01001001); // 첫째열, 0b01001001 -"I"
lcd_gotoxy(0,1);
lcd_putchar(0b01010100); // 둘째열, 0b01010100 - "T"
while(1);
}//end main
★◆ ATmega128 : LCD 제어, switch, LCD.h 이용 ◆★
/*
LCD
스위치 입력에 따른 문자열 출력
SW 8 - The First Basement
SW 14 - The First Floor
SW 15 - The Secone Floor
SW16 - The Third Floor
0311B_LCD_SW_ASM.c
*/
#include <mega128.h>
#asm
.equ __lcd_port = 0x12 ; PORTD(0x12)
#endasm
#include <lcd.h>
void main(void)
{
char Key;
char Line1[] = " LCD Initial "; // 초기 LCD 표시문자
DDRD = 0xff;
PORTD = 0xff;
lcd_init(16); // LCD 16 * 2 초기화
lcd_clear();
lcd_gotoxy(0,0); // 커서 위치 0번째
lcd_puts(Line1);
while(1){
Key = PINE & 0xf0; // 1111 0000
if( Key == 0xe0){ // 1110 0000
lcd_clear();
lcd_gotoxy(1,0);
lcd_putsf(" The Basement "); // The First Basement
}//endif_0xe0
else if( Key == 0xd0){ // 1101 0000
lcd_clear();
lcd_gotoxy(1,0);
lcd_putsf(" The 1st Floor "); // The First Floor
}//endelseif_0xd0
else if( Key == 0xb0 ){ // 1011 0000
lcd_clear();
lcd_gotoxy(1,0);
lcd_putsf(" The 2nd Floor "); // The Second Floor
}//endelseif_0xb0
else if( Key == 0x70 ){ // 0111 0000
lcd_clear();
lcd_gotoxy(1,0);
lcd_putsf(" The 3rd Floor "); // The Third Floor
}//endelseif_0x70
}//endwhile
}//end main
◆◆ ATmega128 : LCD 제어, switch, LCD.h 이용 + 커서 깜빡임 ◆◆
/*
LCD
스위치 입력에 따른 문자열 출력
SW 8 - The First Basement
SW 14 - The First Floor
SW 15 - The Secone Floor
SW16 - The Third Floor
>> 커서 위치 추가 (깜빡임)
0311C_LCD_SW_lcd_h.c
*/
#include <mega128.h>
#include <delay.h>
#asm
.equ __lcd_port = 0x12 ; PORTD(0x12)
#endasm
#include <lcd.h>
void main(void)
{
char Key;
char Line1[] = " LCD Initial "; // 초기 LCD 표시문자
DDRD = 0xff;
PORTD = 0xff;
lcd_init(16); // LCD 16 * 2 초기화
lcd_clear();
lcd_gotoxy(0,0); // 커서 위치 0번째 , 첫째 줄
lcd_puts(Line1);
while(1){
Key = PINE & 0xf0; // 1111 0000
if( Key == 0xe0){ // 1110 0000
lcd_clear();
lcd_gotoxy(0,0);
_lcd_ready();
_lcd_write_data(0x0e);
delay_ms(500);
_lcd_ready();
_lcd_write_data(0x0f);
lcd_putsf("The Basement"); // The First Basement
}//endif_0xe0
else if( Key == 0xd0){ // 1101 0000
lcd_clear();
lcd_gotoxy(1,0);
_lcd_ready();
_lcd_write_data(0x0e);
delay_ms(500);
_lcd_ready();
_lcd_write_data(0x0f);
lcd_putsf("The 1st Floor"); // The First Floor
}//endelseif_0xd0
else if( Key == 0xb0 ){ // 1011 0000
lcd_clear();
lcd_gotoxy(1,0);
_lcd_ready();
_lcd_write_data(0x0e);
delay_ms(500);
_lcd_ready();
_lcd_write_data(0x0f);
lcd_putsf("The 2nd Floor"); // The Second Floor
}//endelseif_0xb0
else if( Key == 0x70 ){ // 0111 0000
lcd_clear();
lcd_gotoxy(1,0);
_lcd_ready();
_lcd_write_data(0x0e);
delay_ms(500);
_lcd_ready();
_lcd_write_data(0x0f);
lcd_putsf("The 3rd Floor"); // The Third Floor
}//endelseif_0x70
}//endwhile
}//end main
◆◆ ATmega128 : LCD 제어, LCD.h 이용 + 문자 움직임 ◆◆
/*
LCD lcd.h 이용
스위치 입력에 따른 문자열 출력
>> 문자열 왼쪽/오른쪽으로 이동시키기
0311E_LCD_SW_lcd_h_flow.c
*/
#include <mega128.h>
#include <delay.h>
#asm
.equ __lcd_port = 0x12 ; PORTD(0x12)
#endasm
#include <lcd.h>
void main(void)
{
char Line1[] = "LCD Font Move!"; // 초기 LCD 표시문자
char FM = 0; // Font move
DDRD = 0xff;
PORTD = 0xff;
lcd_init(16); // LCD 16 * 2 초기화
lcd_clear();
lcd_gotoxy(0,0); // 커서 위치 0번째 , 첫째 줄
lcd_puts(Line1);
while(1){
for( FM = 0 ; FM < 5 ; FM++){
_lcd_ready();
_lcd_write_data(0x1c); // 0x1c : 문자를 오른쪽으로 이동시키는 문자값
delay_ms(500);
}//endfor
for( FM = 0 ; FM < 5 ;FM++){
_lcd_ready();
_lcd_write_data(0x18); // 0x18 : 문자를 왼쪽으로 이동시키는 코드값
delay_ms(500);
}//endfor
}//endwhile
}//end main
◆◆ ATmega128 : LCD 제어, switch, LCD.h 이용 + 문자 움직임 ◆◆