Joke Collection Website - Public benefit messages - Detailed Analysis of C Language SMS Billing
Detailed Analysis of C Language SMS Billing
# include & ltreg52.h & gt
# Define uchar unsigned characters
# Define uint unsigned integer
void GSM _ UART();
Unsigned integer uart_delay (unsigned integer z);
void GSM _ init();
void GSM _ CMGF();
void GSM _ ATC MGS();
void TELNUM();
void GSM _ TEXT();
void GSM _ test();
void BUTTON();
Unsigned integer d;
Unsigned character code atenter [] = {0x41,0x54, 0x0d };;
Unsigned character code atcmgcenter [] = {0x41,0x54, 0x2b, 0x43, 0x4d, 0x47, 0x 46, 0x3d, 0x3 1, 0x0d };;
Unsigned character code atcmgs [] = {0x41,0x54, 0x2b, 0x43, 0x4d, 0x47, 0x53, 0x3d };;
Unsigned character code tel _ num [] = {0x30, 0x3 1, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39};
Unsigned character code text [] ={0x4b, 0x4f };;
Unsigned character code Enter【】= {0x0d };;
Unsigned character code onea [] = {0x31,0x41};
Unsigned character idatabuf [20];
Int mark;
int buf num = 0;
uchar str 1【】= {“AT“};
uchar str 2【】= {“ATD“};
uchar str 3【】= {“ATH“};
uchar str 5【】= {“AT+CMGS =“};
sbit bell=p 1^6;
sbit betton 1_ 1=p3^3;
sbit betton 1=p3^4;
void gsm_uart()
{ EA = 1;
ES = 1;
SCON = 0x 50; //UART mode 1:8-bit UART; REN= 1: receiving is allowed.
PCON = 0x 00; //SMOD=0: The baud rate is not doubled.
TMOD = 0x 20; //t 1 mode 2, used for UART baud rate.
th 1 = 0x FD;
TL 1 = 0x FD; //UART baud rate setting: 9600
TI = 0;
RI = 0;
EA = 1;
tr 1 = 1;
}
Unsigned integer uart_delay (unsigned integer z)
{unsigned integers a, b;
for(a = z; a & gt0; Answer-)
{ for(b = 1000; b & gt0; B-); }
Return z;
}
Use 3 to invalidate ddd () interrupt 4.
{
If(RI)// handles the reception interrupt.
{ buf【buf num】= SBUF; //receive serial data
RI = 0;
buf num++; //Clear the interrupt flag bit
}
}
void GSM_init()
{
uint I;
Uchar code test [] = {0x4 1, 0x54, 0x0d };;
ES = 0;
for(I = 0; I<3; i++)
{
SBUF = test【I】;
while(TI = = 0);
TI = 0;
}
ES = 1;
}
void GSM_CMGF()
{
uchar code sel【 10】= { 0x4 1,0x54,0x2B,0x43,0x4D,0x47,0x 46,0x3D,0x3 1,0x0d }; //AT+CMGF= 1 enter
uint I;
for(I = 0; I< 10; i++)
{
SBUF = sel【I】;
while(TI = = 0);
TI = 0;
}
}
void GSM_ATCMGS()
{ uint I;
Uchar code tel [20] = {0x41,0x54, 0x2B, 0x43, 0x4D, 0x47, 0x53, 0x3D, 0x3 1, 0x33, 0x38, 0x33,
0x36,0x30,0x32,0x33,0x33,0x37,0x39,0x0d };
for(I = 0; I & lt20; i++)
{
SBUF = tel【I】;
while(TI = = 0);
TI = 0;
}
}
void GSM_TEXT()
{
uchar code ne irong【 10】= { 0x 48,0x69,0x2 1,0x6E,0x69,0x68,0x6 1,0x6F,0x2E,0x 1a }; //Hi! Ni Hao.
uint I;
ES = 0;
for(I = 0; I< 10; i++)
{
SBUF = nei Rong【I】;
while(TI = = 0);
TI = 0;
}
ES = 1;
}
Void send ()
{
SBUF = oneA【0】; while(TI = = 0); TI = 0;
SBUF = oneA【 1】; while(TI = = 0); TI = 0;
}
void GSM_test()
{
GSM _ UART();
UART _ delay(400);
GSM _ init();
UART _ delay( 1000);
ES = 0;
buf num = 0;
if(buf【5】= =‘O‘& amp; & ampbuf【6】= =‘K‘。
{
P0 = 0xfeUART _ delay( 1000); P0 = 0xff
}
other
{
P0 = 0x00UART _ delay(4000); P0 = 0xff
}
}
Void button ()
{ betton 1 = 1;
betton 1 _ 1 = 0;
if(betton 1 = = 0)
{
GSM _ test();
UART _ delay( 1200);
GSM _ CMGF();
UART _ delay( 1200);
GSM _ ATC MGS();
UART _ delay( 1200);
GSM _ TEXT();
UART _ delay(800);
UART _ delay(500);
betton 1 = 1;
}
}
Master ()
{
BUTTON();
UART _ delay( 10);
}
- Previous article:Ping' an ringtone SMS
- Next article:My girlfriend has always ignored me recently. What does that mean?
- Related articles
- Why can't Apple 4 send text messages?
- How to cancel SMS verification service
- Xi' an property market new policy: adjust the down payment ratio of second-home commercial loans according to the existing housing area.
- Give birth to a child and send a WeChat red envelope.
- How to set voice ringtones
- My 6 120c SMS module has been cracked. What if I can't receive any text messages?
- Why does Tong Yuan always show the epidemic situation?
- What are the precautions for traveling to Myanmar?
- What day is the Lantern Festival in 217? What day is it?
- If the mobile phone newspaper is not distributed successfully, will the system save the distribution record and for how long?