디스플레이 > mega8 Large Font LCD 시계

TODAY1,211 TOTAL684,081
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 디스플레이 | LCD | mega8 Large Font LCD 시계

페이지 정보

작성자 키트 작성일2017-08-31 17:42 조회651회 댓글0건

본문

//RS (pin4) -----  bit 0
//RD (pin 5) ----- bit 1
//EN (pin 6) ----- bit 2
//사용안함          bit 3
//DB4 (pin 11) --- bit 4
//DB5 (pin 12) --- bit 5
//DB6 (pin 13) --- bit 6
//DB7 (pin 14) --- bit 7

 

 

 

#include <mega8.h>
#include <delay.h>
#include <stdio.h>
#include <string.h>
//
#define MODE_SW      PINC.0
#define HOUR_SW      PINC.1
#define MIN_SW       PINC.2
#define SAVE_SW      PINC.3
//
#define key_Mode     1
#define key_Hour     2
#define key_Min      3
#define key_Save     4
//
#define mode_time    1
#define mode_alarm   2
//
bit  sec_Flg=0;
//
char sec=0, mmin=0, hour=12, day=1, mon=1, year=0, hhour, min_10, min_1;
eeprom char ee_hour, ee_min;
char alrm_hour, alrm_min;
char tp_min=0, tp_hour=0;
char mode=0;
//
bit  key_tp_Flg=0, key_Flg=0;
char key_buf=0;
//
unsigned char str[21];
char font[8][8={
    {0b00000111,0b00001111,0b00011111,0b00011111,0b00011111,0b00011111,0b00011111,0b00011111},
    {0b00011111,0b00011111,0b00011111,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000},
    {0b00011100,0b00011110,0b00011111,0b00011111,0b00011111,0b00011111,0b00011111,0b00011111},
    {0b00011111,0b00011111,0b00011111,0b00011111,0b00011111,0b00011111,0b00001111,0b00000111},
    {0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00011111,0b00011111,0b00011111},
    {0b00011111,0b00011111,0b00011111,0b00011111,0b00011111,0b00011111,0b00011110,0b00011100},
    {0b00011111,0b00011111,0b00011111,0b00000000,0b00000000,0b00000000,0b00011111,0b00011111},
    {0b00011111,0b00000000,0b00000000,0b00000000,0b00000000,0b00011111,0b00011111,0b00011111}
};
//
#define lcd_Out PORTB   // PORTA.4~7 4bits
#define lcd_E   {delay_us(1);lcd_Out&=~4;delay_us(1);}
//
void LCD_CMD(char c){ lcd_Out=(c&0xF0)|4; lcd_E; lcd_Out=(c<<4)|4; lcd_E; delay_ms(3); }
void LCD_DAT(char d){ lcd_Out=(d&0xF0)|5; lcd_E; lcd_Out=(d<<4)|1; lcd_E; delay_us(50); }
void lcd_puts(char *s){ while(*s)LCD_DAT(*s++); }
void lcd_clear(void){ LCD_CMD(0x01); }
void lcd_gotoxy(char col, char row){ 
    if(row<2)LCD_CMD(0x80+(col+row*0x40));
    else     LCD_CMD(0x94+(col+(row-2)*0x40)); 
}
void lcd_init(void){
    DDRB=0xFF;     delay_ms(30);
    LCD_CMD(0x28); LCD_CMD(0x28); LCD_CMD(0x28);
    LCD_CMD(0x0C); LCD_CMD(0x06); lcd_clear();
}
//
void make_custom_font(unsigned char addr,char *s){
    unsigned char i;
    LCD_CMD((addr<<3)|0x40);
    for(i=0;i<8;i++)LCD_DAT(*s++);
}
//
char digit[11][6]={
    {  8,  1,  2,  3,  4,  5},{254,255,254,254,255,254},{  6,  6,  2,255,  7,  7},
    {  6,  6,  2,  7,  7,  5},{  3,  4,255,254,254,255},{255,  6,  6,  7,  7,  5},
    {  8,  6,  6,  3,  7,  5},{  1,  1,255,254,  8,254},{  8,  6,  2,  3,  7,  5},
    {  8,  6,  2,254,254,255},{254,254,254,254,254,254}
};
//
void disp_no1(char no,char x,char y){
    char i; for(i=0;i<8;i++){ lcd_gotoxy(x+i%3,y+i/3); LCD_DAT(digit[no][i]); }
}
void disp_hhour(char no){
    if(no<9)disp_no1(10,0,0); //b
    else    disp_no1(no/10,0,0);
    disp_no1(no%10,3,0);
}
//
interrupt [TIM0_OVF] void timer0_ovf_isr(void){  // 1ms
    if(mode){ // 시간설정 모드거나 알람설정 모드면
        if(tp_hour<12){ lcd_gotoxy(13,0); sprintf(str, " AM"); lcd_puts(str); }
        else          { lcd_gotoxy(13,0); sprintf(str, " PM"); lcd_puts(str); }
        //
        if     (mode==mode_time ){ lcd_gotoxy(13,1); sprintf(str, "TIM"); lcd_puts(str); }
        else if(mode==mode_alarm){ lcd_gotoxy(13,1); sprintf(str, "ALM"); lcd_puts(str); }
        //
        if     (tp_hour>=24)hhour=0;
        else if(tp_hour>=13)hhour=tp_hour-12;
        else                hhour=tp_hour;
        //
        disp_hhour(hhour);
        //
        lcd_gotoxy(6,0); LCD_DAT(165); lcd_gotoxy(6,1);  LCD_DAT(165);
        //
        min_10=tp_min/10; disp_no1(min_10,7,0);
        min_1=tp_min%10;  disp_no1(min_1,10,0);
    }
    else// 시간표시 모드면
        if(hour<12){ lcd_gotoxy(13,0); sprintf(str, " AM"); lcd_puts(str); }
        else       { lcd_gotoxy(13,0); sprintf(str, " PM"); lcd_puts(str); }
        //
        lcd_gotoxy(13,1); sprintf(str, " %2d", sec); lcd_puts(str);
        //
        if(hour>=13)hhour=hour-12;
        else        hhour=hour;
        //
        disp_hhour(hhour);
        //
        if(sec%2==0) {lcd_gotoxy(6,0); LCD_DAT(165); lcd_gotoxy(6,1);  LCD_DAT(165);}
        else {lcd_gotoxy(6,0);         LCD_DAT(254); lcd_gotoxy(6,1);  LCD_DAT(254);}
        //
        min_10=mmin/10; disp_no1(min_10,7,0);
        min_1=mmin%10;  disp_no1(min_1,10,0);
    }
}
//-----------------------------------------------------------
interrupt [TIM1_COMPA] void timer1_compa_isr(void){  // 타이머1 매치 인터럽트 1sec
    sec_Flg=~sec_Flg;
    if(++sec>59){  sec=0;
        if(++mmin>59){  mmin=0;
            if(++hour>23){ hour=0;
                if(++day>31){ day=1;
                    if(++mon>12){ mon=1if(++year>99)year=0; }
                }
            }
        }
    }
    //
    //if((alrm_min=min)&&(alrm_hour==hour)){ BUZ=1; } // 알람 시간이면 부저 ON
    //else                                 { BUZ=0; } // 알람 시간이 아니면 부저 OFF
}
//-----------------------------------------------------------
interrupt [TIM2_COMP] void timer2_comp_isr(void){  // 타이머2 매치 인터럽트 9.984ms
    if((PINC&0x0F)!=0x0F){
        if(!key_tp_Flg){ key_tp_Flg=1;
            if(!MODE_SW){ key_buf=key_Mode; key_Flg=1; }
            if(!HOUR_SW){ key_buf=key_Hour; key_Flg=1; }
            if!MIN_SW){ key_buf=key_Min;  key_Flg=1; }
            if(!SAVE_SW){ key_buf=key_Save; key_Flg=1; }
        }
    }
    elseif(key_tp_Flg)key_tp_Flg=0; }
}
//-----------------------------------------------------------
void main(void){
    int i;
    PORTC=0x0F; DDRC=0x30; DDRB=0x01;

댓글 0

조회수 651

등록된 댓글이 없습니다.

디스플레이HOME > 디스플레이 > 전체 목록

게시물 검색

2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2017
모바일버전으로보기