rlucian90
Junior Member level 1
- Joined
- Sep 21, 2012
- Messages
- 15
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,410
while(1)
{
if(PORTB.B5==1) //button pressed
{ //if it is still pressed after 50ms then
Delay_ms(50); //send SMS
if(PORTB.B5==1)
{
UART1_Init(9600); //init UART
Delay_ms(3000);
//wait for stabilize
while (!UART1_Data_Ready()) {
//sync with modem
sms_AT();
}
trash = UART1_Read(); //clear buffer for next event
sms_mode(); //the text mode for sms
sms_nr(); //sms number to call
sms_msg(); //sms message to send
Delay_ms(100); //light LED
PORTB.B0=1;
Delay_ms(100);
PORTB.B0=0;
Delay_ms(1000);
} //button deboundcer end
} //button pressed end
else
{
PORTB.B0=0;
}
} //While end
}
while(UART1_Data_Ready() == 0); //wait until data is ready for reading
sms_AT();
while (!UART1_Data_Ready()) {
//sync with modem
sms_AT();
}
while(UART1_Data_Ready() == 0) //wait until data is ready for reading
sms_AT();
while(UART1_Data_Ready() == 0); //wait until data is ready for reading
sms_AT();
void sms_AT (){
UART1_Write_Text("AT");
UART1_Write(13); //Enter key = CF + LF
UART1_Write(10);
delay_ms(200);
}
void sms_mode(){
UART1_Write_Text("AT+CMGF=1"); //text mode sms
UART1_Write(13); //Enter key = CF + LF
UART1_Write(10);
delay_ms(500);
}
void sms_nr(){
UART1_Write_Text("AT+CMGS=\"0720050752\""); //phone number
UART1_Write(13); //Enter key = CF + LF
UART1_Write(10);
delay_ms(500);
}
void sms_msg(){
UART1_Write_Text("Senzor activ!"); //sms text
UART1_Write(0x1A); // <ctrl-z>
delay_ms(5000);
}
unsigned char trash[70];
void main() {
int i;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(6000); // Wait for UART module to stabilize
//CMCON = 0x07;
TRISA = 0xFF;
TRISB = 0xFE;
Delay_ms(100); //light LED
PORTB.B0=1;
Delay_ms(1000);
PORTB.B0=0;
while(1)
{
if(PORTB.B5==1) //button pressed
{ //if it is still pressed after 50ms then
Delay_ms(50); //send SMS
if(PORTB.B5==1)
{
UART1_Init(9600); //init UART
Delay_ms(3000);
//wait for stabilize
while (!UART1_Data_Ready()) {
//sync with modem
sms_AT();
}
// trash = UART1_Read(); //clear buffer for next event
sms_mode();
sms_nr();
sms_msg();
Delay_ms(100); //light LED
PORTB.B0=1;
Delay_ms(100);
PORTB.B0=0;
Delay_ms(1000);
} //button deboundcer end
} //button pressed end
else
{
PORTB.B0=0;
}
} //While end
}
Code C - [expand] 1 2 TRISB.F1 = 1; TRISB.F2 = 0;
Code C - [expand] 1 TRISB = 0xFE;
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 void sms_AT (){ UART1_Write_Text("AT"); UART1_Write(13); //Enter key = CF + LF UART1_Write(10); delay_ms(1000); } void sms_mode(){ UART1_Write_Text("AT+CMGF=1"); //text mode sms UART1_Write(13); //Enter key = CF + LF UART1_Write(10); delay_ms(1000); } void sms_nr(){ UART1_Write_Text("AT+CMGS=\"0720050752\""); //phone number UART1_Write(13); //Enter key = CF + LF UART1_Write(10); delay_ms(2000); } void sms_msg(){ UART1_Write_Text("Senzor activ!"); //sms text UART1_Write(0x0D); UART1_Write(0x1A); // <ctrl-z> UART1_Write(0x0D); delay_ms(3000); } unsigned char send_sms = 0; void main(){ TRISA = 0xFF; TRISB = 0xFA; PORTB.B0 = 1; Delay_ms(1000); PORTB.B0 = 0; UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize while(1){ if(PORTB.B5){ Delay_ms(50); if(PORTB.B5){ send_sms = 1; } } if(send_sms){ sms_AT(); sms_mode(); sms_nr(); sms_msg(); PORTB.B0 = 1; Delay_ms(1000); PORTB.B0 = 0; send_sms = 0; } } }
@zuisti I eliminate the UART_INIT from the while loop and reduced the delay for every AT command and seems it works better. I recieved 5 SMS but when i pressed the button for the 6th one the led showed that the sms was sent but it doesnt. I connected the computer to see what is sending the uC and i saw that the part with AT was skipped so the UART_Ready was always 1 and sent to phone only the command to send SMS without being sync. I think i'm close.
@jayanth.devarayanadurga I'm trying on real hardware. Where to add those line in the while loop or before the INIT from the beginning?
@#MAAM# I connected that way to have a TTL signal for both phone and uC. Isn't the same thing if i connect it to 14 and 13 ? I thought those outputs are only for the computer which is +10V and -10V logical.
while (UART1_Data_Ready()) { //sync with modem
trash[i]=RCREG;
i=i+1;
}
i=0;
// UART1_Write_Text(trash);
// UART1_Write(13); //Enter key = CF + LF //those Uart_Writes were for me to see.
// UART1_Write(10);
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?