?? configure.c
字號:
EEPROMButton2Char=BUTTON2_CHAR;
Button1Char=EEPROMButton1Char;
Button2Char=EEPROMButton2Char;
TXANALOG=EEPROMTXANALOG;
RXANALOG=EEPROMRXANALOG;
EEPROMPA_POWER = EEPROMCC1020Config[CC1020_PA_POWER-1];
PA_POWER = EEPROMPA_POWER;
EEPROMPreambleLength = PREAMBLE_LENGTH;
UnitAddress=0x01;
SetupCC1020All();
}
// Lets the user set up which characters are transmitted when the buttons are pressed
void ButtonConfig(void)
{
writestr("Enter character to be sent when button 1 is pressed: ");
EEPROMButton1Char=getchar();
writeln("");
writestr("\n\rEnter character to be sent when button 2 is pressed: ");
EEPROMButton2Char=getchar();
writeln("");
Button1Char=EEPROMButton1Char;
Button2Char=EEPROMButton2Char;
}
// Lets the user select specific TX mode
void SetTXmode(char PA_POWER)
{
volatile char input_valid, input_char;
volatile int i;
writeln("Select TX mode:\n\r");
writeln("1 - TX no modulation");
writeln("2 - TX with modulation (PN9)");
writestr("Enter choice : ");
input_valid = FALSE;
while(input_valid == FALSE)
{
input_char = getchar();
switch( input_char ){
// TX with no modulation
case '1':
SetupCC1020TX(TXANALOG, PA_POWER);
WriteToCC1020Register(CC1020_MODEM,ReadFromCC1020Register(CC1020_MODEM)&~0x04);
OPTION=0x80; // INT on falling edge
TRISC&=~(0x02); // Set DIO as output
input_valid = TRUE;
break;
// TX with PN9 modulation
case '2':
SetupCC1020TX(TXANALOG, PA_POWER);
WriteToCC1020Register(CC1020_MODEM,ReadFromCC1020Register(CC1020_MODEM)|0x04);
OPTION=0x80; // INT on falling edge
TRISC&=~(0x02); // Set DIO as output
DIO=1;
for(i=0x0010; i > 0; i--); //ca.150 usec
DIO=0;
for(i=0x0010; i > 0; i--); //ca.150 usec
DIO=1;
for(i=0x0010; i > 0; i--); //ca.150 usec
DIO=0;
input_valid = TRUE;
break;
// Invalid user input
default:
writeln("\n\rInvalid choice!\n\r");
writeln("1 - TX no modulation");
writeln("2 - TX with modulation (PN9)");
writestr("Enter choice : ");
input_valid = FALSE;
break;
}
}
if((ReadFromCC1020Register(CC1020_MODEM)&0x04) == 0x04){
writeln("\n\rTX with modulation (PN9)");
}else{
writeln("\n\rTX no modulation");
}
}
// Lets the user set PA power
void SetPApower(void)
{
volatile char input_valid, input_char, freq_band;
volatile int i;
writeln("Select PA power:\n\r");
// Display menu according to frequency band:
if((ReadFromCC1020Register(CC1020_ANALOG)&0x80)==0x80){
// 804-940 MHz band
writeln("1 - -20 dBm");
writeln("2 - -10 dBm");
writeln("3 - 0 dBm");
writeln("4 - +5 dBm");
writeln("5 - MAX");
freq_band = 1;
}else{
// 402-470 MHz band
writeln("1 - -20 dBm");
writeln("2 - -10 dBm");
writeln("3 - 0 dBm");
writeln("4 - +10 dBm");
writeln("5 - MAX");
freq_band = 0;
}
writestr("Enter choice : ");
input_valid = FALSE;
while(input_valid == FALSE)
{
input_char = getchar();
switch( input_char ){
// PA power = -20 dBm
case '1':
if(freq_band == 1){
WriteToCC1020Register(CC1020_PA_POWER, EEPROMPA_POWER=0x03);
}else{
WriteToCC1020Register(CC1020_PA_POWER, EEPROMPA_POWER=0x01);
}
input_valid = TRUE;
break;
// PA power = -10 dBm
case '2':
if(freq_band == 1){
WriteToCC1020Register(CC1020_PA_POWER, EEPROMPA_POWER=0x0A);
}else{
WriteToCC1020Register(CC1020_PA_POWER, EEPROMPA_POWER=0x04);
}
input_valid = TRUE;
break;
// PA power = 0 dBm
case '3':
if(freq_band == 1){
WriteToCC1020Register(CC1020_PA_POWER, EEPROMPA_POWER=0xA0);
}else{
WriteToCC1020Register(CC1020_PA_POWER, EEPROMPA_POWER=0x0E);
}
input_valid = TRUE;
break;
// PA power = +5/+10 dBm
case '4':
WriteToCC1020Register(CC1020_PA_POWER, EEPROMPA_POWER=0xFF);
input_valid = TRUE;
break;
// PA power = MAX dBm
case '5':
WriteToCC1020Register(CC1020_PA_POWER, EEPROMPA_POWER=0xFF);
input_valid = TRUE;
break;
// Invalid user input
default:
writeln("\n\rInvalid choice!\n\r");
// Display menu according to frequency band:
if(freq_band == 1){
// 804-940 MHz band
writeln("1 - -20 dBm");
writeln("2 - -10 dBm");
writeln("3 - 0 dBm");
writeln("4 - +5 dBm");
writeln("5 - MAX");
}else{
// 402-470 MHz band
writeln("1 - -20 dBm");
writeln("2 - -10 dBm");
writeln("3 - 0 dBm");
writeln("4 - +10 dBm");
writeln("5 - MAX");
}
writestr("Enter choice : ");
input_valid = FALSE;
break;
}
}
// Display actual PA power according to frequency band:
if(freq_band == 1){
// 804-940 MHz band:
if(ReadFromCC1020Register(CC1020_PA_POWER) == 0x03){
writeln("\n\rPA power = -20 dBm");
}else if(ReadFromCC1020Register(CC1020_PA_POWER) == 0x0A){
writeln("\n\rPA power = -10 dBm");
}else if(ReadFromCC1020Register(CC1020_PA_POWER) == 0xA0){
writeln("\n\rPA power = 0 dBm");
}else if(ReadFromCC1020Register(CC1020_PA_POWER) == 0xFF){
writeln("\n\rPA power = +5 dBm");
}else{
// Do nothing...
}
}else{
// 402-470 MHz band:
if(ReadFromCC1020Register(CC1020_PA_POWER) == 0x01){
writeln("\n\rPA power = -20 dBm");
}else if(ReadFromCC1020Register(CC1020_PA_POWER) == 0x04){
writeln("\n\rPA power = -10 dBm");
}else if(ReadFromCC1020Register(CC1020_PA_POWER) == 0x0E){
writeln("\n\rPA power = 0 dBm");
}else if(ReadFromCC1020Register(CC1020_PA_POWER) == 0xFF){
writeln("\n\rPA power = +10 dBm");
}else{
// Do nothing...
}
}
}
// Lets the user set number of preamble
void SetPreambleLength(void){
char input_str[4], i;
writestr("Select preamble length (MAX = 10 bytes): ");
// Empty input string
for(i = 0; i < 4; i++){
input_str[i] = 0;
}
for(i = 0; (i < 3) && ((input_str[i] = getchar()) != '\r'); i++){
putchar(input_str[i]);
}
EEPROMPreambleLength = MAX(1, MIN(atoi(input_str), 10));
writestr("\n\rPreamble length = ");
writeint(EEPROMPreambleLength);
writestr(" bytes\n\r");
}
// Lets the user access any CC1020 register, for read or write operation
void AccessCC1020Register(void){
char i;
char input_str[3];
char reg_addr;
char reg_value;
char reg_action;
// Access CC1020 register according to user input:
while(TRUE){
// Empty input string
for(i = 0; i < 3; i++){
input_str[i]=0;
}
writestr("\n\rRegister address: ");
for(i = 0; (i < 2); i++){
if((input_str[i] = getchar()) == '\r'){
input_str[i] = 0;
break;
}else{
}
putchar(input_str[i]);
}
reg_addr = ((hexdigit2int(input_str[0]) << 4) & 0xF0) | (hexdigit2int(input_str[1]) & 0x0F);
if(((reg_addr >= 0x00) && (reg_addr <= 0x27)) || ((reg_addr >= 0x40) && (reg_addr <= 0x4B))){
// Empty input string
for(i = 0; i < 3; i++){
input_str[i]=0;
}
writestr("\n\rRegister action (w/r): ");
reg_action = getchar();
putchar(reg_action);
reg_action = toupper(reg_action);
if(reg_action == 'W'){
writestr("\n\rRegister value: ");
for(i = 0; (i < 2); i++){
if((input_str[i] = getchar()) == '\r'){
input_str[i] = 0;
break;
}else{
}
putchar(input_str[i]);
}
reg_value = ((hexdigit2int(input_str[0]) << 4) & 0xF0) | (hexdigit2int(input_str[1]) & 0x0F);
if((reg_addr > 0x00) && (reg_addr <= 0x20)){
EEPROMCC1020Config[reg_addr-1] = reg_value;
if(reg_addr == CC1020_PA_POWER){
EEPROMPA_POWER = reg_value;
}else{
}
}else{
}
WriteToCC1020Register(reg_addr, reg_value);
break;
}else if(reg_action == 'R'){
break;
}else{
writestr("\n\rInvalid register action (valid: r/w) !");
}
}else{
writestr("\n\rInvalid register address (valid: 00-20) !");
}
}
writestr("\n\rRegister status = ");
writehex(ReadFromCC1020Register(reg_addr));
writeln("");
}
// Displays the configuration menu
void DisplayConfigMenu(void)
{
writeln("RF Modem Configuration Menu\n\r");
writeln("D - Dump CC1020 registers");
writeln("F - Default settings");
writeln("C - Calibrate");
writeln("R - RX mode");
writeln("T - TX mode");
writeln("L - PLL lock");
writeln("M - Manchester format");
writeln("N - NRZ format");
writeln("P - Set PA Power");
writeln("I - Set Preamble length");
writeln("J - Access CC1020 register");
writeln("B - Button configuration");
writeln("X - Exit from configuration menu");
}
// Handles keystrokes for the configuration menu
void HandleConfigMenu(char inputvalue)
{
switch(toupper(inputvalue)) {
case 'D' :
DumpCC1020Regs();
break;
case 'X' :
break;
case 'F' :
DefaultSettings();
break;
case 'C' :
if (CalibrateCC1020(PA_POWER))
writeln("Calibrate OK");
else
writeln("Calibrate failed");
break;
case 'R' :
SetupCC1020RX(RXANALOG, PA_POWER);
OPTION=0xC0; // INT on rising edge
TRISC|=0x02; // Set DIO as input
SET_TXLED(FALSE);
SET_RXLED(TRUE);
break;
case 'T' :
SetTXmode(PA_POWER);
SET_TXLED(TRUE);
SET_RXLED(FALSE);
break;
case 'L' :
if ((ReadFromCC1020Register(CC1020_STATUS)&0x10)==0x10)
writeln("PLL in lock");
else
writeln("PLL out of lock");
break;
case 'M' :
WriteToCC1020Register(CC1020_MODEM, (ReadFromCC1020Register(CC1020_MODEM)&~0x03) | 0x01);
EEPROMCC1020Config[CC1020_MODEM-1] |= 0x01;
if((ReadFromCC1020Register(CC1020_MODEM)&0x03)==0x01){
writeln("Manchester format");
}else{
writeln("NRZ format");
}
break;
case 'N' :
WriteToCC1020Register(CC1020_MODEM, ReadFromCC1020Register(CC1020_MODEM)&~0x03);
EEPROMCC1020Config[CC1020_MODEM-1] &= ~0x03;
if((ReadFromCC1020Register(CC1020_MODEM)&0x03)==0x01){
writeln("Manchester format");
}else{
writeln("NRZ format");
}
break;
case 'P' :
SetPApower();
break;
case 'I' :
SetPreambleLength();
break;
case 'J' :
AccessCC1020Register();
break;
case 'B' :
ButtonConfig();
break;
default:
DisplayConfigMenu();
break;
}
}
// Runs the configuration menu
void ConfigurationMode(void)
{
int i;
DisplayConfigMenu();
while(1){
writestr(">");
i=getchar();
writeln("");
HandleConfigMenu(i);
if(toupper(i)=='X'){
SetupCC1020All();
return;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -