Sunteți pe pagina 1din 5

#include <stdio.h> #include<avr/interrupt.h> /* Scheduler include files. */ #include "FreeRTOS.h" #include "task.h" #include "croutine.

h" // FreeRTOS Function include files #define STACK_SIZE 100 // > minimal stack size from FreeRTOSConfig.h void void void void void void void void void void TaskLeftLed(void *pvParameters); TaskRightLed(void *pvParameters); TaskBothLed(void *pvParameters); TaskMotorDrive(void *pvParameters); MOTO_FOR(); MOTO_REV(); MOTO_STOP(); turn_Right(); turn_Left(); T1me();

int main() { // set PIN for output //DDRB = 255; //PINB set as output DDRB = 0B10101101; //PINB4 to PINB7 set as output. PINB0 to PINB3 s et as input DDRD = 0B11111101; //PIND set as output PORTB |= (1<<PB1); PORTD |= (1<<PD1); // create tasks //xTaskCreate(TaskLeftLed,NULL,STACK_SIZE,NULL,2,NULL); or LED Left //xTaskCreate(TaskRightLed,NULL,STACK_SIZE,NULL,2,NULL); //Task for LED Right xTaskCreate(TaskBothLed,NULL,STACK_SIZE,NULL,2,NULL); or LED Both // xTaskCreate(TaskMotorDrive,NULL,STACK_SIZE,NULL,2,NULL); or Motor Drive // start the scheduler vTaskStartScheduler(); for(;;); return 0; } void TaskRightLed(void *pvParameters) { while (1) { //Function for Task Left LED blinking //Infinity loop //Task f

//Task f //Task f

PORTB |= (1<<PB7); //LED 4 turn ON and the rest is OFF T1me(); PORTB &= ~(1<<PB7); PORTB |= (1<<PB5); //LED 3 turn ON and the rest is OFF T1me(); PORTB &= ~(1<<PB5); PORTB |= (1<<PB3); //LED 2 turn ON and the rest is OFF T1me(); PORTB &= ~(1<<PB3); } } void TaskLeftLed(void *pvParameters) { while (1) { //Function for Task Right LED blinking //Infinity loop

PORTD |= (1<<PD7); //LED 5 turn ON and the rest is OFF T1me(); PORTD &= ~(1<<PD7); PORTD |= (1<<PD5); //LED 6 turn ON and the rest is OFF T1me(); PORTD &= ~(1<<PD5); PORTD |= (1<<PD6); //LED 7 turn ON and the rest is OFF T1me(); PORTD &= ~(1<<PD6);

} } void TaskBothLed(void *pvParameters) { while (1) //Infinity loop { PORTB |= (1<<PB7); //LED 4 n 5 turn ON and the rest is OFF PORTD |= (1<<PD7); T1me(); PORTB &= ~(1<<PB7); PORTD &= ~(1<<PD7); PORTB |= PORTD |= T1me(); PORTB &= PORTD &= PORTB |= PORTD |= T1me(); PORTB &= PORTD &= (1<<PB5); //LED 3 n 6 turn ON and the rest is OFF (1<<PD5); ~(1<<PB5); ~(1<<PD5); (1<<PB3); //LED 2 n 7 turn ON and the rest is OFF (1<<PD6); ~(1<<PB3); ~(1<<PD6);

} } /*void TaskMotorDrive(void *pvParameters) //Function for Task Motor Drive { while (1) { if(bit_is_set(PINB,1) && bit_is_set(PIND,1)) //Motor Forward { MOTO_FOR(); } if(bit_is_clear(PINB,1)) t { MOTO_REV(); vTaskDelay(50); turn_Right(); vTaskDelay(30); MOTO_FOR(); } if(bit_is_clear(PIND,1)) { MOTO_REV(); vTaskDelay(50); turn_Left(); vTaskDelay(30); MOTO_FOR(); } if(bit_is_clear(PINB,1) || bit_is_set(PIND,1)) turn to the Left { vTaskDelay(50); } if(bit_is_set(PINB,1) || bit_is_clear(PIND,1)) turn to the Left { vTaskDelay(50); } if(bit_is_clear(PINB,1) && bit_is_clear(PIND,1)) //Motor turn to the Left 180 degree { //Motor //Motor //Motor turn to the Left //Motor turn to the Righ

MOTO_REV(); vTaskDelay(50); turn_Left(); vTaskDelay(120); MOTO_FOR(); } } } void MOTO_FOR() { PORTB &=~ (1<<PB0); Low PORTB |= (1<<PB2); high PORTD |= (1<<PD2); high PORTD &=~ (1<<PD4); low } void MOTO_REV() { PORTB |= (1<<PB0); Low PORTB &=~ (1<<PB2); high PORTD &=~ (1<<PD2); high PORTD |= (1<<PD4); low } void MOTO_STOP() { PORTB &=~ (1<<PB0); Low PORTB &=~ (1<<PB2); high PORTD &=~ (1<<PD2); high PORTD &=~ (1<<PD4); low } void turn_Right() { PORTB &=~ (1<<PB0); Low PORTB |= (1<<PB2); high PORTD &=~ (1<<PD2); //Motor Left PIND 2 set //Motor Right PINB 2 set //Motor Right PINB 0 set //Motor Left PIND 4 set //Motor Left PIND 2 set //Motor Right PINB 2 set //Motor Right PINB 0 set //Motor Left PIND 4 set //Motor Left PIND 2 set //Motor Right PINB 2 set //Motor Right PINB 0 set //Motor Left PIND 4 set //Motor Left PIND 2 set //Motor Right PINB 2 set //Motor Right PINB 0 set

high PORTD |= (1<<PD4); low } void turn_Left() { PORTB |= (1<<PB0); Low PORTB &=~ (1<<PB2); high PORTD |= (1<<PD2); high PORTD &=~ (1<<PD4); low } */ void T1me() { vTaskDelay(15); } //Motor Left PIND 4 set //Motor Left PIND 2 set //Motor Right PINB 2 set //Motor Right PINB 0 set //Motor Left PIND 4 set

S-ar putea să vă placă și