Latest Post :
Loading...
Home » » Pelurusan jalur robot dengan menggunakan CMPS03

Pelurusan jalur robot dengan menggunakan CMPS03

Wednesday, 11 May 2011 | 0 comments



Gambar Robot :


















CMPS03 merupakan sensor arah(kompas digital), sensor jenis ini biasa digunakan untuk menentukan arah dari mata angin dengan range 0-255 data, disini saya menggunakannya untuk meluruskan jalan robot dengan menggunakan compas ini.
disini saya menggunakan:
1. mikrokontroler ATmega 128
2. motor, roda, dan base berbentuk BELT
3. cmps03
4. LCD
5. dan beberapa rangkaian pendukung lainnya.

//***************************COMPAS*****************
// I2C Bus functions
#asm
.equ __i2c_port=0×03 ;PORTE
.equ __sda_bit=2
.equ __scl_bit=3
#endasm
#include
#define cmps_add 0xC0
unsigned char cmps, r=0,ruang;
unsigned char cmps_read(unsigned char add)
{
unsigned char data;
i2c_start();
i2c_write(cmps_add);
i2c_write(add);
i2c_start();
i2c_write(cmps_add|1);
data=i2c_read(0);
i2c_stop();
return data;
}
//***************************LCD********************
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0×18 ;PORTB
#endasm
#include
char lcd_buffer[33];
void tampil(unsigned char dat)
{
unsigned char data;
data = dat / 100;
data+=0×30;
lcd_putchar(data);
dat%=100;
data = dat / 10;
data+=0×30;
lcd_putchar(data);
dat%=10;
data = dat + 0×30;
lcd_putchar(data);
lcd_putsf(” “);
}
//rata jalan
//#define barat 191
void rataBaratJalan(){
lcd_clear();lcd_gotoxy(11,1);lcd_putsf(“barat “);
while (1){
bacaCmps();
if((cmps(barat-20)))
goto kluar1;
else if((cmps65)){
lcd_gotoxy(11,0);lcd_putsf(“kanan”);
TCNT2=0xFF;TCCR2=0×01;
rpwm=120;lpwm=120;
balik_kanan1();delay_ms(5);
rem();delay_ms(1);
}
else if((cmps>=(barat+15))||((cmps<65)&&(cmps<=255))){
lcd_gotoxy(11,0);lcd_putsf(“kiri “);
TCNT2=0xFF;TCCR2=0×02;
rpwm=120;lpwm=120;
balik_kiri1();delay_ms(5);
rem();delay_ms(1);
}
};
kluar1:
lcd_clear();
while (1){
bacaCmps();
if((cmps(barat-2)))
goto kluar;
else if((cmps65)){
lcd_gotoxy(10,0);lcd_putsf(“kanan”);
TCNT2=0xFF;TCCR2=0×01;
rpwm=120;lpwm=120;
balik_kanan1();delay_ms(2);
rem();delay_ms(2);
}
else if((cmps>=(barat+1))||((cmps<65)&&(cmps<=255))){
lcd_gotoxy(10,0);lcd_putsf(“kiri “);
TCNT2=0xFF;TCCR2=0×02;
rpwm=120;lpwm=120;
balik_kiri1();delay_ms(2);
rem();delay_ms(2);
}
};
kluar:
}
//#define utara 253
void rataUtaraJalan(){
lcd_clear();lcd_gotoxy(11,1);lcd_putsf(“utara “);
while (1){
bacaCmps();
if(((cmps(utara-20)))&&(0<=cmps<=10))
goto kluar1;
else if(((cmps118))&&(cmps=(utara+15))||(cmps0)){
lcd_gotoxy(10,0);lcd_putsf(“kiri “);
TCNT2=0xFF;TCCR2=0×02;
rpwm=120;lpwm=120;
balik_kiri1();delay_ms(5);
rem();delay_ms(1);
}
};
kluar1:
lcd_clear();
while (1){
bacaCmps();
if(((cmps(utara-2)))&&(0<=cmps<=2))
goto kluar;
else if((cmps118)){
lcd_gotoxy(10,0);lcd_putsf(“kanan”);
TCNT2=0xFF;TCCR2=0×01;
rpwm=120;lpwm=120;
balik_kanan1();delay_ms(2);
rem();delay_ms(2);
}
else if((cmps>=(utara+2))||(cmps
//#define timur 66
void rataTimurJalan(){
lcd_clear();lcd_gotoxy(11,1);lcd_putsf(“timur “);
while (1){
bacaCmps();
if((cmps(timur-20)))
goto kluar1;
else if((cmps190)&&(cmps>0))){
lcd_gotoxy(10,0);lcd_putsf(“kanan”);
TCNT2=0xFF;TCCR2=0×01;
rpwm=120;lpwm=120;
balik_kanan1();delay_ms(5);
rem();delay_ms(1);
}
else if((cmps>=(timur+15))||(cmps<190)){
lcd_gotoxy(10,0);lcd_putsf(“kiri “);
TCNT2=0xFF;TCCR2=0×02;
rpwm=120;lpwm=120;
balik_kiri1();delay_ms(5);
rem();delay_ms(1);
}
};
kluar1:
lcd_clear();
while (1){
bacaCmps();
if((cmps(timur-2)))
goto kluar;
else if((cmps190)&&(cmps>0))){
lcd_gotoxy(10,0);lcd_putsf(“kanan”);
TCNT2=0xFF;TCCR2=0×01;
rpwm=120;lpwm=120;
balik_kanan1();delay_ms(2);
rem();delay_ms(2);
}
else if((cmps>=(timur+2))||(cmps
//#define selatan 121
void rataSelatanJalan(){
lcd_clear();lcd_gotoxy(11,1);lcd_putsf(“sltn “);
while (1){
bacaCmps();
if((cmps(selatan-20)))
goto kluar1;
else if(cmps=(selatan+15)){
lcd_gotoxy(10,0);lcd_putsf(“kiri “);
TCNT2=0xFF;TCCR2=0×02;
rpwm=120;lpwm=120;
balik_kiri1();delay_ms(5);
rem();delay_ms(1);
}
};
kluar1:
lcd_clear();
while (1){
bacaCmps();
if((cmps(selatan-2)))
goto kluar;
else if(cmps=(selatan+1)){
lcd_gotoxy(10,0);lcd_putsf(“kiri “);
TCNT2=0xFF;TCCR2=0×02;
rpwm=120;lpwm=120;
balik_kiri1();delay_ms(2);
rem();delay_ms(2);
}
};
kluar:
}
















semoga bermanfaat !!

Referensi : http://psicozone.wordpress.com/


Share this article :

No comments:

 
Support : Creating Website | D'ELGER Template | FadeL
Copyright © 2013. LOGIKA D'ELGER - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger