Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.c
- * Author: abdullah
- *
- * Created on 10 Haziran 2012 Pazar, 14:43
- */
- #include <xc.h> // Include the header file needed by the compiler
- #include "RTOS.h" // Include the header for co-operative RTOS.
- __CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & IOSCFS_4MHZ & BOREN_ON);
- unsigned char OS_currentTask; // This register holds the current task's place in the array OS_tasks
- unsigned char OS_tasks[4]; // This array holds PCL and PCLATH for tasks. This array will have..
- // .. (number of tasks)*2 elements, since every task occupies 2 places.
- void fTask1(void); // Prototype the function for task1.
- void fTask2(void); // Prototype the function for task2.
- void main(void) @ 0x0001
- {
- TRISA = 0; // Set all of the PORTA pins as outputs.
- TRISC = 0; // Set all of the PORTC pins as outputs.
- ANSEL = 0; // Set all of the analog input pins as digital i/o.
- PORTA = 0; // Clear PORTA bits.
- PORTC = 0; // Clear PORTC bits.
- OS_currentTask = 0; // Current task is first task.
- fTask1(); // Call task to initialize it.
- OS_currentTask += 2; // Increment task pointer by two since every task occupies 2 places in the array.
- fTask2(); // Call task to initialize it.
- OS_runTasks(4); // Run the tasks in order. The argument of this macro takes is: (Number of tasks) * 2
- }
- void fTask1(void)
- {
- OS_initializeTask(); // Initialize the task so that task runner can get its ingredients.
- while (1)
- {
- PORTC = 0xAA;
- OS_yield(); // Yield CPU to other tasks.
- PORTC = 0x55;
- OS_yield(); // Yield CPU to other tasks.
- }
- }
- void fTask2(void)
- {
- OS_initializeTask(); // Initialize the task so that task runner can get its ingredients.
- while (1)
- {
- PORTC = 0xFF;
- OS_yield(); // Yield CPU to other tasks.
- PORTC = 0x00;
- OS_yield(); // Yield CPU to other tasks.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement