



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




// Project: // Author: // Module description: // ***********************************************************
#include <avr\io.h> // Most basic include files #include <avr\interrupt.h> // Add the necessary ones #include <avr\signal.h> // here #define F_CPU 1000000UL #include <util/delay.h>
// ########################### DEFINITIONS################################### // Time definitions #define t0 10
#define BLACK 0x #define BROWN 0x #define ORANGE 0x0A #define YELLOW 0x #define BLACK2 0x #define BROWN2 0x #define ORANGE2 0xA #define YELLOW2 0x #define st1 0x #define st2 0x #define st3 0xAA #define st4 0x
void motor1(unsigned int,unsigned int); void motor2(unsigned int,unsigned int); unsigned int temp1,temp2,i,j,k,anti1,anti2,tick1,tick2; unsigned int delay = 5;
// Main program // int main(void)
{ unsigned char check1, check2, result; unsigned comb[] = {0x00,0x09,0x0A,0x0C,0x11,0x12,0x13,0x21,0x22,0x23,0x41,0x42,0x43}; unsigned portcomb[] = {0x00,0x01,0x02,0x04,0x08,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; int i;
DDRA = 0x1F; PORTA = 0x00; // Initially all diodes are off DDRC = 0xFF; PORTC = 0x55;
temp1=1; temp2=1;
while(1) {
// checking for Row: DDRB = 0x07; PORTB = 0x07; check1 = PINB;
// checking for Coloumn: DDRB = 0x78; PORTB = 0x78; check2 = PINB;
// result: result = ((check1 & 0x78) | (check2 & 0x07));
for (i=0;i<12;i++) { if(result==comb[i]) { PORTA=(portcomb[i]); } }
if (PORTA==0x01) // For Forward Motion of the Cart { anti1=1; //anti = 1 means anti clockwise....anti = 0 means clockwise anti2=1; tick1=48; // # of ticks in 1 function call tick2=48; motor1(anti1,tick1); motor2(anti2,tick2); }
if (PORTA==0x02) // For Backward Motion of the Cart { anti1=0; //anti = 1 means anti clockwise....anti = 0 means clockwise anti2=0; tick1=48; // # of ticks in 1 function call tick2=48; motor1(anti1,tick1); motor2(anti2,tick2); }
if (PORTA==0x04) // For Clockwise Motion of the Cart { anti1=1; //anti = 1 means anti clockwise....anti = 0 means clockwise anti2=0;
}//end if else { for(i=0;i<tick1;i++) { if (temp1==1) { PORTC = YELLOW; _delay_ms(delay); temp1=3; } if(temp1 == 3) { PORTC=ORANGE; _delay_ms(delay); temp1=2; } if (temp1== 2) { PORTC =BROWN; _delay_ms(delay); temp1=4; } if (temp1== 4) { PORTC=BLACK; _delay_ms(delay); temp1=1; } }//end for }//end else PORTC= 0x00; }//end ftn
void motor2(unsigned int anti2,unsigned int tick2) { if (anti2==1) { for(i=0;i<tick2;i++) { if (temp2==1) { PORTC = BROWN2; _delay_ms(delay); temp2=2; } if(temp2== 2) { PORTC=ORANGE2; _delay_ms(delay); temp2=3; } if (temp2== 3)
_delay_ms(delay); temp2=4; } if (temp2== 3) { PORTC=BLACK2; _delay_ms(delay); temp2=1; } }//end for }//end if else { for(i=0;i<tick2;i++) { if (temp2==1) { PORTC = YELLOW2; _delay_ms(delay); temp2=3; } if(temp2 == 3) { PORTC=ORANGE2; _delay_ms(delay); temp2=2; } if (temp2== 2) { PORTC =BROWN2; _delay_ms(delay); temp2=4; } if (temp2== 3) { PORTC=BLACK2; _delay_ms(delay); temp2=1; } }//end for }//end else PORTC = 0x00; }//end ftn