Update Call
This commit is contained in:
parent
bcc466f985
commit
293060dac0
65
main.c
65
main.c
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* File: main.c
|
||||
* Author: Bruno Rybársky
|
||||
*
|
||||
* Created on November 17, 2022, 12:49 PM
|
||||
*/
|
||||
* File: main.c
|
||||
* Author: Bruno Rybársky
|
||||
*
|
||||
* Created on November 17, 2022, 12:49 PM
|
||||
*/
|
||||
|
||||
//PINS
|
||||
//GP0 - Button 1
|
||||
@ -104,14 +104,13 @@
|
||||
/* These are the definitions */
|
||||
|
||||
const char String1[3] = "OK"; //ok response
|
||||
const char String2[11] = "NO CARRIER"; //call state change
|
||||
const char String3[6] = "ERROR"; //ok response
|
||||
const char String2[27] = "+CLIP: \"+421905708125\",145"; //call state change
|
||||
const char String4[10] = "SMS Ready"; //modem startup
|
||||
|
||||
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-128) /* trial and error value, comes to 3603 Baud */
|
||||
|
||||
#define TxBUF_SIZE 32
|
||||
#define RxBufSize 8
|
||||
@ -136,6 +135,7 @@ volatile char TxCount;
|
||||
volatile char RxFlags;
|
||||
volatile char RxBufDiff;
|
||||
volatile char InChar;
|
||||
volatile char turnOffCounter = 0;
|
||||
|
||||
//start parsing serial data:
|
||||
|
||||
@ -166,6 +166,7 @@ volatile char Millis = 0;
|
||||
/* processor). When a character has been added, the "new data" flag is */
|
||||
/* set to tell the interrupt routine to restart sending data. */
|
||||
/* Note: data can be added to the buffer faster than the interrupt */
|
||||
|
||||
/* routine can transmit it */
|
||||
|
||||
void SendChar(char c) {
|
||||
@ -205,7 +206,7 @@ void __interrupt()isr(void) {
|
||||
// Debouncing code sampling GPIO2 only runs when Millis overflows
|
||||
//if ((GPIOtemp & 0x0D) != (GPIO & 0x0D)) { // compare current input with last round
|
||||
|
||||
if ((GPIO & 0x03) != GPIOold){
|
||||
if ((GPIO & 0x03) != GPIOold) {
|
||||
GPIOtemp = (GPIO & 0x03) ^ GPIOold;
|
||||
GPIOold = GPIO & 0x03;
|
||||
// GPIO2 changed, perform debouncing
|
||||
@ -227,8 +228,10 @@ void __interrupt()isr(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (turnOffCounter > 0 && !--turnOffCounter) {
|
||||
GPIO &= 0xFD;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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
|
||||
@ -356,28 +359,25 @@ void init(void) {
|
||||
OSCCONbits.IRCF2 = 1;
|
||||
TRISIObits.TRISIO5 = 1;
|
||||
TRISIObits.TRISIO4 = 0;
|
||||
TRISIObits.TRISIO1 = 1;
|
||||
TRISIObits.TRISIO1 = 0;
|
||||
TRISIObits.TRISIO0 = 1;
|
||||
WPUbits.WPU1 = 1;
|
||||
WPUbits.WPU0 = 1;
|
||||
ADCON0bits.ADON = 0;
|
||||
ANSELbits.ANS0 = 0;
|
||||
ANSELbits.ANS1 = 0;
|
||||
ANSELbits.ANS2 = 0;
|
||||
ANSELbits.ANS3 = 0;
|
||||
|
||||
|
||||
GPIObits.GP1 = 0;
|
||||
}
|
||||
|
||||
int startSMS() {
|
||||
void startSMS(const int flagBit) {
|
||||
if (FlagC & (1 << 3)) {
|
||||
SendString("AT+CMGS=\"");
|
||||
SendString(StringDial);
|
||||
SendString("\"\n");
|
||||
Flag3 |= (1 << 5);
|
||||
return 1;
|
||||
Flag4 |= (1 << flagBit);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
SendString("AT+CMGF=1\r\n");
|
||||
}
|
||||
if (flagBit == 1) {
|
||||
GPIO |= 0x02;
|
||||
turnOffCounter = 100;
|
||||
SendString("ATH\n");
|
||||
}
|
||||
}
|
||||
if (*inputCharacter != string[messagePointer]) {
|
||||
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) {
|
||||
if (GPIOdeb & (1 << pin)) {
|
||||
GPIOdeb &= ~(1 << pin);
|
||||
if(startSMS()){
|
||||
Flag4 |= (1 << flagBit);
|
||||
}
|
||||
startSMS(flagBit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -408,11 +411,8 @@ void main(void) {
|
||||
init();
|
||||
SendChar('\n');
|
||||
while (1) {
|
||||
|
||||
handleGPIO(6, 0);
|
||||
handleGPIO(7, 1);
|
||||
handleGPIO(4, 2);
|
||||
handleGPIO(5, 3);
|
||||
handleGPIO(4, 0);
|
||||
handleGPIO(5, 1);
|
||||
|
||||
if (RxIPtr != RxIPtr_old) {
|
||||
if (RxIPtr < RxIPtr_old) {
|
||||
@ -430,25 +430,15 @@ void main(void) {
|
||||
if (Flag3 & (1 << 5)) {
|
||||
|
||||
if (Flag4 & (1 << 0)) {
|
||||
SendString("1 ON");
|
||||
SendString("ON");
|
||||
Flag4 &= ~(1 << 0);
|
||||
}
|
||||
|
||||
if (Flag4 & (1 << 1)) {
|
||||
SendString("1 OFF");
|
||||
SendString("OFF");
|
||||
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);
|
||||
Flag3 &= ~(1 << 5);
|
||||
}
|
||||
@ -456,7 +446,6 @@ void main(void) {
|
||||
|
||||
processString(String1, &InChar, 0);
|
||||
processString(String2, &InChar, 1);
|
||||
processString(String3, &InChar, 2);
|
||||
processString(String4, &InChar, 3);
|
||||
|
||||
messagePointer++;
|
||||
|
Loading…
Reference in New Issue
Block a user