|
4G模塊連接sct89c52RC(最小系統(tǒng)版)中斷程序沒有反應(yīng),但是發(fā)送數(shù)據(jù)是正常的
1.4G模塊直連usb-ttl模塊是正常的
2.usb-ttl連接單片機(jī)也是正常的
3.4G模塊txd插到usb-ttl,rxd查到單片機(jī)也是正常的
就只是單片機(jī)直連4G模塊有問題
- #include <REGX52.H>
- #include <stdio.h>
- //定義類型
- typedef unsigned int u16;
- typedef unsigned char u8;
- //宏定義波特率發(fā)生器的載入值 9600
- #define RELOAD_COUNT 0xFA
- //#define RELOAD_COUNT 0xF3
- sbit LED6 = P2^6; //led7位置燈
- static u8 i=0;
- u8 Buffer[10];
- u8 isserver = 1;
- u8 ISSUCCESS = 0; //是否連接成功
- //睡眠
- void delay_10us(u16 ten_us)
- {
- while(ten_us--);
- }
- void delay(u16 len,u16 s){
- while(len--){
- delay_10us(s);
- }
- }
- //串口發(fā)送數(shù)據(jù)
- void UART_SendData(u8 dat)
- {
- ES=0; //關(guān)閉串口中斷
- TI=0; //清發(fā)送完畢中斷請求標(biāo)志位
- SBUF=dat; //發(fā)送
- while(TI==0); //等待發(fā)送完畢
- TI=0; //清發(fā)送完畢中斷請求標(biāo)志位
- ES=1; //允許串口中斷
- }
- //發(fā)送指令
- void SendCmd(u8 *pbuf)
- {
- while(*pbuf!='\0') //遇到空格跳出循環(huán)
- {
- UART_SendData(*pbuf);
- delay_10us(5);
- pbuf++;
- }
- delay_10us(5);
- UART_SendData('\r');//回車
- delay_10us(5);
- UART_SendData('\n');//換行
- delay_10us(2000);
- }
- //發(fā)送消息到服務(wù)端,只是多加了發(fā)送數(shù)據(jù)的指令
- void SendData(u8 *pbuf)
- {
- SendCmd("AT+MIPSEND=1,10");
- while(*pbuf!='\0') //遇到空格跳出循環(huán)
- {
- UART_SendData(*pbuf);
- delay_10us(5);
- pbuf++;
- }
- delay_10us(5);
- UART_SendData('\r');//回車
- delay_10us(5);
- UART_SendData('\n');//換行
- // delay_ms(10);
- }
- //串口設(shè)置
- void UART_Init(void)
- {
- SCON|=0X50; //設(shè)置為工作方式1
- TMOD|=0X20; //設(shè)置計(jì)數(shù)器工作方式2
- PCON=0X80; //波特率加倍
- TH1=RELOAD_COUNT; //計(jì)數(shù)器初始值設(shè)置
- TL1=TH1;
- ES=0; //關(guān)閉接收中斷
- EA=1; //打開總中斷
- TR1=1; //打開計(jì)數(shù)器
- ET1=0;
- // TI=1; //發(fā)送中斷標(biāo)記位,如果使用printf函數(shù)的必須設(shè)置
- }
- void main(){
- LED6=0;
- UART_Init();
-
- while(1){
- if(isserver){
- delay(5,50000);
- SendCmd("AT+CGDCONT=1,\"IP\",\"CMIOT\"");
- delay(5,50000);
- SendCmd("AT+CGACT=1,1");
- delay(5,50000);
- SendCmd("AT+MIPOPEN=1,\"TCP\",\"106.13.207.79\",11112");
- delay(5,50000);
- SendCmd("{id:A0002}");
- }
-
- }
-
- }
- //中斷程序
- void UartIsr(void) interrupt 4
- {
- if (RI == 1) //當(dāng)硬件接收到一個(gè)數(shù)據(jù)時(shí),RI會置位
- {
- SendCmd("接收消息\n");
- LED6 = 1;
- RI = 0;
- }
- }
復(fù)制代碼
|
|