?? uart_phs_token.c
字號:
/**********************************************************/
/* send short message by PHS Module */
/* Author: li tingtao, liu bo */
/*********2008-3.13****************************************/
#include<reg52.h>
#include<intrins.h>
#include<stdio.h>
#include<string.h>
sfr ISP_CONTR= 0xE7;
sfr CCON = 0xD8;
sfr CMOD = 0xD9;
sfr CL = 0xE9;
sfr CH = 0xF9;
sfr CCAPOL = 0xEA;
sfr CCAPOH = 0xFA;
sfr CCAPM0 = 0xDA;
sfr CCAPM1 = 0xDB;
sbit CR = 0xDE;
sbit MCU_Start_Led = P1^1; //P1^7;
#define Self_Define_ISP_Download_Command 0x22
#define RELOAD_COUNT 0xfd
char cmd[]="ATWITS+CMGS=\"";
char str1[]="\",\"";
char str2[]="\"\r";
void serial_port_initial();
void send_UART(unsigned char);
void UART_Interrupt_Receive(void);
void soft_reset_to_ISP_Monitor(void);
void delay(void);
void display_MCU_Start_Led(void);
void send_at_cmd(char *cmd);
int send_message(char *msg,char *number);
void main(void)
{
serial_port_initial(); /*init the serial port*/
send_message("hello","13916808083"); /* send "hello" messages to mobile phone(number:139xxx)*/
while(1);
}
int send_message(char *msg,char *number)
/*parameter:msg:the message will be sent*/
/*parameter:number:the destination mobile phone*/
{
char at_cmd[64]="";
strcat(at_cmd,cmd);
strcat(at_cmd,number);
strcat(at_cmd,str1);
strcat(at_cmd,msg);
strcat(at_cmd,str2);
send_at_cmd(at_cmd);
delay();
return 0;
}
void serial_port_initial()
/*init the serial port*/
{
SCON=0x50;
TMOD=0x21;
TH1=RELOAD_COUNT;
TL1=RELOAD_COUNT;
TR1=1;
ES=1;
EA=1;
}
void send_UART(unsigned char i)
/*send the char i to UART*/
{
ES=0;
TI=0;
SBUF=i;
while(TI==0);
TI=0;
ES=1;
}
void send_at_cmd(char *cmd)
/*send the AT CMD to UART*/
{
char *temp=cmd;
while(*temp)
{
send_UART(*temp);
temp++;
}
}
void UART_Interrupt_Receive(void) interrupt 4
/*interrupt routine*/
{
unsigned char k=0;
if(RI==1)
{
RI=0;
k=SBUF;
if(k==Self_Define_ISP_Download_Command)
{delay();
delay();
soft_reset_to_ISP_Monitor();
}
send_UART(k);
}
else
{
TI=0;
}
}
void soft_reset_to_ISP_Monitor(void)
{
ISP_CONTR=0x60;
}
void delay(void)
{
unsigned int j=0;
unsigned int g=0;
for(j=0;j<5;j++)
{
for(g=0;g<10000;g++)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
void display_MCU_Start_Led(void)
{
unsigned char i = 0;
for(i=0;i<5;i++)
{
MCU_Start_Led=0;
delay();
MCU_Start_Led=1;
delay();
MCU_Start_Led=0;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -