سلام دوستای گلم من یکم تازه واردم :biggrin:
اگه کسی میتونه کمکم کنه که بدونم مشکل برنامه زیر چیه؟
این برنامه با استفاده از mplabc18 کامپایل شده
پروژه اول:روشن و خاموش کردن چند led
برنامه باید اهداف زیر را در بر بگیرد
اگر برنامه بالا را RUNکنید خطا دریافت خواهید کرد :angry:
اگه کسی میتونه کمکم کنه که بدونم مشکل برنامه زیر چیه؟
این برنامه با استفاده از mplabc18 کامپایل شده
پروژه اول:روشن و خاموش کردن چند led
برنامه باید اهداف زیر را در بر بگیرد
Task 1, calledtask_B0, flashes the LED connected to port RB0 at a rate of 250ms
Task 2, calledtask_B1, flashes the LED connected to port RB1 at a rate of 500ms
Task 3, calledtask_B2, flashes the LED connected to port RB2 once a second
Task 2, calledtask_B1, flashes the LED connected to port RB1 at a rate of 500ms
Task 3, calledtask_B2, flashes the LED connected to port RB2 once a second
کد:
#include <salvo.h>
#undef OSC //necessary for this Salvo version, as it also defines this name
#include <p18f452.h>
#include <timers.h>
#pragma config OSC = HS, OSCS = OFF //HS oscillator, oscillator switch off
#pragma config PWRT = ON, BOR = OFF //pwr-up timer on, brown-out detect off
#pragma config WDT = OFF //watchdog timer off
#pragma config STVR = ON, LVP = OFF //Stack overflow reset enable on,
//low voltage programming off
//These functions are tasks.
void b0_Task( void );
void b1_Task( void );
void b2_Task( void );
//Define labels for context switches
_OSLabel(b0_Task1)
_OSLabel(b1_Task1)
_OSLabel(b2_Task1)
void b0_Task(void)
{
for (;;) { //infinite loop
TRISBbits.TRISB0=0;
PORTBbits.RB0=~ PORTBbits.RB0;
OS_Delay (25,b0_Task1); //Task switch, delay for 20x10ms, (200ms)
//Use smaller delay for simulation
}
}
void b1_Task(void)
{
for (;;) { //infinite loop
TRISBbits.TRISB1=0;
PORTBbits.RB1=~ PORTBbits.RB1;
OS_Delay (50,b1_Task1); //Task switch, delay for 50x10ms, (500ms)
//Use smaller delay for simulation
}
}
void b2_Task(void)
{
for (;;) { //infinite loop
TRISBbits.TRISB2=0;
PORTBbits.RB2=~ PORTBbits.RB2;
OS_Delay (100,b2_Task1); //Task switch, delay for 20x10ms, (200ms)
//Use smaller delay for simulation
}
}
/***************************************************************************
Main
***************************************************************************/
void main( void )
{
//Initialise
TRISB = 0b10000000; //Setall Port b bits to output, except bit 7.
PORTB = 0; //Setall Port b outputs low
//Initialise RTOS
OSInit();
OSCreateTask(b0_Task, OSTCBP(1), 10); //Create the b0_Task Task
OSCreateTask(b1_Task, OSTCBP(2), 10); //Create the b1_Task Task
OSCreateTask(b2_Task, OSTCBP(3), 10); //Create the b2_Task Task
//Enable interrupts
OSEi();
//Scheduling Loop
for (;;)
OSSched();
}





دیدگاه