Working mikroC PRO Code attached.
Code C - [expand ] 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <reg51.h>
unsigned char Command_AT[ 3 ] = "AT" ;
unsigned char Command_CMGF[ 16 ] = "AT+CMGF=1" ;
unsigned char Command_CMGS[ 16 ] = "AT+CMGS=" ;
unsigned char mobileno[ 16 ] = "+919590166616" ;
unsigned char SMS0[ ] = "Hello!" ;
void Delay_ms( unsigned int msec) ;
void UART_Init( ) ;
void SendSMS( ) ;
void UART_Write( unsigned char uartData) ;
void UART_Write_Text( unsigned char * uartData) ;
void Delay_ms( unsigned int msec) {
unsigned int i;
for ( i = 0 ; i < ( 5 * msec) ; i++ ) ;
}
void UART_Init( ) {
P3 = 0x03 ;
TMOD = 0x20 ;
SCON = 0x50 ;
TH1 = 0xFD ;
TR1 = 1 ;
EA = 1 ;
ES = 1 ;
}
void SendSMS( ) {
UART_Write_Text( Command_AT) ;
UART_Write( 0x0D ) ;
UART_Write( 0x0A ) ;
Delay_ms( 4000 ) ;
UART_Write_Text( Command_CMGF) ;
UART_Write( 0x0D ) ;
UART_Write( 0x0A ) ;
Delay_ms( 4000 ) ;
UART_Write_Text( Command_CMGS) ;
UART_Write( 0x22 ) ;
UART_Write_Text( mobileno) ;
UART_Write( 0x22 ) ;
UART_Write( 0x0D ) ;
UART_Write( 0x0A ) ;
Delay_ms( 8000 ) ;
UART_Write_Text( SMS0) ;
UART_Write( 0x0D ) ;
UART_Write( 0x1A ) ;
UART_Write( 0x0D ) ;
Delay_ms( 8000 ) ;
}
void UART_Write( unsigned char uartData) {
SBUF = uartData;
while ( TI == 0 ) ;
TI = 0 ;
}
void UART_Write_Text( unsigned char * uartData) {
while ( * uartData) UART_Write( * uartData++ ) ;
}
void main ( ) {
UART_Init( ) ;
Delay_ms( 4000 ) ;
while ( 1 ) {
SendSMS( ) ;
}
}
GSM 8051.rar
25.1 KB · Views: 37
Last edited: Oct 21, 2013