« BackView source: C07-TX.c
// *********************************************************************
#include "../includes/template-basic.h"
#include "../includes/RFPGMTR-LITE.h"
// *********************************************************************
#define BTN1 PORTB.5
#define BTN2 PORTB.4 // Escape from RFPGM - checked by OS
#define BTN3 PORTB.6 // To enter RF PGM mode
#define BTN4 PORTB.2 // To enter RF PGM mode
#define ENTER_RFPGM (!BTN3 && !BTN4)
// *********************************************************************
void initHW(void);
void tryEnterRFPGM(void);
// *********************************************************************
void APPLICATION()
{
enableRFPGM();
// disableRFPGM();
initHW();
while (1)
{
clrwdt();
GIE = 0; // Disable all interrupts
SWDTEN = 0; // Minimize consumption (disable WDT)
RBIE = 1; // Enable wake-up on pin change
iqrfSleep();
RBIF = 0; // Requested: clear flag
SWDTEN = 1; // Enable WDT
waitDelay(10); // Debounce time 100 ms
if (ENTER_RFPGM)
{
tryEnterRFPGM();
goto loop_end;
} // RC-05 command
else if (!BTN1) bufferRF[1] = '1';
else if (!BTN2) bufferRF[1] = '2'; // Escape from RFPGM - controled by OS
else if (!BTN3) bufferRF[1] = '3';
else if (!BTN4) bufferRF[1] = '4';
else
goto loop_end; // No button pressed
bufferRF[2] = getSupplyVoltage(); // Supply voltage level (1 to 15)
bufferRF[0] = 'S';
DLEN = 3; // 3 B RF packet length
PIN = 0;
RFTXpacket(); // Transmit
loop_end:
while (!BTN1 || !BTN2 || !BTN3 || !BTN4) // Wait for all buttons released
clrwdt();
waitDelay(10); // Debounce time 100 ms
}
}
// ----------------------------------------------------------------------
void initHW(void)
{
TRISC &= 0b00000011; // Unused pins as output
TRISA &= 0b11010110; // Unused pins as output
TRISA.0=0;
TRISB = 0b0111.1111; // I/O pins configuration
OPTION.7 = 0; // PORTB pull-ups enabled
WPUB = 0b0111.0100; // Pull-ups for buttons enabled
IOCB = 0b0111.0100; // Interrupt-on-change for buttons enabled
}
// ----------------------------------------------------------------------
void tryEnterRFPGM(void)
{
uns8 i = 0;
while (ENTER_RFPGM)
{
clrwdt();
waitDelay(10);
i++; // Every 100 ms
if (i > 50) // > 5 s button press to enter RFPGM
{
runRFPGM();
break;
}
}
}
// *********************************************************************
Download:
C07-TX.c