Joke Collection Website - Blessing messages - Sim900a Chinese SMS
Sim900a Chinese SMS
The process is consistent.
Only the port definition is different.
# Including
“sim900a.h“
# Including
“usart.h“
# Including
“delay.h“
# Including
“led.h“
# Including
“key.h“
# Including
“lcd.h“
# Including
“dma.h“
# Including
“flash.h“
# Including
“touch.h“
# Including
“malloc.h“
# Including
“string.h“
# Including
"text. h“
# Including
“usart2.h“
# Including
“ff.h“
//Return the received AT command response data to the computer serial port.
//mode:0, USART2_RX_STA is not cleared;
//
1, clear USART2 _ RX _ STA.
empty
sim _ at _ response(u8
Mode)
{
if(usart 2 _ RX _ STA & amp; 0X8000)
//Receive data once.
{
usart 2 _ RX _ BUF【usart 2 _ RX _ STA & amp; 0x 7 fff】= 0; //Add terminator
printf(“% s“,usart 2 _ RX _ BUF);
//Send to serial port
If (mode) usart2 _ rx _ sta = 0;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//ATK-SIM900A
All tests (dial-up test, SMS test and GPRS test) share the same code.
//After sending the command, SIM 900a detects the received reply.
//str: Expected response result
//Return value: 0, and the expected response result was not obtained.
//
Other, location of expected response result (location of str)
u8*
sim 900 a _ check _ cmd(u8
*str)
{
tea
* strx = 0;
if(usart 2 _ RX _ STA & amp; 0X8000)
//Receive data once.
{
usart 2 _ RX _ BUF【usart 2 _ RX _ STA & amp; 0x 7 fff】= 0; //Add terminator
strx = str str((const
char *)usart 2 _ RX _ BUF,(const
char *)str);
}
return
(u8 *)strx;
}
//send a command to the sim900a.
//cmd: Send command string (no carriage return required), when cmd
//ack: expected response result. If it is empty, it means that there is no need to wait for a response.
//waittime: waiting time (unit: 10ms)
//Return value: 0, sending succeeded (get the expected response result).
//
1, sending failed.
u8
sim 900 a _ send _ cmd(u8
*cmd,u8
* confirmed, u 16
Waiting time)
{
u8
RES = 0;
usart 2 _ RX _ STA = 0;
if((u32)cmd & lt; =0XFF)
{
while(DMA 1 _ channel 7-》; CNDTR! =0);
//Wait for the transmission of channel 7 to be completed.
usart 2-& gt; DR =(u32)cmd;
} Otherwise,
U2 _ printf(“% s \ r \ n“,cmd); //Send command
if(ack & amp; & waiting time)
//Need to wait for an answer
{
When (-waiting time)
//Wait for the countdown
{
delay _ ms( 10);
if(usart 2 _ RX _ STA & amp; 0x 8000)// Received the expected response result.
{
If(sim 900 a _ check _ cmd(ack)) interrupt; //Get valid data
usart 2 _ RX _ STA = 0;
}
}
if(wait time = = 0)RES = 1;
}
return
res
}
//Convert 1 characters into 16 hexadecimal digits.
//chr: character,0 ~ 9/a ~ f/a ~ f
//Return value: 16 hexadecimal value corresponding to chr.
u8
sim 900 a _ chr 2 hex(u8
chr)
{
if(chr & gt; =' 0' and amp&chr < =' 9') are returned.
chr-“0”;
if(chr & gt; =‘A‘amp; & chr< =' f') returns
(chr-‘A‘+ 10);
if(chr & gt; =‘a‘amp; & chr< =' f') returns
(chr-‘a‘+ 10);
return
0;
}
//Convert 1 hexadecimal digits into characters.
//Hexadecimal: 16 decimal number, 0 ~15;
//Return value: characters
u8
sim 900 a _ hex 2chr(u8
Hexadecimal)
{
if(hex & lt; =9) Return
Hexadecimal+"0";
If (hexadecimal & gt =10&; & hex< =15) returns.
(hexadecimal-10+'a');
return
'0';
}
//unicode
gbk
Conversion function
//src: input string
//dst: output (if it is uni2gbk, it is the internal code of gbk; Unicode string in case of gbk2uni)
//mode:0, unicode to gbk conversion;
//
1, gbk to unicode conversion;
empty
sim 900 a _ unigbk _ exchange(u8
*src,u8
* Daylight Saving Time, u8
Mode)
{
u 16
temp
u8
buf【2】;
if(mode )//gbk
2
Double bytes are used to encode characters.
{
while(* src! =0)
{
if(* src & lt; 0X8 1)
//Non-Chinese characters
{
temp =(u 16)ff _ convert((WCHAR)* src, 1);
src++;
} Otherwise,
//Chinese characters, accounting for 2 bytes.
{
buf【 1】= * src++;
buf【0】= * src++;
temp =(u 16)ff _ convert((WCHAR)*(u 16 *)buf, 1);
}
* dst++ = sim 900 a _ hex 2chr((temp & gt; & gt 12); 0X0F);
* dst++ = sim 900 a _ hex 2chr((temp & gt; & gt8) and 0x0f);
* dst++ = sim 900 a _ hex 2chr((temp & gt; & gt4) and 0x0f);
* dst++ = sim 900 a _ hex 2chr(temp & amp; 0X0F);
}
} Otherwise,
//unicode
2
gbk
{
while(* src! =0)
{
buf【 1】= sim 900 a _ chr 2 hex(* src++)* 16;
buf【 1】+= sim 900 a _ chr 2 hex(* src++);
buf【0】= sim 900 a _ chr 2 hex(* src++)* 16;
buf【0】+= sim 900 a _ chr 2 hex(* src++);
temp =(u 16)ff _ convert((WCHAR)*(u 16 *)buf,0);
if(temp & lt; 0x 80){ * dst = temp; dst++; }
other
{ *(u 16 *)dst = swap 16(temp); dst+= 2; }
}
}
* dst = 0; //Add terminator
}
//Keyboard code table
constant
u8*
kbd _ TBL 1【 13】= {“ 1“、“2“、“3“、“4“、“5“、“6“、“7“、“8“、“9“、“*“、“0“、“#、“DEL“};
constant
u8*
kbd _ TB L2【 13】= {“ 1“、“2“、“3“、“4“、“5“、“6“、“7“、“8“、“9“、“,“0“,“#“,“DEL“};
u8**
kbd _ tbl
u8*
kbd _ fn _ TBL【2】;
//Load the keyboard interface (size is 240* 140)
//x, y: initial coordinates of the interface (x must be 0 when the resolution is 320*240).
empty
sim 900 a _ load _ keyboard(u 16
x,u 16
y、u8
**kbtbl)
{
u 16
Me;
POINT _ COLOR = RED
kbd _ tbl = kbtbl
LCD _ Fill(x, y, x+240, y+ 140, white);
LCD _ rectangle (x, y, x+240, y+140);
LCD _ rectangle (x+80, y, x+ 160, y+140);
LCD _ rectangle (x, y+28, x+240, y+56);
LCD _ rectangle (x, y+84, x+240, y+112);
POINT _ COLOR = blue;
for(I = 0; I< 15; i++)
{
If (i<13) show _ str _ mid (x+(i% 3) * 80, y+6+28 *(I/3), (u8 *) kbd _ TBL [i],16,80.
other
show _ Str _ Mid(x+(I % 3)* 80,y+6+28 *(I/3),kbd _ fn _ TBL【I- 13】, 16,80);
}
}
- Related articles
- A happy summer greeting text message
- Ok, and send text messages in installments. What does a friend's name mean?
- Suddenly received a text message omsoms requesting to change password
- Write a flyer of more than 200 words
- Nubian mobile phones always can't receive verification codes. What happened?
- How to disinfect after receiving the courier?
- How is Xiaomi Mi 10 useful?
- A brief greeting from the leaders of China New Year.
- For the safety of the community, what should the owner be reminded to say when using the horn at night?
- Blessing to the elders