-
-
Save Ryanhu1015/f20e8a0900e10ca6bd0e9b780f505454 to your computer and use it in GitHub Desktop.
embedded rookie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "globalvar.h" // button2_time_cnt is defined in the header file | |
#include "function.h" | |
#define P3_5 1 // if P3_5 is 1, it will be the transmitter | |
#define period 1000 | |
unsigned char Packet_Tx[8]; // if initialize, this array will be a "constant", which can't be modified in code. | |
void WriteFIFO(void); | |
void WriteFIFO(void) | |
{ | |
unsigned char i; | |
for (i = 0; i < 8; i++) | |
RFLIB_WriteReg(TXFIFO_REG + i, Packet_Tx[i]); | |
} | |
void main(void) | |
{ | |
//hardware initialization | |
//timer0, rf, other settings are done here | |
if (P3_5) | |
{ | |
while (1) | |
{ | |
if (button2_time_cnt >= period) | |
{ | |
//something here to store the state about the num of light are on | |
for (i = 0; i < 8; i++) | |
{ | |
Packet_Tx[i] = 0x11 * (i + 1); // this can be modify, like specify the first two bytes to be the info of ID... | |
// and third byte will be the state of light... | |
} | |
WriteFIFO(); // load data in specific register and wait to transmit | |
RFLIB_StrobeCmd(CMD_TX); //entry tx & transmit | |
Delay10us(1); | |
while ((RFLIB_ReadReg(MODEC1_REG) & 0x80) == 0x80); //wait transmit completed | |
TimeoutFlag = 0; | |
RFLIB_StrobeCmd(CMD_RX); //entry rx | |
Delay10us(1); | |
while ((RFLIB_ReadReg(MODEC1_REG) & 0x80) == 0x80 && TimeoutFlag == 0); //wait receive completed | |
if (TimeoutFlag) | |
{ | |
RFLIB_StrobeCmd(CMD_STBY); //exit rx mode | |
continue; | |
} | |
RxPacket(); | |
Delay10us(1); | |
} | |
} | |
} | |
else | |
{ | |
//the part of receiver | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment