#include <mega128.h>
#include <delay.h>
#define LCD_RS PORTA.0
#define LCD_RW PORTA.1
#define LCD_EN PORTA.2
#define LCD_Data PORTA
int count_2msec = 0;
void LCD_E(void)
{
LCD_EN = 1;
delay_us(250);
LCD_EN = 0;
}
void LCD_Command(unsigned char rs, unsigned char rw, unsigned char data)
{
LCD_RS = rs;
LCD_RW = rw;
LCD_Data = ((LCD_Data & 0x0f) | (data & 0xf0));
LCD_E();
LCD_Data = ((LCD_Data & 0x0f) | ((data<<4) & 0xf0));
LCD_E();
delay_ms(2);
}
void LCD_Init(void)
{
delay_ms(30);
LCD_Command(0,0,0x20);
delay_ms(10);
LCD_Command(0,0,0x20);
delay_us(200);
LCD_Command(0,0,0x20);
LCD_Command(0,0,0x20);
LCD_Command(0,0,0x28);
LCD_Command(0,0,0x0C);
LCD_Command(0,0,0x01);
LCD_Command(0,0,0x06);
}
void main(void)
{
DDRC = 0xff;
PORTC = 0xff;
DDRA = 0xff;
LCD_Init();
TIMSK = 0x05; // timer_counter_0, 1 mask
TCCR0 = 0x05; // 128 분주, 0.008msec
TCNT0 = 6; // 250 개
TCCR1B = 0x05; // 1024 분주
TCNT1H = 0xE1;
TCNT1L = 0x7C;
#asm("sei")
while (1){
LCD_Command(1,0,'C');
delay_ms(100);
}
}
interrupt [TIM0_OVF] void timer_0 (void)
{
TCNT0 = 6;
count_2msec++;
if( count_2msec >= 250 ) {
count_2msec = 0;
PORTC.0 = ~PORTC.0;
}
}
interrupt [TIM1_OVF] void timer_1 (void)
{
TCNT1H = 0xE1;
TCNT1L = 0x7C;
PORTC.7 = ~PORTC.7;
}
'IT > CodeVision atmega128' 카테고리의 다른 글
atmega128을 이용한 초음파센서 동작 (0) | 2022.07.17 |
---|---|
Atmega128을 이용한 0.5초 간격으로 : 깜빡이기 (0) | 2022.07.13 |
댓글