alkid
Junior Member level 1

this is a code for tx but i can't figure which code to edit so that it can transmit using nRF24L01 transceiver and c8051f120 as in it have ADC, tiltSC and alarm which i don't need.
#include <c8051f200.h> // SFR declaration
sbit LED1 = P1^0;
sbit LED2 = P1^1;
sbit LED3 = P1^2;
sbit LED4 = P1^3;
sbit LED5 = P1^4;
sbit LED6 = P1^5;
sbit LED7 = P1^6;
sbit LED8 = P1^7;
sbit LED9 = P2^6;
sbit LED10 = P2^7;
sbit CE = P2^4;
sbit CSN = P2^5;
unsigned int data Received_1stB _at_ 0x10;
unsigned int data Status _at_ 0x12;
unsigned int TiltSC = 0;
unsigned int TimeSC = 0;
unsigned int ReminderSC = 0;
unsigned int Debounce = 0;
unsigned int TXcounter = 0;
unsigned int TXRXcomplete = 0;
unsigned long int x, y, z;
unsigned long int Timeadjustment = 125000;
unsigned int LEDoff1 = 50000;
unsigned int LEDoff2 = 50000;
unsigned int LEDoff3 = 50000;
int TimeadjustmentTX;
int Onalarm;
int Switch = 0;
int Switchalarm = 0;
int Sleep1 = 1, Sleep2 = 1, Sleep3 = 1;
/* Slouch sensor central processor program */
void main()
{
/* Chip initialization */
WDTCN = 0xDE;
WDTCN = 0xAD; // Disable watchdog timer
OSCICN = 0x14; // SYSCLK is set to be 2MHz
/* Port initialization */
PRT0MX = 0x3C; // Port 0 with int0, int1, T0 and T1 enabled
PRT2MX = 0x01; // Port 2 with SPI enabled P2.0 - P2.3
PRT0CF = 0x00; // All pin of port 0 is open-drain
PRT1CF = 0x7F; // All pin of port 1 is push-pull
PRT2CF = 0xFF; // All pin of port 2 is push-pull
/* SPI initialization*/
SPI0CKR = 0x03; // Transfer CLK is 250 kHz
SPI0CN |= 0x02; // Master mode
SPIEN = 1; // Enable SPI
/* Timer0 initialization */
TMOD = 0x66; // Timer0 and Timer1 operate as a counter with 8-bit auto-reload
TH0 = 0xFF;
TL0 = 0xFF;
TR0 = 1;
TF0 = 0;
/* Timer1 initialization*/
TH1 = 0xFF;
TL1 = 0xFF;
TR1 = 1;
TF1 = 0;
/* External interrupt0 and interrupt1 initialization*/
IE = 0x0F; // External interrupt0, external interrupt1, Timer0 and Timer1 interrupt are enabled
IT0 = 0; // EXT0 is set to level trigger
IT1 = 0; // EXT1 is set to level triggrr
IP = 0x01; // EXT0 has high priority
EA = 1; // Enable global interrupt
LED1 = 1;
LED8 = 1;
/* Initializaion of the transceiver as TX */
LED2 = 0;
LED9 = 0;
CSN = 1;
CE = 0; // Standby mode
CSN = 0;
SPI0DAT = 0x24; // Access SETUP_RETR register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0F; // 250uS retransmit delay and 15 re-transmit
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0x27; // Access STATUS register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x7E;
while (SPIF == 0) // Clear all flag
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0x31; // Access RX_PW_P0
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x01; // 1 byte RX payload
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xE1; // Flush TX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0x20; // Access CONFIG register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0A; // Powered up, TX, 1Bytes CRC
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x05; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x11; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
CSN = 0;
SPI0DAT = 0x20; // Access CONFIG register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0B; // Powered up, RX, 1Bytes CRC
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xE1; // Flush TX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xE2; // Flush RX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1;
while (1) // spin forever
{
/* Data transmisson ------ TX */
if (TXcounter == 1)
{
TXcounter = 0;
CE = 0; // Standby mode
CSN = 0;
SPI0DAT = 0x20; // Access CONFIG register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0A; // Powered up, TX, 1Bytes CRC
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
if (TiltSC == 1)
{
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xB1; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = TimeadjustmentTX; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
}
else if (TiltSC == 2)
{
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xB2; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = TimeadjustmentTX; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
}
else if (TiltSC == 3)
{
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xB3; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = TimeadjustmentTX; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
}
else if (TiltSC == 0)
{
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xB4; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = TimeadjustmentTX; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission01.
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
}
}
if (Onalarm == 1)
{
LEDoff1 = 0;
LEDoff2 = 0;
LEDoff3 = 0;
if (Switchalarm == 0)
{
LED1 = 0;
for (x = 3750; x > 0; x--) // For 0.125 second
{
}
}
if (Switchalarm == 1)
{
LED8 = 0;
for (x = 125000; x > 0; x--) // For 4 second
{
}
}
if (Switchalarm == 2)
{
LED8 = 0;
for (x = 125000; x > 0; x--) // For 4 second
{
}
LED1 = 0;
for (x = 3750; x > 0; x--) // For 0.125 second
{
}
}
LED1 = 1;
LED8 = 1;
if (Onalarm == 1)
{
for (x = Timeadjustment; x > 0; x--) // For 5 second in reset
{
}
}
}
else
{
LEDoff1--;
LEDoff2--;
LEDoff3--;
}
if (LEDoff1 == 0)
{
LEDoff1 = 1;
Sleep1 = 0;
LED2 = 1;
LED3 = 1;
LED4 = 1;
}
if (LEDoff2 == 0)
{
LEDoff2 = 1;
Sleep2 = 0;
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
if (LEDoff3 == 0)
{
LEDoff3 = 1;
Sleep3 = 0;
LED9 = 1;
LED10 = 1;
}
if (Sleep1 == 0 && Sleep2 == 0 && Sleep3 == 0 && Onalarm == 0)
{
Sleep1 = 1;
Sleep2 = 1;
Sleep3 = 1;
PCON |= 0x01;
y = 0;
y = 0;
y = 0;
}
}
}
// EXTI0_ISR
void EXTI0_ISR (void) interrupt 0
{
CE = 0;
TXRXcomplete = 1;
CSN = 0;
SPI0DAT = 0x07; // Access STATUS register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x88;
while (SPIF == 0)
{
}
SPIF = 0;
Status = SPI0DAT;
Status &= 0x40;
CSN = 1;
CSN = 0;
SPI0DAT = 0x27; // Access STATUS register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x7E;
while (SPIF == 0) // Clear all flag
{
}
SPIF = 0;
CSN = 1;
/* Data transmission ------ RX */
if (Status == 0x40 && TXRXcomplete == 1)
{
TXRXcomplete = 0;
CSN = 0;
SPI0DAT = 0x61;
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xA1;
while (SPIF == 0)
{
}
SPIF = 0;
Received_1stB = SPI0DAT;
CSN = 1;
if (Received_1stB == 0xE1)
{
Onalarm = 1;
}
else if (Received_1stB == 0xE2)
{
Onalarm = 0;
}
CSN = 0;
SPI0DAT = 0xE2; // Flush RX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
}
CSN = 0;
SPI0DAT = 0x20; // Access CONFIG register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0B; // Powered up, RX, 1Bytes CRC
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xE1; // Flush TX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1;
}
// EXTI1_ISR
void EXTI1_ISR (void) interrupt 2
{
/* Selecting the desired tilt threshold */
IE1 = 0;
LEDoff1 = 50000;
LEDoff2 = 50000;
LEDoff3 = 50000;
if (Debounce !=0)
{
Debounce--;
}
if (Debounce == 0)
{
Debounce = 2500;
if (Switch == 0)
{
TiltSC++;
LED2 = 0;
}
if (Switch == 1)
{
TimeSC++;
LED3 = 0;
}
if (Switch == 2)
{
ReminderSC++;
LED4 = 0;
}
}
LED5 = 1;
LED6 = 1;
LED7 = 1;
if (Switch == 0)
{
TXcounter = 1;
if (TiltSC == 1)
{
LED5 = 0;
}
if (TiltSC == 2)
{
LED5 = 0;
LED6 = 0;
}
if (TiltSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
}
if (TiltSC == 4)
{
TiltSC = 0;
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
}
if (Switch == 1)
{
TXcounter = 1;
if (TimeSC == 1)
{
LED5 = 0;
TimeadjustmentTX = 0xC1;
}
if (TimeSC == 2)
{
LED5 = 0;
LED6 = 0;
TimeadjustmentTX = 0xC2;
}
if (TimeSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
TimeadjustmentTX = 0xC3;
}
if (TimeSC == 4)
{
TimeSC = 0;
LED5 = 1;
LED6 = 1;
LED7 = 1;
TimeadjustmentTX = 0xC4;
}
}
if (Switch == 2)
{
if (ReminderSC == 1)
{
LED5 = 0;
Timeadjustment = 250000; // 10s
}
if (ReminderSC == 2)
{
LED5 = 0;
LED6 = 0;
Timeadjustment = 375000; // 15s
}
if (ReminderSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
Timeadjustment = 500000; // 20s
}
if (ReminderSC == 4)
{
ReminderSC = 0;
LED5 = 1;
LED6 = 1;
LED7 = 1;
Timeadjustment = 125000; // 5s
}
}
}
// T0I_ISR
void T0I_ISR (void) interrupt 1
{
TF0 = 0;
TR0 = 0;
LEDoff1 = 50000;
LEDoff2 = 50000;
LEDoff3 = 50000;
if (Switch == 0)
{
Switch = 1;
}
else if (Switch == 1)
{
Switch = 2;
}
else
{
Switch = 0;
}
LED5 = 1;
LED6 = 1;
LED7 = 1;
if (Switch == 0)
{
LED2 = 0;
LED3 = 1;
LED4 = 1;
if (TiltSC == 1)
{
LED5 = 0;
}
else if (TiltSC == 2)
{
LED5 = 0;
LED6 = 0;
}
else if (TiltSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
}
else if (TiltSC == 4)
{
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
}
if (Switch == 1)
{
LED2 = 1;
LED3 = 0;
LED4 = 1;
if (TimeSC == 1)
{
LED5 = 0;
}
else if (TimeSC == 2)
{
LED5 = 0;
LED6 = 0;
}
else if (TimeSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
}
else if (TimeSC == 4)
{
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
}
if (Switch == 2)
{
LED2 = 1;
LED3 = 1;
LED4 = 0;
if (ReminderSC == 1)
{
LED5 = 0;
}
else if (ReminderSC == 2)
{
LED5 = 0;
LED6 = 0;
}
else if (ReminderSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
}
else if (ReminderSC == 4)
{
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
}
TR0 = 1;
}
// T1I_ISR
void T1I_ISR (void) interrupt 3
{
TF1 = 0;
TR1 = 0;
LEDoff1 = 50000;
LEDoff2 = 50000;
LEDoff3 = 50000;
if (Switchalarm == 0)
{
Switchalarm = 1;
}
else if (Switchalarm == 1)
{
Switchalarm = 2;
}
else
{
Switchalarm = 0;
}
LED9 = 1;
LED10 = 1;
if (Switchalarm == 0)
{
LED9 = 0;
}
if (Switchalarm == 1)
{
LED10 = 0;
}
if (Switchalarm == 2)
{
LED9 = 0;
LED10 = 0;
}
TR1 = 1;
}
#include <c8051f200.h> // SFR declaration
sbit LED1 = P1^0;
sbit LED2 = P1^1;
sbit LED3 = P1^2;
sbit LED4 = P1^3;
sbit LED5 = P1^4;
sbit LED6 = P1^5;
sbit LED7 = P1^6;
sbit LED8 = P1^7;
sbit LED9 = P2^6;
sbit LED10 = P2^7;
sbit CE = P2^4;
sbit CSN = P2^5;
unsigned int data Received_1stB _at_ 0x10;
unsigned int data Status _at_ 0x12;
unsigned int TiltSC = 0;
unsigned int TimeSC = 0;
unsigned int ReminderSC = 0;
unsigned int Debounce = 0;
unsigned int TXcounter = 0;
unsigned int TXRXcomplete = 0;
unsigned long int x, y, z;
unsigned long int Timeadjustment = 125000;
unsigned int LEDoff1 = 50000;
unsigned int LEDoff2 = 50000;
unsigned int LEDoff3 = 50000;
int TimeadjustmentTX;
int Onalarm;
int Switch = 0;
int Switchalarm = 0;
int Sleep1 = 1, Sleep2 = 1, Sleep3 = 1;
/* Slouch sensor central processor program */
void main()
{
/* Chip initialization */
WDTCN = 0xDE;
WDTCN = 0xAD; // Disable watchdog timer
OSCICN = 0x14; // SYSCLK is set to be 2MHz
/* Port initialization */
PRT0MX = 0x3C; // Port 0 with int0, int1, T0 and T1 enabled
PRT2MX = 0x01; // Port 2 with SPI enabled P2.0 - P2.3
PRT0CF = 0x00; // All pin of port 0 is open-drain
PRT1CF = 0x7F; // All pin of port 1 is push-pull
PRT2CF = 0xFF; // All pin of port 2 is push-pull
/* SPI initialization*/
SPI0CKR = 0x03; // Transfer CLK is 250 kHz
SPI0CN |= 0x02; // Master mode
SPIEN = 1; // Enable SPI
/* Timer0 initialization */
TMOD = 0x66; // Timer0 and Timer1 operate as a counter with 8-bit auto-reload
TH0 = 0xFF;
TL0 = 0xFF;
TR0 = 1;
TF0 = 0;
/* Timer1 initialization*/
TH1 = 0xFF;
TL1 = 0xFF;
TR1 = 1;
TF1 = 0;
/* External interrupt0 and interrupt1 initialization*/
IE = 0x0F; // External interrupt0, external interrupt1, Timer0 and Timer1 interrupt are enabled
IT0 = 0; // EXT0 is set to level trigger
IT1 = 0; // EXT1 is set to level triggrr
IP = 0x01; // EXT0 has high priority
EA = 1; // Enable global interrupt
LED1 = 1;
LED8 = 1;
/* Initializaion of the transceiver as TX */
LED2 = 0;
LED9 = 0;
CSN = 1;
CE = 0; // Standby mode
CSN = 0;
SPI0DAT = 0x24; // Access SETUP_RETR register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0F; // 250uS retransmit delay and 15 re-transmit
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0x27; // Access STATUS register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x7E;
while (SPIF == 0) // Clear all flag
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0x31; // Access RX_PW_P0
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x01; // 1 byte RX payload
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xE1; // Flush TX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0x20; // Access CONFIG register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0A; // Powered up, TX, 1Bytes CRC
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x05; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x11; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
CSN = 0;
SPI0DAT = 0x20; // Access CONFIG register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0B; // Powered up, RX, 1Bytes CRC
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xE1; // Flush TX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xE2; // Flush RX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1;
while (1) // spin forever
{
/* Data transmisson ------ TX */
if (TXcounter == 1)
{
TXcounter = 0;
CE = 0; // Standby mode
CSN = 0;
SPI0DAT = 0x20; // Access CONFIG register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0A; // Powered up, TX, 1Bytes CRC
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
if (TiltSC == 1)
{
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xB1; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = TimeadjustmentTX; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
}
else if (TiltSC == 2)
{
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xB2; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = TimeadjustmentTX; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
}
else if (TiltSC == 3)
{
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xB3; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = TimeadjustmentTX; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
}
else if (TiltSC == 0)
{
CSN = 0;
SPI0DAT = 0xA0; // Write payload
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xB4; // 1st data byte
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = TimeadjustmentTX; // 2nd data byte
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1; // Start transmisson
y = 0;
CE = 0; // End transmission01.
for (x = 3000; x > 0; x--) // For 0.1 second
{
}
}
}
if (Onalarm == 1)
{
LEDoff1 = 0;
LEDoff2 = 0;
LEDoff3 = 0;
if (Switchalarm == 0)
{
LED1 = 0;
for (x = 3750; x > 0; x--) // For 0.125 second
{
}
}
if (Switchalarm == 1)
{
LED8 = 0;
for (x = 125000; x > 0; x--) // For 4 second
{
}
}
if (Switchalarm == 2)
{
LED8 = 0;
for (x = 125000; x > 0; x--) // For 4 second
{
}
LED1 = 0;
for (x = 3750; x > 0; x--) // For 0.125 second
{
}
}
LED1 = 1;
LED8 = 1;
if (Onalarm == 1)
{
for (x = Timeadjustment; x > 0; x--) // For 5 second in reset
{
}
}
}
else
{
LEDoff1--;
LEDoff2--;
LEDoff3--;
}
if (LEDoff1 == 0)
{
LEDoff1 = 1;
Sleep1 = 0;
LED2 = 1;
LED3 = 1;
LED4 = 1;
}
if (LEDoff2 == 0)
{
LEDoff2 = 1;
Sleep2 = 0;
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
if (LEDoff3 == 0)
{
LEDoff3 = 1;
Sleep3 = 0;
LED9 = 1;
LED10 = 1;
}
if (Sleep1 == 0 && Sleep2 == 0 && Sleep3 == 0 && Onalarm == 0)
{
Sleep1 = 1;
Sleep2 = 1;
Sleep3 = 1;
PCON |= 0x01;
y = 0;
y = 0;
y = 0;
}
}
}
// EXTI0_ISR
void EXTI0_ISR (void) interrupt 0
{
CE = 0;
TXRXcomplete = 1;
CSN = 0;
SPI0DAT = 0x07; // Access STATUS register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x88;
while (SPIF == 0)
{
}
SPIF = 0;
Status = SPI0DAT;
Status &= 0x40;
CSN = 1;
CSN = 0;
SPI0DAT = 0x27; // Access STATUS register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x7E;
while (SPIF == 0) // Clear all flag
{
}
SPIF = 0;
CSN = 1;
/* Data transmission ------ RX */
if (Status == 0x40 && TXRXcomplete == 1)
{
TXRXcomplete = 0;
CSN = 0;
SPI0DAT = 0x61;
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0xA1;
while (SPIF == 0)
{
}
SPIF = 0;
Received_1stB = SPI0DAT;
CSN = 1;
if (Received_1stB == 0xE1)
{
Onalarm = 1;
}
else if (Received_1stB == 0xE2)
{
Onalarm = 0;
}
CSN = 0;
SPI0DAT = 0xE2; // Flush RX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
}
CSN = 0;
SPI0DAT = 0x20; // Access CONFIG register
while (SPIF == 0)
{
}
SPIF = 0;
SPI0DAT = 0x0B; // Powered up, RX, 1Bytes CRC
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CSN = 0;
SPI0DAT = 0xE1; // Flush TX FIFO
while (SPIF == 0)
{
}
SPIF = 0;
CSN = 1;
CE = 1;
}
// EXTI1_ISR
void EXTI1_ISR (void) interrupt 2
{
/* Selecting the desired tilt threshold */
IE1 = 0;
LEDoff1 = 50000;
LEDoff2 = 50000;
LEDoff3 = 50000;
if (Debounce !=0)
{
Debounce--;
}
if (Debounce == 0)
{
Debounce = 2500;
if (Switch == 0)
{
TiltSC++;
LED2 = 0;
}
if (Switch == 1)
{
TimeSC++;
LED3 = 0;
}
if (Switch == 2)
{
ReminderSC++;
LED4 = 0;
}
}
LED5 = 1;
LED6 = 1;
LED7 = 1;
if (Switch == 0)
{
TXcounter = 1;
if (TiltSC == 1)
{
LED5 = 0;
}
if (TiltSC == 2)
{
LED5 = 0;
LED6 = 0;
}
if (TiltSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
}
if (TiltSC == 4)
{
TiltSC = 0;
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
}
if (Switch == 1)
{
TXcounter = 1;
if (TimeSC == 1)
{
LED5 = 0;
TimeadjustmentTX = 0xC1;
}
if (TimeSC == 2)
{
LED5 = 0;
LED6 = 0;
TimeadjustmentTX = 0xC2;
}
if (TimeSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
TimeadjustmentTX = 0xC3;
}
if (TimeSC == 4)
{
TimeSC = 0;
LED5 = 1;
LED6 = 1;
LED7 = 1;
TimeadjustmentTX = 0xC4;
}
}
if (Switch == 2)
{
if (ReminderSC == 1)
{
LED5 = 0;
Timeadjustment = 250000; // 10s
}
if (ReminderSC == 2)
{
LED5 = 0;
LED6 = 0;
Timeadjustment = 375000; // 15s
}
if (ReminderSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
Timeadjustment = 500000; // 20s
}
if (ReminderSC == 4)
{
ReminderSC = 0;
LED5 = 1;
LED6 = 1;
LED7 = 1;
Timeadjustment = 125000; // 5s
}
}
}
// T0I_ISR
void T0I_ISR (void) interrupt 1
{
TF0 = 0;
TR0 = 0;
LEDoff1 = 50000;
LEDoff2 = 50000;
LEDoff3 = 50000;
if (Switch == 0)
{
Switch = 1;
}
else if (Switch == 1)
{
Switch = 2;
}
else
{
Switch = 0;
}
LED5 = 1;
LED6 = 1;
LED7 = 1;
if (Switch == 0)
{
LED2 = 0;
LED3 = 1;
LED4 = 1;
if (TiltSC == 1)
{
LED5 = 0;
}
else if (TiltSC == 2)
{
LED5 = 0;
LED6 = 0;
}
else if (TiltSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
}
else if (TiltSC == 4)
{
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
}
if (Switch == 1)
{
LED2 = 1;
LED3 = 0;
LED4 = 1;
if (TimeSC == 1)
{
LED5 = 0;
}
else if (TimeSC == 2)
{
LED5 = 0;
LED6 = 0;
}
else if (TimeSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
}
else if (TimeSC == 4)
{
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
}
if (Switch == 2)
{
LED2 = 1;
LED3 = 1;
LED4 = 0;
if (ReminderSC == 1)
{
LED5 = 0;
}
else if (ReminderSC == 2)
{
LED5 = 0;
LED6 = 0;
}
else if (ReminderSC == 3)
{
LED5 = 0;
LED6 = 0;
LED7 = 0;
}
else if (ReminderSC == 4)
{
LED5 = 1;
LED6 = 1;
LED7 = 1;
}
}
TR0 = 1;
}
// T1I_ISR
void T1I_ISR (void) interrupt 3
{
TF1 = 0;
TR1 = 0;
LEDoff1 = 50000;
LEDoff2 = 50000;
LEDoff3 = 50000;
if (Switchalarm == 0)
{
Switchalarm = 1;
}
else if (Switchalarm == 1)
{
Switchalarm = 2;
}
else
{
Switchalarm = 0;
}
LED9 = 1;
LED10 = 1;
if (Switchalarm == 0)
{
LED9 = 0;
}
if (Switchalarm == 1)
{
LED10 = 0;
}
if (Switchalarm == 2)
{
LED9 = 0;
LED10 = 0;
}
TR1 = 1;
}