📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.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:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
#define BENQ 1<<31 //P0.31控制模块启动
#define UART_BPS 9600 //波特率
void UART0_Init (void)
{
uint16 Fdiv;
U0LCR = 0x83; // DLAB=1,允许设置波特率
Fdiv = (Fpclk / 16) / UART_BPS; // 设置波特率
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03;
}
uint8 UART0_GetByte (void) //从串口接收1字节数据
{
uint8 rcv_dat;
uint8 p;
if((U0LSR & 0x01) == 0)
p=1;
else
p=0;
switch(p){
case 0:
rcv_dat =U0RBR;
return (rcv_dat);
break;
case 1:
break;
}
}
void UART0_GetStr (uint8 *s, uint32 m) //从串口接收字符串
{
for ( ; m>0; m--)
{
*s++ = UART0_GetByte();
}
}
uint32 getGS(void)
{ int32 i;
int32 j=0;
uint8 sen[24];
UART0_GetStr(sen,24);
for(i=0;i<24;i++)
{ if((sen[i]=='S')||(sen[i]=='>'))
j=1;}
return j;
}
uint32 getOK(void)
{ int32 i;
int32 j=0;
uint8 sen[24];
UART0_GetStr(sen,24);
for(i=0;i<24;i++)
{ if((sen[i]=='O')||(sen[i]=='k'))
j=1;}
return j;
}
void UART0_SendByte (uint8 dat) //发字符
{
U0THR = dat;
while ((U0LSR & 0x40) == 0); // 等待数据发送完毕
}
void UART0_SendStr (uint8 const *str) //发字符串
{
while (1)
{
if (*str == '\0') break; // 遇到结束符,退出
UART0_SendByte(*str++); // 发送数据
}
}
void timerset(int32 n)
{
T0TC =0; // 定时器0初始化
T0PR =0;
T0MCR =0x05;
T0MR0 =n*Fpclk; //延时n秒
T0TCR =0x01;
while((T0IR&0x01)==0);
T0IR=0x01;
}
int main (void)
{ int32 next=1;
int32 get4=1;
uint8 a[5]={"AT\r\n"};
uint8 b[12]={"AT+CMGF=1\r\n"};
uint8 c[10]={"AT+CMGS="};
uint8 d[13]={"13631391431"};
PINSEL0 = 0x00000005; // 设置I/O连接到UART0
PINSEL1 = 0x00000000; // 设置p0.31为I/O口
IO0DIR =BENQ;
UART0_Init(); // 串口初始化
IO0CLR =BENQ; //P0.31控制BENQ的启动
timerset(20); //延时20秒
IO0SET =BENQ;
while(next)
{
timerset(4); //延时4秒
UART0_SendStr(a); // 向串口发送字符串
if(getOK()) next=0;
else {
if((get4>0)&(get4<4))
{next=1; get4++;}
else next=0; }
}
next=1;
get4=1;
while(next)
{
timerset(4); //延时4秒
UART0_SendStr(b); // 向串口发送字符串
if( getOK()) next=0;
else {
if((get4>0)&(get4<4))
{next=1; get4++;}
else next=0; }
}
next=1;
get4=1;
while(next)
{
timerset(4); //延时4秒
UART0_SendStr(c); // 向串口发送字符串
UART0_SendByte('"'); // 向串口发送字符
UART0_SendStr(d);
UART0_SendByte('"');
UART0_SendByte('\r\n');
if(getGS()) next=0;
else {
if((get4>0)&(get4<4))
{next=1; get4++;}
else next=0; }
}
next=1;
get4=1;
while(next)
{
timerset(4); //延时4秒
UART0_SendByte(0x1A); //向串口发送字符串
UART0_SendByte('\n');
if(getOK()) next=0;
else {
if((get4>0)&(get4<8))
{next=1; get4++;}
else next=0; }
}
while(1);
return 0;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -