목차
목 차
1장 제목
2장 목적
3장 구성
4장 내용
5장 소스
1장 제목
2장 목적
3장 구성
4장 내용
5장 소스
본문내용
char);
void delay_ms(unsigned int);
// 함수 선언부 - LCD 초기화 관련 함수
void FunctionSet(); //FUNCTION SET
void DisplayOnOffControl(); //DISPLAY ON/OFF
void DisplayClear(); //DISPLAY CLEAR
void EntryModeSet(); //ENTRY MODE SET
// 함수 선언부 - LCD 글자표시 함수 (문자 및 문자열)
void DisplayChar(unsigned char);
//오버 플로우 인터럽트 횟수를 제어하기 위한 변수
unsigned char cnt;
int main(void)
{
cnt =0;
//외부 인터럽트 설정
EICRB = 0x02;
EIMSK = 0x10;
// SFR 초기화
MCUCR = 0x80; // I/O 포트를 특수기능 모드로 설정
XMCRA = 0X40; // 외부 메모리 섹터 설정
XMCRB = 0X80; // 외부 메모리 섹터 설정
// LCD 초기화
FunctionSet();
DisplayOnOffControl();
DisplayClear();
EntryModeSet();
SetLCDAddress(LINE1);
DDRB = 0xff; //신호등 사용할 PORTB 출력 설정
DDRD = 0xff; //건널목 사용할 PORTD 출력 설정
DDRF = 0xff; //신호등 사용할 PORTF 출력 설정
DDRE = 0x1f; // 건널목 사용할 PORTE 출력 설정
//PORTB,D,E,F off로 초기화
PORTB = 0xff;
PORTD = 0xff;
PORTF = 0xff;
PORTE = 0x0f;
TIMSK = 0x04; //오버플로우 인터럽트 인에블
TCCR1A = 0x00; // Nomal mode
TCCR1B = 0x04; // 프리스케일 = 256 분주
TCCR1C = 0x00;
TCNT1 = 0x00; //65536(1/16us * 65536 * 256 = 1024ms)
SREG = 0x80; //전역 인터럽트 인에이블
while(1);
}
SIGNAL(SIG_OVERFLOW1) //TImer/counter 1 오버플로우
{
cnt++;
int i =0;
if( cnt < 11)
{
PORTF = 0xfe; // 붉은색 점등
PORTE = 0x0b;
PORTB = 0xa5; // 좌신호, 붉은색 점등
PORTD = 0xfd; //건널목 붉은색 점등
if(4 <= cnt && cnt < 10) // 좌신호는 소등하고 직진만 점등
{
PORTB = 0x7e;
}
if( 10<=cnt && cnt <11) // PORTB & PORTC 노란불 점등
{
PORTB = 0xdb;
}
}
else if( 11 <= cnt && cnt <22)
{
PORTB = 0xe7; // 붉은색 점등
// 좌신호 붉은색 점등
PORTE = 0x0b;
PORTF = 0xfa;
if(15 <= cnt && cnt <21) // 좌신호는 소등하고 직진만 점등
{
PORTE = 0x0f;
PORTF = 0xf7;
PORTD = 0xfa; // 건널목 녹색 점등
if(cnt == 15)
{
DisplayChar('6');
}
else if(cnt ==16)
{
SetLCDAddress(LINE1);
DisplayChar('5');
}
else if(cnt ==17)
{
SetLCDAddress(LINE1);
DisplayChar('4');
}
else if(cnt ==18)
{
SetLCDAddress(LINE1);
DisplayChar('3');
}
else if(cnt ==19)
{
SetLCDAddress(LINE1);
DisplayChar('2');
}
else if(cnt ==20)
{
SetLCDAddress(LINE1);
DisplayChar('1');
}
}
if(21<= cnt && cnt <22) // PORTD& PORTF 노란불 점등
{
DisplayClear();
PORTE = 0x07;
PORTF = 0xfd;
PORTD = 0xfd; //건널목 붉은색 점등
}
}
else if (cnt ==22) //지연 카운터 초기화
{
cnt =0;
}
}
void SetLCDAddress(unsigned char mode)
{
LCD_EN = (0x80 | mode);
delay_us(50);
}
void DisplayChar(unsigned char c)
{
LCD_WRITE = c;
delay_us(50);
}
void FunctionSet()
{
delay_ms(50);
LCD_EN = 0x38;
}
void DisplayOnOffControl()
{
delay_us(40);
LCD_EN = 0x0c;
}
void DisplayClear()
{
delay_us(40);
LCD_EN = 0x01;
}
void EntryModeSet()
{
delay_ms(2);
LCD_EN = 0x06;
delay_us(40);
}
void delay_us(unsigned char time_us)
{
register unsigned char i;
for(i=0;i
{
asm volatile("PUSH R0"); //2 cycle
asm volatile("POP R0"); //2 cycle
asm volatile("PUSH R0"); //2 cycle
asm volatile("POP R0"); //2 cycle
asm volatile("PUSH R0"); //2 cycle
asm volatile("POP R0"); //2 cycle
// Sum = 16 cycle=1 us for 16MHz
}
}
void delay_ms(unsigned int time_ms)
{
register unsigned int i;
for(i=0;i
{
delay_us(250);
delay_us(250);
delay_us(250);
delay_us(250);
}
}
SIGNAL(SIG_INTERRUPT4)
{
while((PINE & 0x10 )==0);
}
void delay_ms(unsigned int);
// 함수 선언부 - LCD 초기화 관련 함수
void FunctionSet(); //FUNCTION SET
void DisplayOnOffControl(); //DISPLAY ON/OFF
void DisplayClear(); //DISPLAY CLEAR
void EntryModeSet(); //ENTRY MODE SET
// 함수 선언부 - LCD 글자표시 함수 (문자 및 문자열)
void DisplayChar(unsigned char);
//오버 플로우 인터럽트 횟수를 제어하기 위한 변수
unsigned char cnt;
int main(void)
{
cnt =0;
//외부 인터럽트 설정
EICRB = 0x02;
EIMSK = 0x10;
// SFR 초기화
MCUCR = 0x80; // I/O 포트를 특수기능 모드로 설정
XMCRA = 0X40; // 외부 메모리 섹터 설정
XMCRB = 0X80; // 외부 메모리 섹터 설정
// LCD 초기화
FunctionSet();
DisplayOnOffControl();
DisplayClear();
EntryModeSet();
SetLCDAddress(LINE1);
DDRB = 0xff; //신호등 사용할 PORTB 출력 설정
DDRD = 0xff; //건널목 사용할 PORTD 출력 설정
DDRF = 0xff; //신호등 사용할 PORTF 출력 설정
DDRE = 0x1f; // 건널목 사용할 PORTE 출력 설정
//PORTB,D,E,F off로 초기화
PORTB = 0xff;
PORTD = 0xff;
PORTF = 0xff;
PORTE = 0x0f;
TIMSK = 0x04; //오버플로우 인터럽트 인에블
TCCR1A = 0x00; // Nomal mode
TCCR1B = 0x04; // 프리스케일 = 256 분주
TCCR1C = 0x00;
TCNT1 = 0x00; //65536(1/16us * 65536 * 256 = 1024ms)
SREG = 0x80; //전역 인터럽트 인에이블
while(1);
}
SIGNAL(SIG_OVERFLOW1) //TImer/counter 1 오버플로우
{
cnt++;
int i =0;
if( cnt < 11)
{
PORTF = 0xfe; // 붉은색 점등
PORTE = 0x0b;
PORTB = 0xa5; // 좌신호, 붉은색 점등
PORTD = 0xfd; //건널목 붉은색 점등
if(4 <= cnt && cnt < 10) // 좌신호는 소등하고 직진만 점등
{
PORTB = 0x7e;
}
if( 10<=cnt && cnt <11) // PORTB & PORTC 노란불 점등
{
PORTB = 0xdb;
}
}
else if( 11 <= cnt && cnt <22)
{
PORTB = 0xe7; // 붉은색 점등
// 좌신호 붉은색 점등
PORTE = 0x0b;
PORTF = 0xfa;
if(15 <= cnt && cnt <21) // 좌신호는 소등하고 직진만 점등
{
PORTE = 0x0f;
PORTF = 0xf7;
PORTD = 0xfa; // 건널목 녹색 점등
if(cnt == 15)
{
DisplayChar('6');
}
else if(cnt ==16)
{
SetLCDAddress(LINE1);
DisplayChar('5');
}
else if(cnt ==17)
{
SetLCDAddress(LINE1);
DisplayChar('4');
}
else if(cnt ==18)
{
SetLCDAddress(LINE1);
DisplayChar('3');
}
else if(cnt ==19)
{
SetLCDAddress(LINE1);
DisplayChar('2');
}
else if(cnt ==20)
{
SetLCDAddress(LINE1);
DisplayChar('1');
}
}
if(21<= cnt && cnt <22) // PORTD& PORTF 노란불 점등
{
DisplayClear();
PORTE = 0x07;
PORTF = 0xfd;
PORTD = 0xfd; //건널목 붉은색 점등
}
}
else if (cnt ==22) //지연 카운터 초기화
{
cnt =0;
}
}
void SetLCDAddress(unsigned char mode)
{
LCD_EN = (0x80 | mode);
delay_us(50);
}
void DisplayChar(unsigned char c)
{
LCD_WRITE = c;
delay_us(50);
}
void FunctionSet()
{
delay_ms(50);
LCD_EN = 0x38;
}
void DisplayOnOffControl()
{
delay_us(40);
LCD_EN = 0x0c;
}
void DisplayClear()
{
delay_us(40);
LCD_EN = 0x01;
}
void EntryModeSet()
{
delay_ms(2);
LCD_EN = 0x06;
delay_us(40);
}
void delay_us(unsigned char time_us)
{
register unsigned char i;
for(i=0;i
asm volatile("PUSH R0"); //2 cycle
asm volatile("POP R0"); //2 cycle
asm volatile("PUSH R0"); //2 cycle
asm volatile("POP R0"); //2 cycle
asm volatile("PUSH R0"); //2 cycle
asm volatile("POP R0"); //2 cycle
// Sum = 16 cycle=1 us for 16MHz
}
}
void delay_ms(unsigned int time_ms)
{
register unsigned int i;
for(i=0;i
delay_us(250);
delay_us(250);
delay_us(250);
delay_us(250);
}
}
SIGNAL(SIG_INTERRUPT4)
{
while((PINE & 0x10 )==0);
}
키워드
추천자료
AT89S51 마이컴 구조 자료
초음파 센서를 이용한 저가형 청소로봇의 청소 성능 개선 방안
4족 보행 운반 로봇의 개발
적외선센서를 이용한 주차시스템
디지털 신호의 출력 원리(7segment)
마이크로프로세서
전기공학실험_보고서(BLDC모터).
AVR 레포트
(최종) 컴퓨터를 이용한 계측실험 I
Zigbex를 이용한 학내 환경 관리 시스템
타이머 / PWM [마컴 예비레포트]
애플 / 삼성 / 노키아 분석 - ① 삼성 애플 노키아 비교 분석 ② 삼성 애플 소송 분쟁
[마이크로프로세서응용실험] (결과) 실험 06: 시계 알람 설정
방통대 중간과제 취미와 예술 D형, 취미로서의 먹고 마시기 ‘먹방’에 관하여: 삼시세끼
소개글