哪位大哥能给一段GPRS模块通信的程序示例,我用的是sim900A模块。

哪位大哥能给一段GPRS模块通信的程序示例,我用的是sim900A模块。,第1张

#include stdio.h>

#include stdlib.h>

#include string.h>

#include unistd.h>

#include fcntl.h>

#include errno.h>

#include termios.h>

int open_port(void)

{

int fd

fd = open("/dev/s3c2410_serial1", O_RDWR|O_NOCTTY|O_NDELAY)

if(fd == -1)

printf("Unable to open uart1\n")

else

fcntl(fd, F_SETFL, 0)

return fd

}

int setup_uart(int fd)

{

struct termios oldtio, newtio

if((tcgetattr(fd, &oldtio)) != 0)

{

printf("Save old error!\n")

return -1

}

bzero(&newtio, sizeof(newtio))

newtio.c_cflag |= (CLOCAL | CREAD)

newtio.c_cflag &= ~CSIZE

newtio.c_cflag &= ~CSTOPB// 1 stop bit

newtio.c_cflag &= ~PARENB// No parity

newtio.c_cflag |= CS8// 8 bits data

cfsetispeed(&newtio, B9600)

cfsetospeed(&newtio, B9600)

//newtio.c_lflag |= (ICANON | ECHO)

//newtio.c_lflag &= ~ECHOE

//newtio.c_iflag &= ~(IXON | IXOFF | IXANY)

newtio.c_cc[VTIME] = 0

newtio.c_cc[VMIN] = 0

tcflush(fd, TCIFLUSH)

if((tcsetattr(fd, TCSANOW, &newtio)) != 0)

{

printf("Set new error!\n")

return -1

}

}

int main(void)

{

int i

int fd

char c,str[200]

fd = open_port()

if(fd == -1)

return 0

i = setup_uart(fd)

if(i == -1)

return 0

while(1)

{

for(i=0i200i++)

str = '\0'

i = 0

printf("GPRS-CMD #")

while((c=getchar()) != 10)

{

str = c

i++

}

str = 13

str[i+1] = '\0'

i = write(fd, str, strlen(str))

if(i 0)

printf("write error!")

for(i=0i100i++)

usleep(100)

i = read(fd, str, 200)

printf("%s\n", str)

}

}

另一篇和主题相似的已发送往您的邮箱,请查收.

代码如下 流程是一致的 只是端口定义不同

#include "sim900a.h"

#include "usart.h"

#include "delay.h"

#include "led.h"

#include "key.h"

#include "lcd.h"

#include "dma.h"

#include "flash.h"

#include "touch.h"

#include "malloc.h"

#include "string.h"

#include "text.h"

#include "usart2.h"

#include "ff.h"

//将收到的AT指令应答数据返回给电脑串口

//mode:0,不清零USART2_RX_STA

// 1,清零USART2_RX_STA

void sim_at_response(u8 mode)

