Joke Collection Website - Blessing messages - Seek a SIM900 controlled by 89C5 1 single chip microcomputer (similar can also be done), and send and receive short messages!
Seek a SIM900 controlled by 89C5 1 single chip microcomputer (similar can also be done), and send and receive short messages!
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
Various test codes (dial test, SMS test and GPRS test) * * *
//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*
Sim900a _ check _ command (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=strstr((const
Char*)USART2_RX_BUF, (constant
Char*) string);
}
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
sim900a_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 channel 7 transmission to complete.
usart 2->; DR =(u32)cmd;
} Otherwise,
u2_printf("%s\r\n ",cmd); //Send command
If (confirm & & wait time)
//Need to wait for an answer
{
While(-waiting time)
//Wait for the countdown
{
delay _ ms( 10);
if(usart 2 _ RX _ STA & amp; 0X8000)// Received the expected response result.
{
If(sim900a_check_cmd(ack)) interrupt; //Get valid data
usart 2 _ RX _ STA = 0;
}
}
if(wait time = = 0)RES = 1;
}
return
res
}
//Convert the 1 character into 16 hexadecimal digits.
//chr: character,0 ~ 9/a ~ f/a ~ f。
//Return value: 16 hexadecimal value corresponding to chr.
u8
sim900a_chr2hex(u8
chr)
{
if(chr & gt; =' 0' & CHR < =' 9') returns.
chr-' 0 ';
if(chr & gt; =' a' & chr < =' f') and press enter.
(chr-' A '+ 10);
if(chr & gt; =' a' & chr < =' f') and press enter.
(chr-' a '+ 10);
return
0;
}
//Convert 1 hexadecimal digits into characters.
//Hexadecimal: 16 decimal number, 0 ~15;
//Return value: characters
u8
sim900a_hex2chr(u8
Hexadecimal)
{
If (hexadecimal < = 9) returns
Hexadecimal+"0";
If (hexadecimal & gt =10&; & hexadecimal < =15) returns.
(hexadecimal-10+'a');
return
'0';
}
//unicode
gbk
mental set shifting
//src: input string
//dst: output (gbk internal code in case of UNI2GBK, unicode string in case of gbk2uni)
//mode:0, unicode to gbk conversion;
//
1, gbk to unicode conversion;
empty
sim900a_unigbk_exchange(u8
*src,u8
* Daylight Saving Time, u8
Mode)
{
u 16
Temperature;
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)& amp; 0X0F);
* dst++ = sim 900 a _ hex 2chr((temp & gt; & gt8)& amp; 0X0F);
* dst++ = sim 900 a _ hex 2chr((temp & gt; & gt4)& amp; 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_tbl2[ 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 coordinate of the interface (x must be 0 when the resolution is 320*240).
empty
Sim900a _ 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_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+ 1 12);
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
- I received a speeding message from the victim's cell phone, and I don't know if it's true or not.
- What should I do if the vivo SMS sign is missing?
- Love words to express love to girls
- What is the name of Yang Zhenzhen's ringtone in Hagar's Three Daughters?
- Illustration of how Huawei Glory x6 is disassembled.
- The four-character idiom of homophonic blessing in the Year of the Rat is a good greeting for the Year of the Rat.
- How to navigate Pinduoduo to the collection point?
- The man I like texted me, and I asked him what happened. He didn't say anything. What happened?
- Dragon Boat Festival blessing pictures and messages Dragon Boat Festival blessing pictures with words
- The credit card of China Bank received a text message saying that it was approved, but it is being approved online.