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

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

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


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

페이지 정보

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

본문

 

3660040649_3aCAzst9_25C125A625B825F1_25BE25F825C025BD.png3Ftype3Dw740


#include <mega8.h>
#include <delay.h>
#include <stdio.h>
#include <string.h>
#include <alcd.h>       // PORTB0-7
 
//
#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}
};
//
void make_custom_font(unsigned char addr,char *s){
    unsigned char i;
    for(i=0;i<8;i++){ lcd_write_byte(((addr<<3)|0x40)+i,*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_putchar(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_putchar(165); lcd_gotoxy(6,1);  lcd_putchar(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_putchar(165); lcd_gotoxy(6,1);  lcd_putchar(165);}
        else {lcd_gotoxy(6,0);         lcd_putchar(254); lcd_gotoxy(6,1);  lcd_putchar(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;
 
    lcd_init(16);
    for(i=0;i<8;i++)make_custom_font(0, font[i]);
 
    TCCR0=3;     TCNT0=6;     TIMSK=0x01;   //16000000/  64/250=1000Hz=1ms,  (256-250)=6
    TCCR2=0x0F;  OCR2=155;    TIMSK|=0x80;  //16000000/1024/(1+155)=100.16Hz=9.984ms
    TCCR1B=0x0c; OCR1A=62499; TIMSK|=0x10;  //16MHz/256/(1+62499)=1Hz=1sec
    alrm_hour=ee_hour; alrm_min=ee_min; // eeprom을 읽어서
    if((alrm_hour>24)||(alrm_min>59)){ ee_min=alrm_min=0; ee_hour=alrm_hour=24; } // 시간범위 밖이면 초기화
    SREG=0x80;
    while(1){
        while(key_Flg){  // 키를 눌렀을 때만 실행
            key_Flg=0;   // 실행되면 크리어 시킴
            if(key_buf==key_Mode){ // 모드 변경
                if(++mode>mode_alarm)mode=0// 시계모드 -> 시간설정모드 -> 알람설정모드 -> 다시 시계모드로
                //
                if     (mode==mode_time ){ tp_min=mmin;     tp_hour=hour;      } // 설정용 변수에 시계 시간을 복사

댓글 0

조회수 625

등록된 댓글이 없습니다.

디스플레이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
모바일버전으로보기