{

if(USART2_RX_STA&0X8000) //接收到一次数据了

{

USART2_RX_BUF[USART2_RX_STA&0X7FFF]=0//添加结束符

printf("%s",USART2_RX_BUF) //发送到串口

if(mode)USART2_RX_STA=0

}

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

//ATK-SIM900A 各项测试(拨号测试、短信测试、GPRS测试)共用代码

//sim900a发送命令后,检测接收到的应答

//str:期待的应答结果

//返回值:0,没有得到期待的应答结果

//其他,期待应答结果的位置(str的位置)

u8* sim900a_check_cmd(u8 *str)

{

char *strx=0

if(USART2_RX_STA&0X8000) //接收到一次数据了

{

USART2_RX_BUF[USART2_RX_STA&0X7FFF]=0//添加结束符

strx=strstr((const char*)USART2_RX_BUF,(const char*)str)

}

return (u8*)strx

}

//向sim900a发送命令

//cmd:发送的命令字符串(不需要添加回车了),当cmd<0XFF的时候,发送数字(比如发送0X1A),大于的时候发送字符串.

//ack:期待的应答结果,如果为空,则表示不需要等待应答

//waittime:等待时间(单位:10ms)

//返回值:0,发送成功(得到了期待的应答结果)

// 1,发送失败

u8 sim900a_send_cmd(u8 *cmd,u8 *ack,u16 waittime)

{

u8 res=0

USART2_RX_STA=0

if((u32)cmd<=0XFF)

{

while(DMA1_Channel7->CNDTR!=0) //等待通道7传输完成

USART2->DR=(u32)cmd

}else u2_printf("%s\r\n",cmd)//发送命令

if(ack&&waittime) //需要等待应答

{

while(--waittime) //等待倒计时

{

delay_ms(10)

if(USART2_RX_STA&0X8000)//接收到期待的应答结果

{

if(sim900a_check_cmd(ack))break//得到有效数据

USART2_RX_STA=0

}

}

if(waittime==0)res=1

}

return res

}

//将1个字符转换为16进制数字

//chr:字符,0~9/A~F/a~F

//返回值:chr对应的16进制数值

u8 sim900a_chr2hex(u8 chr)

{

if(chr>='0'&&chr<='9')return chr-'0'

if(chr>='A'&&chr<='F')return (chr-'A'+10)

if(chr>='a'&&chr<='f')return (chr-'a'+10)

return 0

}

//将1个16进制数字转换为字符

//hex:16进制数字,0~15

//返回值:字符

u8 sim900a_hex2chr(u8 hex)

{

if(hex<=9)return hex+'0'

if(hex>=10&&hex<=15)return (hex-10+'A')

return '0'

}

//unicode gbk 转换函数

//src:输入字符串

//dst:输出(uni2gbk时为gbk内码,gbk2uni时,为unicode字符串)

//mode:0,unicode到gbk转换

// 1,gbk到unicode转换

void sim900a_unigbk_exchange(u8 *src,u8 *dst,u8 mode)

{

u16 temp

u8 buf[2]

if(mode)//gbk 2 unicode

{

while(*src!=0)

{

if(*src<0X81) //非汉字

{

temp=(u16)ff_convert((WCHAR)*src,1)

src++

}else //汉字,占2个字节

{

buf[1]=*src++

buf[0]=*src++

temp=(u16)ff_convert((WCHAR)*(u16*)buf,1)

}

*dst++=sim900a_hex2chr((temp>>12)&0X0F)

*dst++=sim900a_hex2chr((temp>>8)&0X0F)

*dst++=sim900a_hex2chr((temp>>4)&0X0F)

*dst++=sim900a_hex2chr(temp&0X0F)

}

}else //unicode 2 gbk

{

while(*src!=0)

{

buf[1]=sim900a_chr2hex(*src++)*16

buf[1]+=sim900a_chr2hex(*src++)

buf[0]=sim900a_chr2hex(*src++)*16

buf[0]+=sim900a_chr2hex(*src++)

temp=(u16)ff_convert((WCHAR)*(u16*)buf,0)

if(temp<0X80){*dst=tempdst++}

else {*(u16*)dst=swap16(temp)dst+=2}

}

}

*dst=0//添加结束符

}

//键盘码表

const u8* kbd_tbl1[13]={"1","2","3","4","5","6","7","8","9","*","0","#","DEL"}

const u8* kbd_tbl2[13]={"1","2","3","4","5","6","7","8","9",".","0","#","DEL"}

u8** kbd_tbl

u8* kbd_fn_tbl[2]

//加载键盘界面(尺寸为240*140)

//x,y:界面起始坐标(320*240分辨率的时候,x必须为0)

void sim900a_load_keyboard(u16 x,u16 y,u8 **kbtbl)

{

u16 i

POINT_COLOR=RED

kbd_tbl=kbtbl

LCD_Fill(x,y,x+240,y+140,WHITE)

LCD_DrawRectangle(x,y,x+240,y+140)

LCD_DrawRectangle(x+80,y,x+160,y+140)

LCD_DrawRectangle(x,y+28,x+240,y+56)

LCD_DrawRectangle(x,y+84,x+240,y+112)

POINT_COLOR=BLUE

for(i=0i<15i++)

{

if(i<13)Show_Str_Mid(x+(i%3)*80,y+6+28*(i/3),(u8*)kbd_tbl[i],16,80)

else Show_Str_Mid(x+(i%3)*80,y+6+28*(i/3),kbd_fn_tbl[i-13],16,80)

}

}

苹果手机查看sim卡应用程序的方法如下:

准备材料:苹果6手机

1、在iPhone屏幕上找到设置图标。

2、 然后打开设置界面。

3、随后在界面中选择点击蜂窝数据网络选项。

4、打开蜂窝数据网络界面中点击sim卡应用程序选项。

5、打开sim卡应用程序界面中点击usim卡信息选项。

6、d出选项界面中点击电话号码与短信存储容量选项。

7、此时显示电话号码与短信存储容量还剩多少。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11557358.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存