I was recently working on a light sensing robot. Some how i managed to come up with it. I programed the robot with following program. I just wanted to know if there is some better way of doing the same, or is it fine when it comes on good programming.
#define F_CPU 12000000UL // define cpu frequency for delay function
#include <avr/io.h> // includes input/output header file
#include <util/delay.h> // includes delay header file
//#include"lcd.h"
//#include"lcd.c"
/* Program for Line follower */
//******************************************************************************
/* Connection of 3 PIN Sensor PORTs with atmega 8
PC4 Port is connected with PIN27 of Atmega 8
PC5 Port is connected with PIN28 of Atmega 8
PC3 Port is connected with PIN26 of Atmega 8(DTMF D3 is also sent to this pin)
PC2 Port is connected with PIN25 of Atmega 8(DTMF D2 is also sent to this pin)
PC1 Port is connected with PIN24 of Atmega 8(DTMF D1 is also sent to this pin)
PC0 Port is connected with PIN23 of Atmega 8(DTMF D0 is also sent to this pin)
PC6 Port is connected with PIN 1(Reset Pin) of Atmega 8
*******************************************************************************
Connection of L293D IC with atmega 8
Pin 2(A1) of L293D is Connected with PB2(Pin 16 of Atmega8)
Pin 7(B1) of L293D is Connected with PB3(MOSI)(Pin 17 of Atmega8)
**A1 and B1 are the input pins of Left side H-Bridge of L293D which is driving the Left Motor
Pin 15 (A2) of L293D is Connected with PB0(Pin 14of Atmega8)
Pin 10 (B2) of L293D is Connected with PB1(Pin 15 of Atmega8)
Pin 1(EN1) and pin 9(EN2) is connected Via motor enable switch.
when we switch on Enable Switch Both EN1 and EN2 are given
5 Volt supply to enalbe both H-Bridges of L293D
Pin 3 and pin6 of L293D is Connected with Left Motor Connector
Pin 14 and Pin 11 of L293D is connected with Right Motor Connector */
//Connect Light Sensor on PC5 Port
int main(void)
{
DDRB=0b11111111; //PORTB as output Port connected to motors
DDRC=0b0000000; //PORTC Input port connected to Sensors
//lcd_init(LCD_DISP_ON);
//lcd_puts("AMIT SHIROHA\n");
//lcd_puts("SBIT, SONIPAT");
int light_sensor=0;
while(1) // infinite loop
{
light_sensor=PINC&0b0100000; // mask PC5 bit of Port C
if(light_sensor==0b0100000) //if LED1 is your right light sensor "
PORTB=0b00000001; // move left
else
PORTB=0b00001000; // move right
}//while closed
}//main closed