Memprogram Line Follower Robot dengan CodeVisionAVR


               Kalau Sebelumnya sudah saya posting tentang Rangkaian Line Follower Robot 8 sensor http://gunture.blogspot.com/2011/08/rangkaian-line-follower-robot.html sekarang saya akan mencoba memberikan sedikit code program sederhananya menggunakan CodeVisionAVR, cekidot...;-p


/*****************************************************
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 : Line Follower
Version : 1.0
Date    : 11/24/2011
Author  : http//:www.gunture.blogspot.com
Company : Microware
Comments: Settingan Pin, Arah motor, dan sensor sesuai dengan Elektronik Robot Anda


Chip type           : ATmega8
Program type        : Application
Clock frequency     : 11,059200 MHz
Memory model        : Small
External RAM size   : 0
Data Stack size     : 256
*****************************************************/

#include //panggil library Atmega8
#include //panggil Library Delay

#define maju_kanan      PORTC.1
#define mundur_kanan    PORTC.0
#define maju_kiri       PORTC.2
#define mundur_kiri     PORTC.3

#define kec_kiri        OCR1A   //PIN PWM ATMEGA8
#define kec_kanan       OCR1B   //PIN PWM ATMEGA8

// Declare your global variables here
int posisi;

//Fungsi Robot Berjalan Maju
void maju(int lpwm, int rpwm){
   maju_kiri   = 1;   maju_kanan   = 1;
   mundur_kiri = 0;   mundur_kanan = 0;
   lpwm=kec_kiri;     rpwm=kec_kanan;
}

//Fungsi Robot Berjalan Pivot Kanan
void pivot_kanan(int lpwm, int rpwm){
   maju_kiri   = 1;   maju_kanan   = 0;
   mundur_kiri = 0;   mundur_kanan = 1;
   lpwm=kec_kiri;     rpwm=kec_kanan;
}

//Fungsi Robot Berjalan Pivot Kiri
void pivot_kiri(int lpwm, int rpwm){
   maju_kiri   = 0;   maju_kanan   = 1;
   mundur_kiri = 1;   mundur_kanan = 0;
   lpwm=kec_kiri;     rpwm=kec_kanan;
}

//Fungsi pembacaan sensor, sensor dihubungkan ke PORTD sebagai input
int baca_sensor(){
   switch(PIND){
      case 0b01111111 : posisi=9; break;
      case 0b00111111 : posisi=9; break;
      case 0b00011111 : posisi=9; break;
      case 0b00001111 : posisi=9; break;
      case 0b00000111 : posisi=9; break;
      case 0b00000001 : posisi=7; break;
      case 0b00000011 : posisi=6; break;
      case 0b00000010 : posisi=5; break;
      case 0b00000110 : posisi=4; break;
      case 0b00000100 : posisi=3; break;
      case 0b00001100 : posisi=2; break;
      case 0b00001000 : posisi=1; break;
      case 0b00011000 : posisi=0; break;  //posisi tengah
      case 0b00010000 : posisi=-1; break;
      case 0b00110000 : posisi=-2; break;
      case 0b00100000 : posisi=-3; break;
      case 0b01100000 : posisi=-4; break;
      case 0b01000000 : posisi=-5; break;
      case 0b11000000 : posisi=-6; break;
      case 0b10000000 : posisi=-7; break;
      case 0b11100000 : posisi=-9; break;
      case 0b11110000 : posisi=-9; break;
      case 0b11111000 : posisi=-9; break;
      case 0b11111100 : posisi=-9; break;
      case 0b11111110 : posisi=-9; break;
      case 0b00000000: if (posisi < 0)posisi = -9;else if (posisi > 0)posisi = 9;break; //robot kehilangan garis
   }  
   return posisi;
}


void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTB=0x00;
DDRB=0xFF;

// Port C initialization
// Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTC=0x00;
DDRC=0x7F;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 10,800 kHz
// Mode: Fast PWM top=00FFh
// OC1A output: Non-Inv.
// OC1B output: Non-Inv.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0xA1;
TCCR1B=0x0D;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=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;
while (1)
      {
      // Place your code here
     
      //Program Utama
     
      switch(baca_sensor()){
         case -9: pivot_kiri(150,150);break;
         case -7: pivot_kiri(175,10);break;
         case -6: maju(200,0);break;
         case -5: maju(255,30);break;
         case -4: maju(255,75);break;
         case -3: maju(255,100);break;
         case -2: maju(255,170);break;
         case -1: maju(255,230);break;
         case  0: maju(255,255);break;
         case  1: maju(230,255);break;
         case  2: maju(170,255);break;
         case  3: maju(100,255);break;
         case  4: maju(75,255);break;
         case  5: maju(30,255);break;
         case  6: maju(0,200);break;
         case  7: pivot_kanan(10,200);break;
         case  9: pivot_kanan(150,150);break;
      }
      };
}


> Download Full Program :-D

Previous
Next Post »

12 comments

Click here for comments
Anonymous
admin
December 30, 2011 at 1:59 PM ×

Gan ane mau tanya cara memasukan programnya bisa dikasih tau gak ane buingung masalahnya ada banyak file please

Reply
avatar
December 31, 2011 at 2:45 AM ×

cari file *.hex nya gan... donload pake khazama avr programmer ke mikronya... kalo mo diedit tinggal buka file code visionnya...
:D

Reply
avatar
Anonymous
admin
February 23, 2012 at 10:17 PM ×

gak bisa di download gan .

Reply
avatar
Anonymous
admin
May 3, 2012 at 9:59 AM ×

file udah d delete gan...

Reply
avatar
October 3, 2012 at 6:54 AM ×

sudah bisa di download gan file nya..
link sudah diperbaiki...
:)

Reply
avatar
Anonymous
admin
November 23, 2012 at 1:00 AM ×

gan bisa minta skema buat source di atas
send via email gan
agiek.smada@gmail.com
terima kasih gan

Reply
avatar
Unknown
admin
May 3, 2013 at 3:13 AM ×

om tolong dong dibahas line follower menggunakan 12 sensor, yang pakek multiplexer, terima kasih.

Reply
avatar
Unknown
admin
May 22, 2014 at 7:28 PM ×

ini nih ane baru nemu program line follower yang rumit kaya gini. makasih atas ilmunya

Reply
avatar
November 7, 2014 at 4:26 PM ×

terimakasi banyak sudah membantu saya bapak...

Reply
avatar
Unknown
admin
May 27, 2016 at 3:35 PM ×

masukinnya gimana ya

Reply
avatar
Unknown
admin
May 27, 2016 at 3:36 PM ×

masukinnya gimana ya

Reply
avatar
Thanks for your comment