BASIC4MCU | 질문게시판 | atmega128 lcd 질문입니다ㅜ
페이지 정보
작성자 코딩응애 작성일2018-12-07 17:15 조회4,836회 댓글0건본문
시 분 초 나오는 타이머가 나오게 4bit 4줄짜리 LCD를 구동하려는데
#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.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 = 0
PORT_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); }
void LCD_STR(Byte *s){ while(*s)LCD_CHAR(*s++); }
int main(void){
Byte str1[]="Current Time"; Byte str2[]="00:00:00";
LCD_init(); //LCD 초기화
LCD_STR(str1); //문자열 출력
LCD_write_command(LINE2); //2번째줄
LCD_STR(str2);
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; }
}
build는 되는데 시간이 가지않습니다.
모두 D포트에 연결되어 있습니다ㅠㅠ
댓글 0
조회수 4,836등록된 댓글이 없습니다.