Page 116 - MDP2020-3
P. 116
110
| 인천전자마이스터고등학교 ·············································································································
나) 초음파 센서와 LCD를 사용하여 거리 측정
#include <mega128a.h>
#include <stdio.h>
#include <delay.h>
#asm
.equ __lcd_port=0x1b; //PORTA
#endasm
#include <lcd.h> //LCD 제어 함수를 사용을 위해 추가
//에코 핀에서 출력되는 펄스의 길이를 저장하는 전역변수
unsigned int dist;
//
int i;
char sbuf[16];
void init_uart0(void)
{
//시리얼 통신을 통한 디버깅용
UCSR0A=0b00000000;
UCSR0B=0b10011000;
UCSR0C=0b10000110;
UBRR0H=0;
UBRR0L=103;
//printf("STARTING SYSTEM ... \n\r");
}
void TC0_cnt()
{
TCCR0 = 0b00000010; //normal mode, prescaler = 8
TIMSK = 0b00000000; //tc0 ovf interrput : disable;
TCNT0 = 253;
//(16MHz^-1) * 8 * (255 - 253) = 1us;
}
interrupt [EXT_INT0] void extint0_isr()
{