ADW1016 DRA818U DRA818V Source Codes For PIC
ADW1016 DRA818U DRA818V Source Codes For PIC
V1.01
This document contains source codes for high power wireless voice
transceiver module DRA818U/DRA818V and is used only for reference. In
order to understand the codes better, users also can refer to the document
ADW1011_configure_DRA818V_DRA818U_through_computer for details.
DRA818U/DRA818V modules use standard UART interface to communicate with the host. The default
data format is: 9600 8 N 1 ( 9.6k bps baud rate, 8-bit data, no parity check and 1 stop bit). Users can send
AT commands to configure the parameters and the modules will give response when they receive correct
AT commands.
AT comannds:
The AT commands are in ASCII format and ended with <CR><LF>.
RAM DEFINE
CMD_HAND[15]={0x41,0x54,0x2B,0x44,0x4D,0x4F,0x43,0x4F,0x4E,0x4E,0x45,0x43,0x54,0x0d,0x0a};
unsigned char
CMD_VOLUME[16]={0x41,0x54,0x2B,0x44,0x4D,0x4F,0x53,0x45,0x54,0x56,0x4f,0x4c,0x55,0x4d,0x45,0x3d};
//=======================================================
void uart_init()
SPBRGH = 0;
SPBRG = 23;
TXSTA = 0;
RCSTA = 0x90;
BAUDCON = 0;
TXIE = 0;
RCIE = 0;
}
//------------------------------------------------
void check_uart()
// send handshake instruction to module regularly to check the connection status of module
unsigned char i;
if(Flag.in_rx == 1)
rx_cnt --;
if(rx_cnt == 0)
Flag.in_rx = 0;
Flag.in_tx = 0;
Flag.cn_fail = 1;
LED_CTCS = LED_OFF;
Flag.poweron = 1;
fresh_display();
return;
if((Flag.in_tx == 1)||(Flag.in_rx == 1)) // No interleave sending instruction, to ensure the module properly receiving
instruction.
return;
send_hand();
}
//------------------------------------------------
void uart_trans_check(void)
stop_TX();
Flag.in_tx = 0;
Flag.in_rx = 1;
rx_cnt = 2;
len_txnow = 0;
len_rxnow = 0;
tx_len = 0;
clr_tx_buf();
start_RX();
//------------------------------------------------
void uart_recv_ack(void)
if(Flag.in_rx == 0)
return;
if(len_rxnow == rx_len)
Flag.in_rx = 0;
status_cnt = 2;
Flag.cn_fail = 0;
LED_CTCS = LED_ON;
fresh_display();
stop_RX();
if((rx_len == 15)&&(Flag.poweron))
Flag.reset = 1;
Flag.poweron = 0;
return;
else if(Flag.cn_fail == 1)
return;
else
status_cnt -= 1;
if(status_cnt == 0)
// If the instruction returns null continuously, set the flag bit of module connection to failed
Flag.cn_fail = 1;
LED_CTCS = LED_OFF;
Flag.poweron = 1;
//------------------------------------------------
void send_hand()
unsigned char i;
for(i=0;i<=14;i++)
tx_buf[i] = CMD_HAND[i];
rx_len = 15;
tx_len = 15;
len_txnow = 0;
Flag.in_tx = 1;
clr_rx_buf();
start_TX();
//------------------------------------------------
void send_set()
unsigned char i;
for(i=0;i<=14;i++)
tx_buf[i] = CMD_SET[i];
tx_buf[15] = ASCII(Flag.gbw);
tx_buf[16] = ASCII_comma;
ASCII_TFV();
tx_buf[25] = ASCII_comma;
ASCII_RFV();
tx_buf[34] = ASCII_comma;
tx_buf[35] = ASCII(Tx_ctcs_3);
tx_buf[36] = ASCII(Tx_ctcs_2);
tx_buf[37] = ASCII(Tx_ctcs_1);
tx_buf[38] = ASCII(Tx_ctcs_0);
tx_buf[37] = ASCII_comma;
tx_buf[38] = ASCII(sq);
tx_buf[39] = ASCII_comma;
tx_buf[40] = ASCII(Rx_ctcs_3);
tx_buf[41] = ASCII(Rx_ctcs_2);
tx_buf[42] = ASCII(Rx_ctcs_1);
tx_buf[43] = ASCII(Rx_ctcs_0);
tx_buf[44] = 0x0d;
tx_buf[45] = 0x0a;
rx_len = 16;
tx_len = 46;
len_txnow = 0;
Flag.in_tx = 1;
clr_rx_buf();
start_TX();
//------------------------------------------------
void send_vol()
unsigned char i;
for(i=0;i<=15;i++)
tx_buf[i] = CMD_VOLUME[i];
tx_buf[16] = ASCII(vol);
tx_buf[17] = 0x0d;
tx_buf[18] = 0x0a;
rx_len = 17;
tx_len = 19;
// write number of bytes to set the volume level to send and receive data
len_txnow = 0;
Flag.in_tx = 1;
clr_rx_buf();
start_TX();
//------------------------------------------------
void clr_tx_buf()
unsigned char i;
for(i=0;i<=39;i++)
tx_buf[i]=0;
//------------------------------------------------
void clr_rx_buf()
unsigned char i;
for(i=0;i<=18;i++)
rx_buf[i] = 0;
//------------------------------------------------
void start_TX()
TXEN = 1;
TXIE = 1;
//------------------------------------------------
void stop_TX()
// close UARTsending
TXEN = 0;
TXIE = 0;
//------------------------------------------------
void start_RX()
CREN = 1;
RCIE = 1;
//------------------------------------------------
void stop_RX()
CREN = 0;
RCIE = 0;
//------------------------------------------------
// interrupt handling
if(TXIF)
if(Flag.in_tx == 0)
stop_TX();
TXREG = tx_buf[len_txnow];
len_txnow ++;
else
TXIE = 0;
// send over
if(RCIF)
NOP();
if(Flag.in_rx)
rx_buf[len_rxnow] = RCREG;
if((len_rxnow++) == (rx_len+1))
stop_RX();
else
stop_RX();
int_temp = RCREG;