|
今天调了语音模块,大家交流下
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define CPU_F ((double)8000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define TEXTLEN 100 //固定文字的长度
#define HEADLEN 5 //数据包头的长度
#define LEN_OFFSET 2 //长度字节的偏移量(本例中长度不超过255字节,因此只使用1字节长度)
#define K0 (P1IN&BIT0)
//数据包头(0xFD + 2字节长度 + 1字节命令字 + 1字节命令参数)
uchar head[HEADLEN] = {0xfd,0x00,0x00,0x01,0x18};//文字(中间有需要变化的内容可在发送前修改)
//uchar text[TEXTLEN] = {"18700946151"};
uchar xor = 0;
void clock_int()
{
WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog Timer
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
//1Mhz
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */
}
void io_int()
{
P1OUT = 0x00;
P1DIR = BIT0;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
}
void uart_int()
{
UCA0CTL1 |= UCSSEL_1; // SMCLK
UCA0BR0 = 3; // 1MHz 19200
UCA0BR1 = 0; // 1MHz 19200
UCA0MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE+ UCA0TXIE; // Enable USCI_A0 RX interrupt
}
void R_S_Byte(char R_Byte)
{
while(!(IFG2 & UCA0TXIFG)); //????????
UCA0TXBUF=R_Byte;
}
void yuyin(uchar* text)
{
uint i;
uchar b[TEXTLEN+1];
xor = 0; //校验码初始化
for(i=0;i=text;
for(i=strlen(text);i=' ';b[TEXTLEN]='\0';
head[LEN_OFFSET] = TEXTLEN + 3; //计算正文长度(1命令字 + 1命令参数 + 文字长度 + 1校验位)
//发送数据包头(0xFD + 2字节长度 + 1字节命令字 + 1字节命令参数)
for(i = 0; i < HEADLEN; i++)
{xor ^= head;R_S_Byte(head);}
//发送文字内容
for(i = 0; i < TEXTLEN; i++)
{xor ^= b;R_S_Byte(b);}
R_S_Byte(xor); //发送校验位
delay_ms(20000);
}
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
clock_int();
io_int();
uart_int();
while(1)
{
// yuyin("[v8][m6][n1][y0]3243254543256");
yuyin("45476879870");
}
}
|
|