作品:基于SIM900A的電池自動滿電提醒及實時查詢電量裝置,附件中含有SIM900A參考資料,源碼,仿真圖等
proteus仿真原理圖:仿真圖中不包含sim900A模塊,7805模塊可以將輸入電壓在6-36V之間的電壓穩定輸出為5V,作為ADC0832的電壓源以及參考電壓。
微信圖片_20181010160548.png (94.26 KB, 下載次數: 48)
下載附件
2018-10-10 16:20 上傳
實物圖:測量的電池(核定電壓在12V)電量為10V左右,14.4V為滿電浮充狀態(以14.4V為滿電標準,信息顯示電滿),此時10V,則顯示少于90%電量。
微信圖片_20181010162209.jpg (163.43 KB, 下載次數: 69)
下載附件
2018-10-10 16:22 上傳
微信圖片_20181010162205.jpg (213.6 KB, 下載次數: 52)
下載附件
2018-10-10 16:22 上傳
微信圖片_20181010162352.png (242.48 KB, 下載次數: 41)
下載附件
2018-10-10 16:23 上傳
單片機主函數代碼:
- /*******************************************************************************
- * 標題: 基于SIM900A的自動充電提醒以及實時查詢電量裝置 *
- * 時間 2018年10月10日16:12:42 *
- * *
- * 實驗說明:本裝置的核心是SIM900A模塊,需要調用SIM900A指令。本原理圖中ADC0832 *
- 的參考電壓為5V,由7805穩壓源提供7805的電源以及參考電壓。檢測電池的電壓在9-15V之 *
- 間,采用分壓方式,一個30K,一個10K電阻進行分壓。假如檢測電壓為15V,則輸入ADC0832 *
- 的電壓為5V。依次類推。 *
- *
- ********************************************************************************
- * 實驗心得:SIM900A是個難點,需要在電腦上進行調試。ADC0832進行AD轉化的時候,需 *
- 要研究下時序圖,在進行數據檢測的時候需要進行兩次檢測,如果前后兩次數據相等,那 *
- 么再返回得到的值,減少了測量誤差。7805穩壓源是個重要的部件,為了提供精確穩定的 *
- 5V參考電壓 *
- ********************************************************************************/
- #include <reg51.h>
- #include "UART.h"
- #include "DELAY.h"
- #include "define.h"
- #include "ADC0832.h"
- //全局變量
- #define Yes 1
- #define No 0
- typedef unsigned int u16;
- typedef unsigned char u8;
- unsigned char number[11]={'0','0','0','0','0','0','0','0','0','0','0'};
- unsigned char Voltage_bit; //對電壓進行AD轉化后的數字信號,5V為參考電壓,此時Voltage_bit=256;
- float Percentage; //電量百分比,Percentage = Voltage/256;
- /********測試GSM是否啟動**********/
- int test_boot;
- /********測試GSM是否注冊網絡**********/
- int test_net_register;
- /********測試是否有電話打入**********/
- int test_have_call;
- /********測試是否有信息發入**********/
- int test_have_SM;
- /********GSM串口接收數據緩存**********/
- unsigned char GSM_receive[60];
- /********GSM串口接收計數器**********/
- unsigned char GSMDATA_count;
- /********號碼緩存*******************/
- /********短信發送程序********/
- //IO口定義
- sbit K1 = P2^0;
- sbit K2 = P2^1;
- sbit Powerkey = P2^2;
- sbit beep = P1^5;
- //短信發送程序
- void message()
- {
- Send_String("AT+CMGF=1\r\n");//指定信息的輸入輸出格式為文本格式
- Delay_Ms(100);
-
- Send_String("AT+CSMP=17,167,2,25\r\n"); //
- Delay_Ms(100);
-
- Send_String("AT+CSCS=\"UCS2\"\r\n"); //設置為 UCS2 字符集編碼
- Delay_Ms(100);
-
- Send_String("AT+CMGS=\"00310038003800380038003600340035003000300033\"\r\n"); //號碼18888645003的Unicode編碼,0031 0038 0038 0038 0038 0036 0034 0035 0030 0030 0033
- Delay_Ms(100);
-
- Send_String("4E3B4EBAFF0C53C889C197625566\r\n"); //主人,又見面啦 4E3B 4EBA FF0C 53C8 89C1 9762 5566
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- }
- void Phonemessage()
- {
- Send_String("AT+CMGF=1\r\n");//指定信息的輸入輸出格式為文本格式
- Delay_Ms(100);
-
- Send_String("AT+CSMP=17,167,2,25\r\n"); //
- Delay_Ms(100);
-
- Send_String("AT+CSCS=\"UCS2\"\r\n"); //設置為 UCS2 字符集編碼
- Delay_Ms(100);
-
- Send_String("AT+CMGS=\"00310038003800380038003600340035003000300033\"\r\n"); //號碼18888645003的Unicode編碼,0031 0038 0038 0038 0038 0036 0034 0035 0030 0030 0033
- Delay_Ms(100);
-
- Send_String("4E3B4EBAFF0C62116536523075358BDD5566\r\n"); //主人,我收到電話啦 4E3B 4EBA FF0C 6211 6536 5230 7535 8BDD 5566
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- }
- void othermessage()
- {
- Send_String("AT+CMGF=1\r\n");//指定信息的輸入輸出格式為文本格式
- Delay_Ms(100);
-
- Send_String("AT+CSMP=17,167,2,25\r\n"); //
- Delay_Ms(100);
-
- Send_String("AT+CSCS=\"UCS2\"\r\n"); //設置為 UCS2 字符集編碼
- Delay_Ms(100);
-
- Send_String("AT+CMGS=\"00310038003800380038003600340035003000300033\"\r\n"); //號碼18888645003的Unicode編碼,0031 0038 0038 0038 0038 0036 0034 0035 0030 0030 0033
- Delay_Ms(100);
-
- /*Send_String("00560065006E00630065002C6211653652304F60768477ED4FE15566\r\n"); //主人,我收到電話啦 4E3B 4EBA FF0C 6211 6536 5230 7535 8BDD 5566
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);*/
- }
- void delay(u16 i)
- {
- while(i--);
- }
- void main()
- {
- unsigned char j=0;
- test_boot = No;
- Powerkey = 0;
- test_have_call=No;
- test_have_SM = No;
- //GSM啟動
- Powerkey=1;
- Delay_Ms(1000); //系統重啟在開機和關機之間的間隔要大于800ms.
- Powerkey=0;
- Uart_Init();
- while(test_boot==No)
- {
- Send_String("AT\r\n"); //如果開機成功,則會返回一個OK,進入串口中斷
- Delay_Ms(1000);
- }
- Send_String("AT+CLIP=1\r\n");
- Delay_Ms(100);
- while(1)
- {
- Voltage_bit = ADC0832(0); //從ADC轉化通道0進入,模數轉化后的值為Voltage_bit;
- Percentage = (float)Voltage_bit/256; //電量百分比轉化語句
- j = 0;
- if(K1==0)
- {
- while(j==0)
- {
- message();
- j=1;
- }
-
- }
- if(K2==0)
- {
- while(j==0)
- {
- othermessage();
- j=1;
- }
- }
- while(test_have_call==Yes)
- {
- if(number[10]=='3'&&number[9]=='0'&&number[8]=='0'&&number[7]=='5')
- Phonemessage();
- break;
- }
-
- if(test_have_SM == Yes)
- {
- //Send_String("AT+CMGR=1\r\n");
- //if(GSM_receive[69]=='7'&&GSM_receive[70]=='5'&&GSM_receive[71]=='3'&&GSM_receive[72]=='5')
- //{
- Send_String("AT+CMGD=1\r\n");
- if(Percentage<=0.1)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E003100300025\r\n"); //Vence,電量少于10%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
-
- }
-
- if(Percentage>0.1&&Percentage<=0.2)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E003200300025\r\n"); //Vence,電量少于20%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
-
- if(Percentage>0.2&&Percentage<=0.3)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E003300300025\r\n"); //Vence,電量少于30%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
-
- if(Percentage>0.3&&Percentage<=0.4)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E003400300025\r\n"); //Vence,電量少于40%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
-
- if(Percentage>0.4&&Percentage<=0.5)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E003500300025\r\n"); //Vence,電量少于50%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
-
- if(Percentage>0.5&&Percentage<=0.6)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E003600300025\r\n"); //Vence,電量少于60%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
-
- if(Percentage>0.6&&Percentage<=0.7)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E003700300025\r\n"); //Vence,電量少于70%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
-
- if(Percentage>0.7&&Percentage<=0.8)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E003800300025\r\n"); //Vence,電量少于80%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
-
- if(Percentage>0.8&&Percentage<=0.9)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E003900300025\r\n"); //Vence,電量少于90%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
-
- if(Percentage>0.9&&Percentage<1)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF5C114E8E0031003000300025\r\n"); //Vence,電量少于100%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
-
- if(Percentage==1)
- {
- othermessage();
- Send_String("00560065006E00630065002C73B05728753591CF4E3A0031003000300025\r\n"); //Vence,電量為100%
- Delay_Ms(100);
- Send_Char(0x1A); //結束命令符號
- Delay_Ms(200);
- test_have_SM = No;
- Send_String("AT+CMGD=1,4\r\n");
- }
- //}
-
- }
- }
- }
- /****************************************************************************/
- void uart(void) interrupt 4
- {
- unsigned char UART_data;
- unsigned char i;
- if(RI)
- {
- UART_data=SBUF;
- if(UART_data=='\n')
- {
- if(GSM_receive[0]=='O'&&GSM_receive[1]=='K')
- test_boot=Yes;
- else
- test_boot=No;
-
- if(GSM_receive[12]=='C')
- test_net_register=Yes;
- else
- test_net_register=No;
-
- if(GSM_receive[0]=='R'&&GSM_receive[1]=='I'&&GSM_receive[2]=='N'&&GSM_receive[3]=='G')
- {
- test_have_call=Yes;
- }
- else
- {
- test_have_call=No;
- }
-
- if(GSM_receive[0]=='+'&&GSM_receive[1]=='C'&&GSM_receive[2]=='L'&&GSM_receive[3]=='I'&&GSM_receive[4]=='P')
- {
- for(i=0;i<11;i++)
- {
- number[i]=GSM_receive[i+8];
- }
- //display_number(line_2,0x00);
-
-
- }
- if(GSM_receive[0]=='+'&&GSM_receive[1]=='C'&&GSM_receive[2]=='M'&&GSM_receive[3]=='T'&&GSM_receive[4]=='I')
- {
- test_have_SM = Yes;
- }
- GSMDATA_count=0;
- }
- else
- {
- GSM_receive[GSMDATA_count]=UART_data;
- GSMDATA_count++;
- }
- }
- RI=0;
- }
復制代碼
0.png (44.61 KB, 下載次數: 45)
下載附件
2018-10-10 17:05 上傳
0.png (16.2 KB, 下載次數: 56)
下載附件
2018-10-10 17:06 上傳
全部資料51hei下載地址:
SIM900A自動滿電提醒裝置.zip
(8.4 MB, 下載次數: 51)
2018-10-10 16:32 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|