Update Call
This commit is contained in:
parent
bcc466f985
commit
293060dac0
53
main.c
53
main.c
@ -104,14 +104,13 @@
|
|||||||
/* These are the definitions */
|
/* These are the definitions */
|
||||||
|
|
||||||
const char String1[3] = "OK"; //ok response
|
const char String1[3] = "OK"; //ok response
|
||||||
const char String2[11] = "NO CARRIER"; //call state change
|
const char String2[27] = "+CLIP: \"+421905708125\",145"; //call state change
|
||||||
const char String3[6] = "ERROR"; //ok response
|
|
||||||
const char String4[10] = "SMS Ready"; //modem startup
|
const char String4[10] = "SMS Ready"; //modem startup
|
||||||
|
|
||||||
const char StringDial[14] = "+421905708125";
|
const char StringDial[14] = "+421905708125";
|
||||||
|
|
||||||
//#define TMR0_BAUD (256-133) /* trial and error value, comes to 3603 Baud */
|
//#define TMR0_BAUD (256-133) /* trial and error value, comes to 3603 Baud */
|
||||||
#define TMR0_BAUD (256-133) /* trial and error value, comes to 3603 Baud */
|
#define TMR0_BAUD (256-128) /* trial and error value, comes to 3603 Baud */
|
||||||
|
|
||||||
#define TxBUF_SIZE 32
|
#define TxBUF_SIZE 32
|
||||||
#define RxBufSize 8
|
#define RxBufSize 8
|
||||||
@ -136,6 +135,7 @@ volatile char TxCount;
|
|||||||
volatile char RxFlags;
|
volatile char RxFlags;
|
||||||
volatile char RxBufDiff;
|
volatile char RxBufDiff;
|
||||||
volatile char InChar;
|
volatile char InChar;
|
||||||
|
volatile char turnOffCounter = 0;
|
||||||
|
|
||||||
//start parsing serial data:
|
//start parsing serial data:
|
||||||
|
|
||||||
@ -166,6 +166,7 @@ volatile char Millis = 0;
|
|||||||
/* processor). When a character has been added, the "new data" flag is */
|
/* processor). When a character has been added, the "new data" flag is */
|
||||||
/* set to tell the interrupt routine to restart sending data. */
|
/* set to tell the interrupt routine to restart sending data. */
|
||||||
/* Note: data can be added to the buffer faster than the interrupt */
|
/* Note: data can be added to the buffer faster than the interrupt */
|
||||||
|
|
||||||
/* routine can transmit it */
|
/* routine can transmit it */
|
||||||
|
|
||||||
void SendChar(char c) {
|
void SendChar(char c) {
|
||||||
@ -227,8 +228,10 @@ void __interrupt()isr(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (turnOffCounter > 0 && !--turnOffCounter) {
|
||||||
|
GPIO &= 0xFD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Routine to receive asynchronous data from GPIO5
|
// Routine to receive asynchronous data from GPIO5
|
||||||
// credit: http://www.electro-tech-online.com/micro-controllers/18828-finding-serial-start-bit-bit-banging.html#post117227
|
// credit: http://www.electro-tech-online.com/micro-controllers/18828-finding-serial-start-bit-bit-banging.html#post117227
|
||||||
@ -356,28 +359,25 @@ void init(void) {
|
|||||||
OSCCONbits.IRCF2 = 1;
|
OSCCONbits.IRCF2 = 1;
|
||||||
TRISIObits.TRISIO5 = 1;
|
TRISIObits.TRISIO5 = 1;
|
||||||
TRISIObits.TRISIO4 = 0;
|
TRISIObits.TRISIO4 = 0;
|
||||||
TRISIObits.TRISIO1 = 1;
|
TRISIObits.TRISIO1 = 0;
|
||||||
TRISIObits.TRISIO0 = 1;
|
TRISIObits.TRISIO0 = 1;
|
||||||
WPUbits.WPU1 = 1;
|
|
||||||
WPUbits.WPU0 = 1;
|
WPUbits.WPU0 = 1;
|
||||||
ADCON0bits.ADON = 0;
|
ADCON0bits.ADON = 0;
|
||||||
ANSELbits.ANS0 = 0;
|
ANSELbits.ANS0 = 0;
|
||||||
ANSELbits.ANS1 = 0;
|
ANSELbits.ANS1 = 0;
|
||||||
ANSELbits.ANS2 = 0;
|
ANSELbits.ANS2 = 0;
|
||||||
ANSELbits.ANS3 = 0;
|
ANSELbits.ANS3 = 0;
|
||||||
|
GPIObits.GP1 = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int startSMS() {
|
void startSMS(const int flagBit) {
|
||||||
if (FlagC & (1 << 3)) {
|
if (FlagC & (1 << 3)) {
|
||||||
SendString("AT+CMGS=\"");
|
SendString("AT+CMGS=\"");
|
||||||
SendString(StringDial);
|
SendString(StringDial);
|
||||||
SendString("\"\n");
|
SendString("\"\n");
|
||||||
Flag3 |= (1 << 5);
|
Flag3 |= (1 << 5);
|
||||||
return 1;
|
Flag4 |= (1 << flagBit);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void processString(const char *string, volatile char *inputCharacter, const int flagBit) {
|
void processString(const char *string, volatile char *inputCharacter, const int flagBit) {
|
||||||
@ -388,6 +388,11 @@ void processString(const char *string, volatile char *inputCharacter, const int
|
|||||||
if (flagBit == 3) {
|
if (flagBit == 3) {
|
||||||
SendString("AT+CMGF=1\r\n");
|
SendString("AT+CMGF=1\r\n");
|
||||||
}
|
}
|
||||||
|
if (flagBit == 1) {
|
||||||
|
GPIO |= 0x02;
|
||||||
|
turnOffCounter = 100;
|
||||||
|
SendString("ATH\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (*inputCharacter != string[messagePointer]) {
|
if (*inputCharacter != string[messagePointer]) {
|
||||||
Flag2 &= ~(1 << flagBit);
|
Flag2 &= ~(1 << flagBit);
|
||||||
@ -398,9 +403,7 @@ void processString(const char *string, volatile char *inputCharacter, const int
|
|||||||
void handleGPIO(const int pin, const int flagBit) {
|
void handleGPIO(const int pin, const int flagBit) {
|
||||||
if (GPIOdeb & (1 << pin)) {
|
if (GPIOdeb & (1 << pin)) {
|
||||||
GPIOdeb &= ~(1 << pin);
|
GPIOdeb &= ~(1 << pin);
|
||||||
if(startSMS()){
|
startSMS(flagBit);
|
||||||
Flag4 |= (1 << flagBit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,11 +411,8 @@ void main(void) {
|
|||||||
init();
|
init();
|
||||||
SendChar('\n');
|
SendChar('\n');
|
||||||
while (1) {
|
while (1) {
|
||||||
|
handleGPIO(4, 0);
|
||||||
handleGPIO(6, 0);
|
handleGPIO(5, 1);
|
||||||
handleGPIO(7, 1);
|
|
||||||
handleGPIO(4, 2);
|
|
||||||
handleGPIO(5, 3);
|
|
||||||
|
|
||||||
if (RxIPtr != RxIPtr_old) {
|
if (RxIPtr != RxIPtr_old) {
|
||||||
if (RxIPtr < RxIPtr_old) {
|
if (RxIPtr < RxIPtr_old) {
|
||||||
@ -430,25 +430,15 @@ void main(void) {
|
|||||||
if (Flag3 & (1 << 5)) {
|
if (Flag3 & (1 << 5)) {
|
||||||
|
|
||||||
if (Flag4 & (1 << 0)) {
|
if (Flag4 & (1 << 0)) {
|
||||||
SendString("1 ON");
|
SendString("ON");
|
||||||
Flag4 &= ~(1 << 0);
|
Flag4 &= ~(1 << 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Flag4 & (1 << 1)) {
|
if (Flag4 & (1 << 1)) {
|
||||||
SendString("1 OFF");
|
SendString("OFF");
|
||||||
Flag4 &= ~(1 << 1);
|
Flag4 &= ~(1 << 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Flag4 & (1 << 2)) {
|
|
||||||
SendString("2 ON");
|
|
||||||
Flag4 &= ~(1 << 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Flag4 & (1 << 3)) {
|
|
||||||
SendString("2 OFF");
|
|
||||||
Flag4 &= ~(1 << 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
SendChar(26);
|
SendChar(26);
|
||||||
Flag3 &= ~(1 << 5);
|
Flag3 &= ~(1 << 5);
|
||||||
}
|
}
|
||||||
@ -456,7 +446,6 @@ void main(void) {
|
|||||||
|
|
||||||
processString(String1, &InChar, 0);
|
processString(String1, &InChar, 0);
|
||||||
processString(String2, &InChar, 1);
|
processString(String2, &InChar, 1);
|
||||||
processString(String3, &InChar, 2);
|
|
||||||
processString(String4, &InChar, 3);
|
processString(String4, &InChar, 3);
|
||||||
|
|
||||||
messagePointer++;
|
messagePointer++;
|
||||||
|
Loading…
Reference in New Issue
Block a user