ronydc said:ok ok.. friends..
no need to reply this post.
i have got the solution and i am able to make 8 relays on and off with SMS with IC 8051.
THANKS ANY WAY.
ronydc said:ok ok.. friends..
no need to reply this post.
i have got the solution and i am able to make 8 relays on and off with SMS with IC 8051.
THANKS ANY WAY.
program smsController
'*************Variable declaration******************
Symbol LongDELAY = Delay_ms(500)
Symbol ShortDELAY = Delay_ms(50)
dim sms_receive, temp as byte
dim Sender_Num, phone_num as integer [12]
dim comm as byte [14]
dim a, i, j, k as byte
'**************variable and constant declaring and initializing**************
const CMD1 = "AT+CPMS=ME ,0x0d, 0" 'Select the phone memory ("ME")
const CMD2 = "AT+CMGR=1 ,0x0d, 0" 'read the received message(Memory possition 1)
const CMD3 = "AT+CMGD=1 ,0x0d, 0" 'delete the received message (Memory possition1)
const CMD4 = "AT+CMGF=1 ,0X0d, 0" 'set message format to text mode
const CMD5 = "ATEO ,0X0d, 0" 'Disable echo from modem
const defaultnum = "255714021335" 'default number to the system
sub procedure interrupt ' Interrupt service routine to register def No
if INTCON.RBIF = 1 then ' Changes on RB4-RB7 ?
INTCON.RBIF = 0
else if INTCON.INTF = 1 then ' External interupt (RB0 pin switch button) ?
phone_num = defaultnum ' Goto save the num to eeprom for
goto regista ' sender verification
INTCON.INTF = 0
else if INTCON.T0IF = 1 then ' TMR0 interrupt occurred ?
INTCON.T0IF = 0
else if INTCON.EEIF = 1 then ' Is EEPROM write cycle finished ?
INTCON.EEIF = 0
end if
end if
end if
end if
end sub
main: 'program start here
TRISB = %00111111 ' Pins RB6 and RB7 are output
OPTION_REG = %10000000 ' Turn off pull-up resistors
' and set interrupt on falling edge
' of RB0 signal
INTCON = %10010000 ' Enable external interrupts
PORTB = 0 ' Initial value on PORTB
'***********send command to initialize mobile phone***********
Usart_init(2400) 'initializing baud rate 4 rx and tx
Usart_Write_Text(CMD5) 'stop echos from modem
LongDelay
Usart_Write_Text(CMD1) 'initializing phone memory 1 for sms
LongDelay
Usart_Write_Text(CMD4) 'initiate modem to text mode
CheckSMS:
LongDELAY
Usart_Write_Text(CMD2) 'send command to read the sms from phone memory1
start_read:
if Usart_Data_Ready = 1 then
i = 0
j = 0
goto again
inc (j)
else if j = 4 then '\ =>if looped 4 times no sms
goto CheckSMS '/ ask modem for next time
else goto start_read
end if
end if
again:
sms_receive = Usart_Read
if sms_receive = $2B then'\ skip first + sign find next +
inc (i) '\ (2B="+")
else if i=2 then
i=0
goto save_num
else if sms_receive = $0A then'skip all other sms string
k=0
goto copy_comm '/ sms command
end if
end if
end if
ShortDELAY
goto again
save_num: 'saving sender number to ram
for i=0 to 11
Sender_Num= Usart_Read
Delay_ms(45)
next i
goto again
copy_comm:'copy a command and save to the uCU's ram
while true
sms_receive = Usart_Read
if sms_receive <> $0B then '=>(0B =11= CR) at the end of text sms
comm[k]= sms_receive
inc (k)
ShortDELAY
else goto sender_var
end if
wend
sender_var: 'do verification of sender number
for j=0 to 11
temp = eeprom_read(j)
if temp = Sender_Num[j] then
for a = 0 to 200
Delay_us(500)
next a
else if j=11 then
goto comm_interp 'if valid go to interplate the command
else goto clear_memory' => the number is invalid when j <> 11
end if
end if
next j
clear_memory: 'clear memory and delete message on modem
for i=0 to 11
Sender_Num=$0
next i
for j=0 to 13
comm[j]=$0
next j
Usart_Write_Text(CMD3)
goto start_read
comm_interp: 'interprate command
if comm[0]="o" then
goto openn
else if comm[0]="c" then
goto closse
else if comm[0]="r" then
j=0
phone_num = Sender_Num
goto regesta
goto clear_memory
else goto clear_memory
end if
end if
end if
openn: 'Open door
PORTB.1=1
LongDelay
PORTB.1=0
goto clear_memory
closse: 'Close door
PORTB.2=1
LongDelay
PORTB.2=0
goto clear_memory
regesta: 'Do register new number to the system that will be used to verify sms sender number
for i = 0 to 11
Eeprom_Write(i, phone_num)
for j = 0 to 200
Delay_us(500)
next j
next i
return
end.
yasir: ths is my first project the the person who encouraged me to get into this world of PIC programming adviced me to start with Basic so after i finish this i will do next project in C but i am new to this world.yasir9909 said:why don't you better use 'C' language instead of basic
C is most widely used language for microcontroller programming
yasir: ths is my first project the the person who encouraged me to get into this world of PIC programming advised me to start with Basic so after i finish this i will do next project in C but i am new to this world.yasir9909 said:why don't you better use 'C' language instead of basic
C is most widely used language for microcontroller programming
//ICC-AVR application builder : 6/22/2009 9:22:22 AM
// Target : M32
// Crystal: 7.3728Mhz
#include <iom32v.h>
#include <macros.h>
unsigned char SMSFlag=0,SMSReadFlag=0,ButtonPressed=0;
unsigned int timer0_counter=0;
unsigned int i=0,j=0,k=0;
unsigned char cmd_cmgf[]="AT+CMGF=1\r";
unsigned char cmd_cmgl[]="AT+CMGL=\"ALL\"";
unsigned char cReturn[]="\r";
unsigned char cmd_cmgs[]="AT+CMGS=\"+913451234567\"";
unsigned char cmd_AT[]="AT\r";
unsigned char cmd_cgmm[]="AT+CGMM\r";
unsigned char testMessage[]="Hello! this is Test Message!!!";
unsigned char ctrlZ=0x1A;
/***********************************************************************************************/
void delay_1uSec(unsigned int);
void delay_1uSec(unsigned int m) // approximately m*1uSec Delay
{
for(j=0;j<m;j++)
{
for(k=0;k<8;k++)
asm("nop");
}
}
//**********************************************************************************************//
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x01;
DDRB = 0x00;
PORTC = 0x00;
DDRC = 0x0F;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER0 initialize - prescale:8
// desired value: 8KHz
// actual value: 8.014KHz (0.2%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x8D; //set count
OCR0 = 0x73; //set compare
TCCR0 = 0x02; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:12
void timer0_ovf_isr(void)
{
TCNT0 = 0x8D; //reload counter value
timer0_counter++;
if(ButtonPressed==1)
PORTC = 0x0F|PORTC;
}
//UART0 initialize
// desired baud rate: 57600
/* ************************************************************************ */
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x07; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x18;
}
///////////////////////// UART data receive routine //////////////////////////
unsigned char ReceiveByte(void)
{
while(!(UCSRA & BIT(RXC)));
return UDR;
}
///////////////////////// UART data transmit routine //////////////////////////
void SEND_CHAR_UART(char ch)
{
while(!(UCSRA & BIT(UDRE))) ;
UDR = ch;
}
//*----------------------------------------------------------------------------*//
void SendStr(char *ch)
{
while(*ch != 0x00)
SEND_CHAR_UART(*ch++);
}
/*------------------------------------*/
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
uart0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x01; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//
void main(void)
{
init_devices();
//insert your functional code here...
//*************************************
// Set Text Mode
//*************************************
for(i=0;i<sizeof(cmd_cmgf);i++)
SEND_CHAR_UART(cmd_cmgf[i]);
//*************************************
for(i=0;i<sizeof(cmd_AT);i++)
SEND_CHAR_UART(cmd_AT[i]);
//*************************************
for(i=0;i<sizeof(cmd_cgmm);i++)
SEND_CHAR_UART(cmd_cgmm[i]);
//*************************************
delay_1uSec(90000);
// AT+CMGL="ALL"
SEND_CHAR_UART('A');
SEND_CHAR_UART('T');
SEND_CHAR_UART('+');
SEND_CHAR_UART('C');
SEND_CHAR_UART('M');
SEND_CHAR_UART('G');
SEND_CHAR_UART('L');
SEND_CHAR_UART('=');
SEND_CHAR_UART('"');
SEND_CHAR_UART('A');
SEND_CHAR_UART('L');
SEND_CHAR_UART('L');
SEND_CHAR_UART('"');
for(i=0;i<sizeof(cReturn);i++)
SEND_CHAR_UART(cReturn[i]);
//***************************************
delay_1uSec(90000);
delay_1uSec(90000);
// AT+CMGS="+913451234567"
SEND_CHAR_UART('A');
SEND_CHAR_UART('T');
SEND_CHAR_UART('+');
SEND_CHAR_UART('C');
SEND_CHAR_UART('M');
SEND_CHAR_UART('G');
SEND_CHAR_UART('S');
SEND_CHAR_UART('=');
SEND_CHAR_UART('"');
SEND_CHAR_UART('+');
SEND_CHAR_UART('9');
SEND_CHAR_UART('1');
SEND_CHAR_UART('3');
SEND_CHAR_UART('4');
SEND_CHAR_UART('5');
SEND_CHAR_UART('1');
SEND_CHAR_UART('2');
SEND_CHAR_UART('3');
SEND_CHAR_UART('4');
SEND_CHAR_UART('5');
SEND_CHAR_UART('6');
SEND_CHAR_UART('7');
SEND_CHAR_UART('"');
SEND_CHAR_UART(13); //Carriage Return
delay_1uSec(90000);
for(i=0;i<sizeof(testMessage);i++)
SEND_CHAR_UART(testMessage[i]);
SEND_CHAR_UART(26); //CTRL-Z
//***************************************
while(1)
{
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?