1、MSP430 单片机学习笔记1MSP430 单片机和 GPRS 模块 MC52i 的应用1. 连接图示2. 程序例程2. #include 3. #include “string.h”4. 5. typedef unsigned short int u166. typedef unsigned char u87. typedef signed short int s168. typedef signed char s89. 10. #define SYS_SUCCESS 011. #define SYS_FAIL 112. /=13. / DTU Pin define14. #define D
2、TU_IGT_PORT_DIR P1DIR15. #define DTU_IGT_PORT_OUT P1OUT16. #define DTU_IGT_PIN BIT617. 18. #define DTU_RTS_PORT_DIR P1DIR19. #define DTU_RTS_PORT_OUT P1OUT20. #define DTU_RTS_PIN BIT221.22. #define DTU_CTS_PORT_DIR P1DIR23. #define DTU_CTS_PORT_IN P1IN24. #define DTU_CTS_PIN BIT425.26. #define DTU_I
3、GT_FIRE DTU_IGT_PORT_DIR |= DTU_IGT_PIN;MSP430 单片机学习笔记227. DTU_IGT_PORT_OUT |= DTU_IGT_PIN28. #define DTU_IGT_SHUT DTU_IGT_PORT_DIR |= DTU_IGT_PIN;29. DTU_IGT_PORT_OUT 31. DTU_RTS_PORT_OUT |= DTU_RTS_PIN32. #define DTU_RTS_LOW DTU_RTS_PORT_DIR |= DTU_RTS_PIN;33. DTU_RTS_PORT_OUT 35. #DTU_CTS (DTU_CT
4、S_PORT_IN 40. u16 g_count = 0 ;41. u8 g_sys_error = SYS_SUCCESS ;42. 43. /*44. * Function Name : Delay *45. * Parameter : uTime *46. * Return :47. */48. void Delay(u16 uTime)49. 50. u16 i=0;51. u16 j=0;52. for (i = 0 ; I (DTU_DAT_LEN -1)MSP430 单片机学习笔记4115. 116. g_count = 0;117. 118. 119. 120. *121.
5、* Function Name : Uart1SendByte *122. * Parameter : u8 dat *123. * Return : *124. */125. void Uart1SendByte(u8 dat)126. 127. while(0 = (IFG2 128. U1TXBUF = dat;129. 130. 131. *132. * Function Name : ClearDtuBuf *133. * Parameter : *134. * Return : *135. */136. void ClearDtuBuf(void)137. 138. u8 len
6、= 0;139. g_count = 0;140. 141. IE2 / Close receive interrupt142. for (; len DTU_DAT_LEN; len+)143. 144. g_rec_buflen = 0 ;145. 146. IE2 |= URXIE1;147. 148. 149. void SendDat(s8 * strptr)150. 151. u8 i.j;152. j = strlen(strptr);153. for (i=0;ij;i+)154. 155. Uart1SendByte(u8)strptri);156. 157. 158. *M
7、SP430 单片机学习笔记5159. * DTU MODULE: Start, Shut, Initialize160. */161. void StartDtu(void)162. 163. DTU_IGT_FIRE;164. Delay(1);165. DTU_IGT_SHUT;166. Delay(100);167. DTU_IGT_FIRE;168. 169. 170. void ShutdownDtu(void)171. 172. Delay(100);173. SendDat(“ATsmsorn”);174. Delay(100);175. 176. 177. void InitD
8、tu(void)178. 179. SendDat(“ATQ3rn”);180. Delay(1000);181. SendDat(“ATE0rn”);182. Delay(100);183. SendDat(“AT+CMGF=1rn”);184. Delay(100);185. SendDat(“AT+CFUN=7rn”);186. Delay(100);187. SendDat(“AT+CFUN?rn”);188. Delay(100);189. 190. 191. void SendDtuMsg(char *num, char * msg)192. 193. char instruct
9、= “AT+CMGS=”;194. char numinstuct27;195. 196. strcpy(numinstuct, instruct);197. strcat(numinstuct, num);198. strcat(numinstuct, “”rn”);199. SendDat(numinstuct);200. SendDat(msg);201. Uart1SendByte(0x1A); / CTRL+Z202.MSP430 单片机学习笔记6203. 204. 205. void main()206. 207. WDTCTL = WDTPW + WDTHOLD; / close WATCH DOG208. InitClock();209. InitUart1();210. DTU_RTS_LOW ;211. 212. StartDtu() ;213. _EINT() ;214. Delay(2000) ;215. InitDtu() ;216. 217. SendDat(“ATrn“) ;218. SendDtuMsg ( ”18615771975”, ”Hello world! Just a Test!”);219. CloseDtu();220. 221. while(1)222. 223. 224. 225.