#define StartSendingK1on PORTBbits.RB0 // input
#define StartSendingK1off PORTBbits.RB1 // input
#define StartSendingK2on PORTBbits.RB2 // input
#define StartSendingK2off PORTBbits.RB3 // input
#define LED_KEY LATBbits.LATB4 // Output
#define LED_RUN LATBbits.LATB5 // Output
#define RF_TX LATDbits.LATD0 // Output
#define RF_Alim LATEbits.LATE8 // Output
#define LED_CN LATDbits.LATD1 // Output
void setup_ports(void);
void DelayNmSec(unsigned int N);
void Delay(unsigned int N);
void InitUART();
struct {
unsigned Running : 1;
unsigned CheckRX : 1;
unsigned SendTX : 1;
unsigned SendData : 1;
unsigned RF_Sending : 1;
unsigned unused : 11;
} Flags;
//-----------------------------------------------------------------------------
// Setup
//-----------------------------------------------------------------------------
void setup_ports(void)
{
ADPCFG=0xFFFF; // all PORTB = Digital(1) : no ADC
// Clear All Ports Prior to defining I/O
PORTB=0; //Initialize LED pin data to off state
PORTC=0;
PORTD=0;
PORTE=0;
// Now set pin direction registers
TRISB = 0xFFCF; // RB0-3 inputs, RB0 StartSending PushB in, RB4 LED_KEY out, RB5 LED_RUN out 1100|1111
TRISC = 0xFFFF; // U1ATX/RC13 in , U1ATX/RC14 out INUTILE de les configurer ainsi car directement on configure l UART
TRISD = 0xFFFC; // RD1 RF24G_CE out , RD0 RF24G_CS out
TRISE = 0x00FF; // RE8 RF_Alim out, le reste input 0|1111|1111
TRISF = 0xFFFB; // SDI1/RF2 in, SDO1/RF3 out : 1011 ou 1x11 car SDI1 doit se programmer via le TRISF
}
//-----------------------------------------------------------------------------
// intitialise ChangeNotification CN7 et l interruption
//-----------------------------------------------------------------------------
void initChangeNotification(void)
{
// CNEN1 = 0x000C; // RB0-RB1 donc CN2-3
CNEN1 = 0x003C; // RB0-RB3 donc CN2-5
CNPU1= 0; CNPU2=0; // No pull-up on input change
IFS0bits.CNIF = 0; // Clear IF bit
IPC3bits.CNIP = 3; // assigning Interrupt Priority to IPC Register
IEC0bits.CNIE = 1; // assiging Interrupt Enable
}