This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :Distance measurement with Ultrasonic Sensor (PING) and shown in LCD
Date : 25/10/2009
Author :Rony Yang
Comments:It works. Don't forget to set the sprintf data conversion.
Just find it by yourself.^^
Chip type : ATmega8535
Program type : Application
Clock frequency : 11,059200 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 128
*****************************************************/
#include (mega8535.h)
#include (delay.h)
#include (stdio.h)
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include
// Declare your global variables here
unsigned int count=0;
float time, distance;
char buf[33];
void ping(void)
{
//PORTD.0 digunakan sebagai signal input dan output dari dan ke Sensor Ping
count=0;
DDRD.0=1;
PORTD.0=1;
delay_us(4);
PORTD.0=0;
DDRD.0=0;
PORTD.0=1;
while(PIND.0==0)
{
}
while(PIND.0==1)
{
count++;
}
}
void main(void)
{
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// LCD module initialization
lcd_init(16);
while (1)
{
// Place your code here
ping();
//count multiply by 1/oscillator frequency
time=(count*0.09042245370370370370370370370);
//distance=time multiply by 0.354
//(default 0.340(from 340 m/s)) then divided by 2
distance=((time*0.354)/2);
sprintf(buf,"Jarak= %0.2f cm ",distance);
lcd_gotoxy(0,0);
lcd_puts(buf);
delay_ms(200);
lcd_clear();
};
}
0 komentar:
Posting Komentar