#include "mbed.h"
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------
Serial pc1(SERIAL_TX, SERIAL_RX);
Serial pc2(PA_9, PA_10);
void Rx_interrupt();
// Circular buffers for serial TX and RX data - used by interrupt routines
int buffer_size = 150;
// might need to increase buffer size for high baud rates
char tx_buffer[70];
char rx1_buffer[150];
char rx2_buffer[150];
// Circular buffer pointers
// volatile makes read-modify-write atomic
volatile int tx_in=0;
volatile int tx_out=0;
volatile int rx1_in=0;
volatile int rx2_in=0;
volatile int rx_out=0;
// Line buffers for sprintf and sscanf
char tx_line[80];
char rx_line[80];
char message[20];
char mode[15] = "AT+CMGF=1\r";
char phone[30] = "AT+CMGS=\"1252013637735859\"\r";
char sms[30] = "Hello my dream!\x01a";
char read[15] ="AT+CMGR=";//AT+CMGL="REC UNREAD"
char flag = 0;
int temp = 14;
DigitalOut myled(LED1);
DigitalIn mybutton(PC_13);
DigitalIn ghg(PB_3);
int main()
{
int i,num,length;
myled =1;
pc1.attach(&Rx_interrupt, Serial::RxIrq);
pc2.attach(&Rx_interrupt, Serial::RxIrq);
while(1)
{
//pc1.printf("I love moonkk");
if(mybutton == 0)
{
pc1.printf ("button low");
wait(1);
}
if(ghg==1)
{
pc1.printf("%s",mode);
pc2.printf("%s",mode);
wait(1);
pc1.printf("%s",phone);
pc2.printf("%s",phone);
wait(1);
pc1.printf("set:%d",temp);
pc1.printf("%s",sms);
pc2.printf("set:%d",temp);
pc2.printf("%s",sms);
wait(2);
}
if(flag == 2)
{
wait(0.5);
flag = 0;
length = strlen(rx2_buffer);
//pc1.printf("%c",rx2_buffer[5]);
//pc1.printf("%c",rx2_buffer[6]);
if(rx2_buffer[5]=='T'&&rx2_buffer[6]=='I')
{
if(rx2_buffer[15]>='0'&&rx2_buffer[15]<='9')
{
num = (int)(rx2_buffer[14] - 0x30)*10+(int)(rx2_buffer[15] - 0x30);
}
else
{
num = (int)(rx2_buffer[14] - 0x30);
}
pc1.printf("AT+CMGR=%d\r",num);
pc2.printf("AT+CMGR=%d\r",num);
}
if(rx2_buffer[5]=='G'&&rx2_buffer[6]=='R')
{
int j = 0;
int q =0;
pc1.printf(rx2_buffer);
for(j=0;j<length;j++)
{
if(rx2_buffer[j]=='#')
{
break;
}
}
if(j<length)
{
//j++;
while(rx2_buffer[j]!='\0')
{
message[q++]=rx2_buffer[j++];
}
message[q]='\0';
pc1.printf("\nmeaas:%s\n",message);
}
if(message[0]=='#'&&message[1]=='o'&&message[2]=='n')
{
pc1.printf("%s",mode);
pc2.printf("%s",mode);
wait(1);
pc1.printf("%s",phone);
pc2.printf("%s",phone);
wait(1);
pc1.printf("set:%d",temp);
pc1.printf("%s",sms);
pc2.printf("set:%d",temp);
pc2.printf("%s",sms);
wait(2);
}
else if(message[0]=='#'&&message[1]=='o'&&message[2]=='f')
{
pc1.printf("%s",mode);
pc2.printf("%s",mode);
wait(1);
pc1.printf("%s",phone);
pc2.printf("%s",phone);
wait(1);
pc1.printf("off:%d",temp);
pc1.printf("%s",sms);
pc2.printf("off:%d",temp);
pc2.printf("%s",sms);
wait(2);
}
else
{
pc1.printf("%s",mode);
pc2.printf("%s",mode);
wait(1);
pc1.printf("%s",phone);
pc2.printf("%s",phone);
wait(1);
pc1.printf("other:%d",temp);
pc1.printf("%s",sms);
pc2.printf("other:%d",temp);
pc2.printf("%s",sms);
wait(2);
}
}
for(i=0;i<length+2;i++)
{
rx2_buffer[i]='\0';
}
rx2_in = 0;
}
if(flag==1)
{
wait(1);
flag = 0;
length = strlen(rx1_buffer);
if(rx1_buffer[0]=='d'&&rx1_buffer[1]=='e'&&rx1_buffer[2]=='l')
{
int i;
for(i=0;i<=num;i++)
{
pc1.printf("AT+CMGD=%d\r",i);
pc2.printf("AT+CMGD=%d\r",i);
wait(1);
}
}
pc1.printf("length:%d",length);
num++;
pc1.printf("AT+CMGR=%d\r",num);
pc2.printf("AT+CMGR=%d\r",num);
for(i=0;i<length+2;i++)
{
rx1_buffer[i]='\0';
}
rx1_in = 0;
}
}
}
void Rx_interrupt()
{
while (pc1.readable())
{
flag = 1;
rx1_buffer[rx1_in] = pc1.getc();
rx1_in = (rx1_in + 1) % buffer_size;
}
while (pc2.readable())
{
flag = 2;
rx2_buffer[rx2_in] = pc2.getc();
rx2_in = (rx2_in + 1) % buffer_size;
}
// rx_buffer[rx_in]='\0';
}
没有合适的资源?快使用搜索试试~ 我知道了~
Keil5-send-message.rar_Keil5-send-message_keil5 _keil5 stm32_stm
共229个文件
h:139个
o:63个
bak:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 168 浏览量
2022-09-23
16:54:15
上传
评论
收藏 1.02MB RAR 举报
温馨提示
Keil5 for stm32 的发短信工程,比较简单实用 可以用作智能控制方面的应用
资源推荐
资源详情
资源评论
收起资源包目录
Keil5-send-message.rar_Keil5-send-message_keil5 _keil5 stm32_stm (229个子文件)
mbed.ar 412KB
printf.axf 344KB
printf.uvgui_longqi.bak 70KB
printf_uvproj.bak 22KB
printf_uvopt.bak 8KB
printf_NUCLEO_F401RE.bin 17KB
main.cpp 5KB
main.crf 446KB
main.d 7KB
printf_mbed NUCLEO_F401RE.dep 7KB
dirstate 90B
stm32f401xe.h 336KB
stm32f4xx_hal_eth.h 111KB
core_cm4.h 105KB
core_cm3.h 96KB
stm32f4xx_hal_tim.h 65KB
stm32f4xx_hal_rcc.h 59KB
stm32f4xx_ll_fmc.h 55KB
stm32f4xx_hal_rcc_ex.h 46KB
stm32f4xx_hal_sd.h 42KB
stm32f4xx_ll_fsmc.h 42KB
stm32f4xx_ll_sdmmc.h 41KB
stm32f4xx_hal_flash_ex.h 40KB
core_cm0plus.h 39KB
stm32f4xx_hal_can.h 36KB
stm32f4xx_hal_gpio_ex.h 35KB
stm32f4xx_hal_dma.h 34KB
stm32f4xx_hal_sai.h 33KB
stm32f4xx_hal_rtc.h 32KB
stm32f4xx_hal_rtc_ex.h 32KB
core_cm0.h 32KB
stm32f4xx_hal_adc.h 31KB
stm32f4xx_hal_ltdc.h 25KB
stm32f4xx_hal_uart.h 24KB
stm32f4xx_hal_dma2d.h 22KB
stm32f4xx_hal_i2c.h 22KB
core_cm4_simd.h 22KB
stm32f4xx_hal_smartcard.h 21KB
stm32f4xx_hal_usart.h 21KB
stm32f4xx_hal_dcmi.h 20KB
stm32f4xx_hal_cryp.h 20KB
stm32f4xx_hal_spi.h 19KB
core_cmInstr.h 19KB
stm32f4xx_ll_usb.h 19KB
stm32f4xx_hal_irda.h 18KB
stm32f4xx_hal_adc_ex.h 18KB
stm32f4xx_hal_i2s.h 17KB
core_cmFunc.h 16KB
stm32f4xx_hal_tim_ex.h 15KB
stm32f4xx_hal_conf.h 15KB
stm32f4xx_hal_hash.h 14KB
stm32f4xx_hal_dac.h 13KB
stm32f4xx_hal_flash.h 13KB
stm32f4xx_hal_pwr.h 13KB
stm32f4xx_hal_gpio.h 12KB
stm32f4xx_hal_pcd.h 12KB
stm32f4xx_hal_dac_ex.h 11KB
stm32f4xx_hal.h 10KB
stm32f4xx_hal_nand.h 10KB
stm32f4xx_hal_nor.h 9KB
stm32f4xx_hal_hcd.h 9KB
stm32f4xx_hal_iwdg.h 9KB
stm32f4xx_hal_pccard.h 8KB
stm32f4xx_hal_wwdg.h 8KB
stm32f4xx.h 8KB
stm32f4xx_hal_rng.h 7KB
stm32f4xx_hal_sdram.h 7KB
stm32f4xx_hal_sram.h 7KB
stm32f4xx_hal_cortex.h 7KB
CAN.h 7KB
stm32f4xx_hal_pwr_ex.h 7KB
stm32f4xx_hal_cryp_ex.h 6KB
stm32f4xx_hal_def.h 6KB
stm32f4xx_hal_hash_ex.h 5KB
PinNames.h 5KB
stm32f4xx_hal_crc.h 5KB
CallChain.h 5KB
Ethernet.h 5KB
InterruptManager.h 4KB
PwmOut.h 4KB
I2CSlave.h 4KB
stm32f4xx_hal_i2c_ex.h 4KB
SerialBase.h 4KB
mbed_interface.h 4KB
stm32f4xx_hal_dma_ex.h 4KB
InterruptIn.h 4KB
I2C.h 4KB
stm32f4xx_hal_i2s_ex.h 4KB
system_stm32f4xx.h 4KB
FileHandle.h 3KB
Ticker.h 3KB
SPISlave.h 3KB
AnalogOut.h 3KB
FileSystemLike.h 3KB
LocalFileSystem.h 3KB
FunctionPointer.h 3KB
objects.h 3KB
DigitalInOut.h 3KB
DirHandle.h 3KB
PeripheralNames.h 3KB
共 229 条
- 1
- 2
- 3
资源评论
Kinonoyomeo
- 粉丝: 76
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功