BASIC4MCU | 질문게시판 | 답변 : 답변 : atmega128 4bit LCD 스톱워치
페이지 정보
작성자 코딩응애 작성일2018-12-05 17:27 조회7,066회 댓글1건본문
#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>#define FUNCSET 0x28 //Function Set
#define ENTMODE 0x06 //Entry Mode Set
#define ALLCLR 0x01 //Clear Display
#define DISPON 0x0c //Display On
#define LINE2 0xC0 //Set DDRAM Address (0x40)
#define LINE3 0x94 //Set DDRAM Address (0x14)
#define LINE4 0xD4 //Set DDRAM Address (0x54)#define PORT_DATA PORTD
#define DDR_DATA DDRD#define Byte unsigned char
volatile Byte flag=0,sec=0,min=0,hour=24;//인스트럭션 쓰기 함수
void LCD_write_command(unsigned char byte){_delay_ms(2);
//인스트럭션 상위 바이트
PORT_DATA = (byte & 0xF0); //데이터
PORT_DATA &= 0xFE; //RS = 0
PORT_DATA &= 0xFD; //RW = 0
_delay_us(1);
PORT_DATA |= 0x04; //E = 1
_delay_us(1);
PORT_DATA &= 0xFB; //E = 0//인스트럭션 하위 바이트
PORT_DATA = ((byte<<4) & 0xF0);//데이터
PORT_DATA &= 0xFE; //RS = 0
PORT_DATA &= 0xFD; //RW = 0
_delay_us(1);
PORT_DATA |= 0x04; //E = 1
_delay_us(1);
PORT_DATA &= 0xFB; //E = 0
}void LCD_write_data(unsigned char byte){
_delay_ms(2);//데이터 상위 바이트
PORT_DATA = (byte & 0xF0); //데이터
PORT_DATA |= 0x01; //RS = 1
PORT_DATA &= 0xFD; //RW = 0
_delay_us(1);
PORT_DATA |= 0x04; //E = 1
_delay_us(1);
PORT_DATA &= 0xFB; //E = 0PORT_DATA = ((byte<<4) & 0xF0);//데이터
PORT_DATA |= 0x01; //RS = 1
PORT_DATA &= 0xFD; //RW = 0
_delay_us(1);
PORT_DATA |= 0x04; //E = 1
_delay_us(1);
PORT_DATA &= 0xFB; //E = 0
}//문자열 출력 함수
void LCD_write_string(char *string){
uint8_t i;
for(i=0; string[i]; i++){ //종료 문자를 만날 때 까지
LCD_write_data(string[i]);
}
}void LCD_init(void){
DDR_DATA = 0xFF; //출력 포트 설정
PORT_DATA &= 0xFB; //E = 0
_delay_ms(15);
LCD_write_command(0x20);
_delay_ms(5);
LCD_write_command(0x20);
_delay_us(100);
LCD_write_command(0x20);
LCD_write_command(FUNCSET);
LCD_write_command(DISPON);
LCD_write_command(ALLCLR);
LCD_write_command(ENTMODE);}
ISR(TIMER0_COMP_vect){
if(++sec>59){ sec=0;
if(++min>59){ min=0; if(++hour>23)hour=0; }
}
flag=1;}
void LCD_CHAR(Byte c){ LCD_write_data(c); }
int main(void){
LCD_init(); //LCD 초기화
LCD_write_string(" Current Time"); //문자열 출력
LCD_write_command(LINE2); //2번째줄
LCD_write_string(" 00 : 00 : 00 "); //문자열 출력
LCD_write_command(LINE3); //3번째줄
LCD_write_string(" Temperature "); //문자열 출력
LCD_write_command(LINE4); //4번째줄
LCD_write_string(" C "); //문자열 출력
TCCR1B=0x0D; OCR1A=15624; TIMSK=0x10;
SREG=0x80;
while(1){if(flag){ flag=0;
LCD_init(); LCD_CHAR((hour/10)+'0'); LCD_CHAR((hour%10)+'0');
LCD_init();
LCD_write_string(" "); LCD_CHAR((min /10)+'0'); LCD_CHAR((min %10)+'0');
LCD_init();
LCD_write_string(" "); LCD_CHAR((sec /10)+'0'); LCD_CHAR((sec %10)+'0');};
return 0;}
이렇게 수정했는데 ISR에서 에러가 뜹니다 ..
댓글 1
조회수 7,066master님의 댓글
master 작성일
#include <avr/interrupt.h>
헤더파일 선언이 누락되어 있습니다.