loading
ATmega128을 이용한 문자 'C' 표시하기
본문 바로가기
IT/CodeVision atmega128

ATmega128을 이용한 문자 'C' 표시하기

by 쿠로쿠로네코 2022. 7. 14.
반응형

#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;
}

반응형

댓글