void InitTimer1(){
T1CON = 0x8000;
T1IE_bit = 1;
T1IF_bit = 0;
IPC0 = IPC0 | 0x1000;
PR1 = 20000;
}
void Timer1Interrupt() iv IVT_ADDR_T1INTERRUPT{
T1IF_bit = 0;
//Enter your code here
readBuffer();
}
void Main()
{
Init();
InitTimer1();
do
{
Lcd_Out(1,1, "Drone-X");
PWM1_MC_Set_Duty(Data_in[1]*100, 1);
PWM1_MC_Set_Duty(0*100, 2);
ByteToHex(Data_in[0], txt);
Lcd_Out(2, 1, txt);
ByteToHex(Data_in[1], txt);
Lcd_Out(2, 4, txt);
ByteToHex(Data_in[2], txt);
Lcd_Out(2, 7, txt);
ByteToHex(Data_in[3], txt);
Lcd_Out(2, 10, txt);
ByteToHex(Data_in[4], txt);
Lcd_Out(2, 13, txt);
}while (1);
}
void Init()
{
Unlock_IOLOCK();
RPINR20 = 0b0000000000000111;
RPOR2 = 0b0000100000000111;
lock_IOLOCK();
AD1PCFGL = 0xFFFF; // digital not analog
CMCON = 7;
TRISB.B8 = 0;
TRISB.B14 = 0;
TRISB.B12 = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
SPI1_Init();
Delay_ms(100);
RF_init_TX();
Delay_ms(100);
PWM1_MC_Init(1000, 3, 0xff, 0);
PWM1_MC_Set_Duty(1000, 1);
PWM1_MC_Start();
}
char readBuffer(){
char i, s;
Ce_pin = 0;
s = Get_FIFO_Flags();
if((s & 2) != 0){
toggleCSN();
SPI1_Write(R_RX_PAYLOAD);
for(i=0; i < dataLength; i++){ Data_In[i] = SPI1_Read(0);} //ITS HERE THAT seem to stop my PWM *********************************
}
Csn_pin = 1;
Ce_pin = 1;
return s;
}