📄 main.c
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2004-09-16
** Last Version: 1.0
** Descriptions: The main() function example template
**
**--------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**--------------------------------------------------------------------------------------------------------
** Modified by: Zhao xuji
** Modified date: 2008-07-08
** Version: v1.01
** Descriptions: DTU Config
**
*********************************************************************************************************/
#include "main.h"
#include "config.h"
#include "UART.h"
/*********************************************************************************************************
** Function name: DelayNS
** Descriptions: 延时函数
** input parameters: uiDly 值越大,延时时间越长
** output parameters: 无
** Returned value: 无
*********************************************************************************************************/
void DelayNS (uint32 uiDly)
{
uint32 i;
for (; uiDly > 0; uiDly--){
for(i = 0; i < 50000; i++);
}
}
/*********************************************************************************************************
** Function name: main
** Descriptions: 主函数
** Input parameters: None
** output parameters: None
** Created Date:
*********************************************************************************************************/
int main (void)
{
char InSetString[] = "+++ in set\r\n";
char OutSetString[] = "AT+OUTSET=ON\r\n";
char SetIP[] = "AT+SVRIP=166.111.8.238\r\n ";
char SetPORT[] = "AT+SVRPORT=23\r\n ";
char AckStr[] = "OK";
PCONP |= 1 << 4; /* 打开UART1 */
PINSEL7 = (PINSEL7 & (~0x0F)) | 0x0F;
U1LCR = 0x80; /* DLAB=1,允许设置波特率 */
U1DLM = ((Fpclk/16)/9600)/256; /* 设置分频值 */
U1DLL = ((Fpclk/16)/9600)%256;
U1LCR = 0x03; /* 令DLAB位为0 */
U1FCR &= ~0x07; /* 禁用FIFO */
U1IER &= ~0x07; /* 禁止UART产生中断 */
UART1SendStr(InSetString); /* 发送进入配置命令 */
if(FALSE == UART1RcvAck(AckStr,2)) /* 判断应答是否正确…… */
while(1); /* ……应答错误,则程序停在此处 */
DelayNS(200);
UART1SendStr(SetIP); /* 发送配置IP地址命令 */
if(FALSE == UART1RcvAck(AckStr,2)) /* 判断应答是否正确…… */
while(1); /* ……应答错误,则程序停在此处 */
DelayNS(200);
UART1SendStr(SetPORT); /* 发送配置端口号命令 */
if(FALSE == UART1RcvAck(AckStr,2)) /* 判断应答是否正确…… */
while(1); /* ……应答错误,则程序停在此处 */
DelayNS(200);
UART1SendStr(OutSetString); /* 发送退出配置命令 */
if(FALSE == UART1RcvAck(AckStr,2)) /* 判断应答是否正确…… */
while(1); /* ……应答错误,则程序停在此处 */
DelayNS(200);
if(FALSE == UART1RcvAck("CONNECT\r\n",9))
while(1); /* 收到错误的连接指示符停在此处 */
BUZZER_Set(); /* BEEP 蜂鸣 表示配置成功 */
DelayNS(15);
BUZZER_Clr();
DelayNS(15);
BUZZER_Set();
DelayNS(15);
BUZZER_Clr();
DelayNS(15);
while(1);
return 0;
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -