Open changheepark-dev opened 10 months ago
#define F_CPU 16000000UL // 16MHz의 오실레이터를 사용
#include <avr/io.h> //입출력 포트 사용을 위한 헤더 include
#define __DELAY_BACKWARD_COMPATIBLE__
#include <avr/delay.h> //딜레이 사용을 위한 헤더 inlcude
#include <avr/interrupt.h> //인터럽트 사용을 위한 헤더 include
#include "lcd.h" //LCD 사용을 위한 헤더 include -> " "외부의 파일을 include
unsigned int ckd = 0;
ISR(INT0_vect) {
TCNT1 = 0;
while (PIND != 255)
ckd = TCNT1;
}
void INTR_Init()
{
EICRA = (0b10<<ISC00);
EIMSK = (1<<INT0);
PORTD |= (1<<PD0);
sei();
}
int Watch1(unsigned int y, unsigned int NUM) {
LCDMove(y,0);
unsigned char wc[] = "Minor ";
LCDPuts(wc);
}
int Watch2(unsigned int y, unsigned int NUM) {
LCDMove(y,0);
unsigned char wc[] = "Major : 000 ";
wc[11] = '0'+((NUM %100000)/10000);
wc[12] = '0'+((NUM %10000)/1000);
wc[13] = '0'+((NUM %1000)/100);
wc[14] = '-';
wc[15] = '0'+((NUM %100)/10);
LCDPuts(wc);
}
int Watch3(unsigned int y, unsigned int NUM) {
LCDMove(y,0);
unsigned char wc[] = "Critical : 000 ";
wc[11] = '0'+((NUM %100000)/10000);
wc[12] = '0'+((NUM %10000)/1000);
wc[13] = '0'+((NUM %1000)/100);
wc[14] = '-';
wc[15] = '0'+((NUM %100)/10);
LCDPuts(wc);
}
int main(void){
DDRB = 0xf0;
DDRD = 0x00;
PORTD = 0xff;
TCCR1A = (0<<WGM11) | (0<<WGM10);
TCCR1B = (0<<WGM13) | (1<<WGM12) | (1<<CS12) | (0<<CS11) | (0<<CS10);
INTR_Init();
MCU_Init();
LCDInit();
while (1){
if (ckd <= 9) {
PORTB = 0x00;
Watch1(0, ckd);
}
else if (ckd > 38000) {
PORTB = 0xf0;
Watch3(0, ckd - 40000);
}
else {
PORTB = 0xf0;
Watch2(0, ckd - 10000);
}
}
}