|
如题,前阵子本人买了一块GSM模块,PTM100,实现了通过STM32控制GSM模块发送短信及彩信; 趁此机会将源码上传与大家共享,希望大家拍砖 8 B) t2 b) A" @1 ^. v4 N PS:发帖字数有限,只能发了main函数部分,其他部分在附件中,大家可自行下载查看 int main(void)1 P- R) g9 h( m { 2 l6 g1 X! C; q* u0 p$ g# L u8 count_error=0,GSM_Init_Flag=0x00; u8 length;& G. C; d/ X4 { ~ RCC_Configuration(); GPIO_Configuration(); + {3 i/ p+ L5 O$ ?# T% E NVIC_Configuration(); USART_Configuration();0 r! u1 j& b9 b3 [- V& Y gsm_count=0;% n; ~; A( I7 f k1 W2 I5 @ GPIO_SetBits(GPIOA,GPIO_Pin_0); 8 O4 J/ ~0 Q% E% U4 f2 H2 X GPIO_SetBits(GPIOA,GPIO_Pin_4); GPIO_SetBits(GPIOA,GPIO_Pin_5); GPIO_SetBits(GPIOA,GPIO_Pin_6);9 o1 \" Y: L1 s3 _; D, s* F GPIO_SetBits(GPIOA,GPIO_Pin_7); GPIO_SetBits(GPIOA,GPIO_Pin_8); GSM_Init_Flag=CheckGSM();" q! Q8 J9 n6 e : p1 x5 g. c) N5 ?: S0 \, o y" e while(1) { : U3 \* ?) o8 o+ X- j) t: ] if(GSM_Init_Flag==USART_ERROR) & L/ |. q8 }% h {3 \, H7 G: c0 o: } if(count_error==0) {! v0 _8 V3 b" ]6 ]8 u5 M USART2_SendToPC("USART_ERROR\n",12);: R8 L5 G: n" j! z( K: L0 }# t0 s count_error++; }) }: j5 _/ L7 {5 P" ] GPIO_ResetBits(GPIOA,GPIO_Pin_0);& s/ d1 y; z; Y( {7 `$ C Delay_us(10000);9 {0 R/ M7 g% r* f, v GPIO_SetBits(GPIOA,GPIO_Pin_0);4 o& Q+ Z# y/ z7 Y! g Delay_us(10000); } else if(GSM_Init_Flag==CIMI_ERROR) {7 a) \& Y0 Y, G' p0 E' o* k+ Q if(count_error==0)+ n9 x$ X4 t8 n5 f- N! R {9 ~0 [# M, G. V" D' Z3 p1 w USART2_SendToPC("CIMI_ERROR\n",11); count_error++;4 R C0 v0 {: n8 R; B }" ~' X N0 r# x& r & o o9 W' C6 v2 |* O& q9 I& l GPIO_ResetBits(GPIOA,GPIO_Pin_4); Delay_us(10000); GPIO_SetBits(GPIOA,GPIO_Pin_4);: ]) n I% g2 z( y Delay_us(10000);7 y8 C% d& r$ U( n- ~( e7 n+ p) L- p } else if(GSM_Init_Flag==CREG_ERROR) {0 ^, G' D: U8 `8 w$ \/ R2 L# _ if(count_error==0) {$ l1 ]- t! K- F) @ USART2_SendToPC("CREG_ERROR\n",11);" t! Q5 R9 U" S! g+ k, Z) Y count_error++;- B. r8 J9 d H( v } " g j, i7 ?4 O. z GPIO_ResetBits(GPIOA,GPIO_Pin_5); Delay_us(10000); GPIO_SetBits(GPIOA,GPIO_Pin_5);( d+ f# p7 v: ^! @; P9 } Delay_us(10000);1 x- V, G- e5 s } else if(GSM_Init_Flag==CSQ_ERROR) { p2 b( |6 j/ r" g if(count_error==0)$ k2 Q6 U! N# H { USART2_SendToPC("CSQ_ERROR\n",10); count_error++; }' b+ ]6 W! y* s8 {) i 9 I' m t. t% I1 l3 M) D0 D! P GPIO_ResetBits(GPIOA,GPIO_Pin_6);$ N9 P8 ?0 K, F% R Delay_us(10000);, f6 ?- w+ I q, H GPIO_SetBits(GPIOA,GPIO_Pin_6); Delay_us(10000); } % W4 v7 _( v/ c4 @% N; `+ N else { 7 c2 D8 q4 i; ]! s0 T8 H+ _8 E count_error=0; GPIO_ResetBits(GPIOA,GPIO_Pin_7); Delay_us(10000); GPIO_SetBits(GPIOA,GPIO_Pin_7); Delay_us(10000);1 ^! m, {8 e0 c6 _( W& S7 V }; g) E2 [ n8 j) x 2 \2 `4 U& `0 M* N3 {5 E! K if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1)==0) { Delay_us(15000); if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1)==0)/ C( g2 K/ b0 Q! W5 e# } while(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1)); Message_Send(Phone_Num,Title,strlen(Title),MMS,3286);6 w( q# q+ k' E" j5 F% r }- E% O: O- X8 D+ F P1 x5 s9 o, A2 f8 f1 i0 } } } |
main.zip
下载9.47 KB, 下载次数: 101
微信公众号
手机版
void Delay_us(unsigned int count)
{3 ^# f! W h0 C- u' c6 U
unsigned int i=0;, U0 Q8 `* Q( n2 J3 B/ m: o5 ^$ h* a
while(count--): B" V j% k7 a- j% P8 u2 }
{
for(i=0;i<24;i++);
}
}) s# E+ ?8 {; |7 u5 M" d0 V k+ V
) m+ C* S' Z( T
这是延时函数,只是大概延时了一段时间,因为只是自己学的玩的,没那么较真
玩玩还是可以的,总归是为了学习,花点钱也值了
玩玩还是可以的,总归是为了学习,花点钱也值了
不到100,串口通讯
谢谢支持
嘿嘿,谢谢
谢谢支持
谢谢支持