有方M590E GSM模塊,用STC12C5A60S2 可以串口通信, 一切正常...用STC15W204S與模塊就不行,模塊與串口助手可以通信,STC15W204S與串口助手也可以通信,波特率都設置成38400,何解?
#include <stc15w204s.h>
#include <stdio.h>
#include <string.h>
void UartInit(void) //38400bps@11.0592MHz
{
SCON = 0x50; //8位數據,可變波特率
AUXR |= 0x01; //串口1選擇定時器2為波特率發生器
AUXR |= 0x04; //定時器2時鐘為Fosc,即1T
T2L = 0xB8; //設定定時初值
T2H = 0xFF; //設定定時初值
AUXR |= 0x10; //啟動定時器2
}
void delay(unsigned int time)
{
unsigned int i;
for(;time>0;time--)
{ i=1500;
while(i--);
}
}
void main(void)
{
UartInit();
TI=1;
printf("ATD1****16235;\n");
delay(15000);
printf("ATH\n");
delay(10000);
printf("ATD>3;\n"); //前面的電話號碼在卡的電話薄第3位
delay(15000);
printf("ATH\n");
while(1);
}
|