新手上路
- 积分
- 31
- 金钱
- 31
- 注册时间
- 2019-10-23
- 在线时间
- 10 小时
|
6金钱
本帖最后由 一抹 于 2017-3-27 15:31 编辑
大家好,我使用的是PIC单片机,在使用电脑调试时能想服务器发送数据。下面的是我的AT指令定义和程序
//^^^^^^^^^^^AT指令定义^^^^^^^^^^^^^^//
unsigned char ydnet[]="AT+CSTT=\"CMNET\"\r\n";
unsigned char activate[]="AT+CIICR\r\n";
unsigned char obtainIP[]="AT+CIFSR\r\n";
unsigned char localcom[]="AT+CLPORT=\"TCP\",8080\r\n";
unsigned char connect_sever[]="AT+CIPSTART=\"TCP\",\"167546f76u.iask.in\",24569\r\n";
unsigned char senddata[]="AT+CIPSEND\r\n";
麻烦大家指导,
/*********************************************************************************************/
#include <p18f4520.h> //包含PIC头文件
#define uint unsigned int
#define uchar unsigned char
unsigned char sign=0;
unsigned char counter=0;
unsigned char Re_buf[2];
//^^^^^^^^^^^AT指令定义^^^^^^^^^^^^^^//
unsigned char ydnet[]="AT+CSTT=\"CMNET\"\r\n";
unsigned char activate[]="AT+CIICR\r\n";
unsigned char obtainIP[]="AT+CIFSR\r\n";
unsigned char localcom[]="AT+CLPORT=\"TCP\",8080\r\n";
unsigned char connect_sever[]="AT+CIPSTART=\"TCP\",\"************\",24569\r\n";
unsigned char senddata[]="AT+CIPSEND\r\n";
//^^^^^^^^^^^延时函数^^^^^^^^^^^^^^//
void delayms(unsigned int t);
void UartData(unsigned char dat);
void USART_SendStr(unsigned char *ptr,unsigned char length);
//void sim808_connect_sever(void);
void sim808_connect_sever_init(void);
//^^^^^^^^^^^延时函数^^^^^^^^^^^^^^//
void delayms(unsigned int t)
{
unsigned int x,y;
for(x=t;x>0;x--)
{
for(y=100;y>0;y--)
{
}
}
}
//^^^^^^^^^^^字节发送函数0^^^^^^^^^^^^^^^//
void UartData(unsigned char dat)
{
TXREG=dat;
while(TXSTAbits.TRMT==0);
}
//^^^^^^^^^^^字符串发送函数1^^^^^^^^^^^^^^^^^^//
void USART_SendString(unsigned char *p)
{
while(*p)
{
UartData(*p);
p++;
}
}
//^^^^^^^^^^^字符串发送函数2^^^^^^^^^^^^^^^^^^//
void USART_SendStr(unsigned char *ptr,unsigned char length)
{
int i=0;
while(i<length)
{
UartData(*(ptr+i));
i++;
}
}
void interrupt_isr(void)
{
if(PIR1bits.RCIF==1)
{
PIR1bits.RCIF=0;
Re_buf[counter]=RCREG;
counter++;
if(counter==2)
{
counter=0;
sign=1;
}
}
}
void sim808_connect_sever_init(void)
{
//delayms(1000);delayms(1000);delayms(1000);delayms(1000);delayms(1000);
//delayms(1000);delayms(1000);delayms(1000);delayms(1000);delayms(1000);
delayms(1000);delayms(1000);delayms(1000);delayms(1000);delayms(1000);
USART_SendString(ydnet);
delayms(5000);
USART_SendString(activate);
delayms(5000);
USART_SendString(obtainIP);
delayms(5000);
USART_SendString(localcom);
delayms(10000);
USART_SendString(connect_sever);
delayms(25000);
}
void main()
{
TRISCbits.TRISC6=1;
TRISCbits.TRISC7=1; //设置C口方向全为输出
SPBRG=25; //设置波特率为9600BPS
TXSTA=0X24; //使能串口发送,选择高速波特率
RCSTA=0X90; //使能串口工作,连续接收
PIE1bits.RCIE=0X1; //使能接收中断
INTCON=0XC0;
delayms(1000);
sim808_connect_sever_init();
while(1)
{
USART_SendString(senddata);
delayms(1000);
UartData(0X34);
delayms(200);
UartData('\r');
UartData('\n');
}
}
|
|