Update Call
This commit is contained in:
parent
bcc466f985
commit
293060dac0
113
main.c
113
main.c
@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* File: main.c
|
* File: main.c
|
||||||
* Author: Bruno Rybársky
|
* Author: Bruno Rybársky
|
||||||
*
|
*
|
||||||
* Created on November 17, 2022, 12:49 PM
|
* Created on November 17, 2022, 12:49 PM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//PINS
|
//PINS
|
||||||
//GP0 - Button 1
|
//GP0 - Button 1
|
||||||
@ -104,20 +104,19 @@
|
|||||||
/* 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
|
||||||
volatile char TxBuf[TxBUF_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
volatile char TxBuf[TxBUF_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00};
|
||||||
#define TxBUF_MASK (TxBUF_SIZE-1)
|
#define TxBUF_MASK (TxBUF_SIZE-1)
|
||||||
volatile char RxBuf[RxBufSize];
|
volatile char RxBuf[RxBufSize];
|
||||||
volatile char RxIPtr;
|
volatile char RxIPtr;
|
||||||
@ -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,14 +166,15 @@ 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) {
|
||||||
GIE = 0; /* disable interrupts to avoid a race condition */
|
GIE = 0; /* disable interrupts to avoid a race condition */
|
||||||
TxBuf[TxOPtr++] = c;
|
TxBuf[TxOPtr++] = c;
|
||||||
TxOPtr = TxOPtr & TxBUF_MASK;
|
TxOPtr = TxOPtr & TxBUF_MASK;
|
||||||
TxFlags |= 0x80;
|
TxFlags |= 0x80;
|
||||||
GIE = 1; /* safe to restart them now */
|
GIE = 1; /* safe to restart them now */
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendString(const char *c) {
|
void SendString(const char *c) {
|
||||||
@ -205,7 +206,7 @@ void __interrupt()isr(void) {
|
|||||||
// Debouncing code sampling GPIO2 only runs when Millis overflows
|
// Debouncing code sampling GPIO2 only runs when Millis overflows
|
||||||
//if ((GPIOtemp & 0x0D) != (GPIO & 0x0D)) { // compare current input with last round
|
//if ((GPIOtemp & 0x0D) != (GPIO & 0x0D)) { // compare current input with last round
|
||||||
|
|
||||||
if ((GPIO & 0x03) != GPIOold){
|
if ((GPIO & 0x03) != GPIOold) {
|
||||||
GPIOtemp = (GPIO & 0x03) ^ GPIOold;
|
GPIOtemp = (GPIO & 0x03) ^ GPIOold;
|
||||||
GPIOold = GPIO & 0x03;
|
GPIOold = GPIO & 0x03;
|
||||||
// GPIO2 changed, perform debouncing
|
// GPIO2 changed, perform debouncing
|
||||||
@ -227,9 +228,11 @@ 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
|
||||||
asm("decfsz _RecSkips,F");
|
asm("decfsz _RecSkips,F");
|
||||||
@ -246,8 +249,8 @@ void __interrupt()isr(void) {
|
|||||||
asm("goto DoneRS232_Rx");
|
asm("goto DoneRS232_Rx");
|
||||||
asm("movf _InByte,W");
|
asm("movf _InByte,W");
|
||||||
asm("movwf _RxChar");
|
asm("movwf _RxChar");
|
||||||
asm("bsf _RxFlags,1"); // b_byte_available
|
asm("bsf _RxFlags,1"); // b_byte_available
|
||||||
asm("bcf _RxFlags,0"); // b_receiving
|
asm("bcf _RxFlags,0"); // b_receiving
|
||||||
RxBuf[RxIPtr++] = RxChar; /* write received byte to circular buffer */
|
RxBuf[RxIPtr++] = RxChar; /* write received byte to circular buffer */
|
||||||
RxIPtr = RxIPtr & 0x7;
|
RxIPtr = RxIPtr & 0x7;
|
||||||
asm("goto DoneRS232_Rx");
|
asm("goto DoneRS232_Rx");
|
||||||
@ -259,7 +262,7 @@ void __interrupt()isr(void) {
|
|||||||
asm("goto DoneRS232_Rx");
|
asm("goto DoneRS232_Rx");
|
||||||
asm("movlw 4");
|
asm("movlw 4");
|
||||||
asm("movwf _RecSkips");
|
asm("movwf _RecSkips");
|
||||||
asm("bsf _RxFlags,0"); // b_receiving
|
asm("bsf _RxFlags,0"); // b_receiving
|
||||||
asm("movlw 80h");
|
asm("movlw 80h");
|
||||||
asm("movwf _InByte");
|
asm("movwf _InByte");
|
||||||
asm("DoneRS232_Rx:");
|
asm("DoneRS232_Rx:");
|
||||||
@ -270,34 +273,34 @@ void __interrupt()isr(void) {
|
|||||||
// Here check if there is data being sent, or ready to send
|
// Here check if there is data being sent, or ready to send
|
||||||
asm("btfsc _TxFlags, 6"); /* already sending ?*/
|
asm("btfsc _TxFlags, 6"); /* already sending ?*/
|
||||||
asm("goto Tx_Sending");
|
asm("goto Tx_Sending");
|
||||||
asm("btfsc _TxFlags, 7"); // data to send
|
asm("btfsc _TxFlags, 7"); // data to send
|
||||||
asm("goto Tx_Start_Bit");
|
asm("goto Tx_Start_Bit");
|
||||||
asm("incf _TxSkips, F"); // set back to 1, so we retest next time round
|
asm("incf _TxSkips, F"); // set back to 1, so we retest next time round
|
||||||
asm("goto DoneRS232_Tx"); // nothing to do
|
asm("goto DoneRS232_Tx"); // nothing to do
|
||||||
|
|
||||||
// come here to start sending a new byte
|
// come here to start sending a new byte
|
||||||
asm("Tx_Start_Bit:");
|
asm("Tx_Start_Bit:");
|
||||||
asm("decfsz _TxSkips, f");
|
asm("decfsz _TxSkips, f");
|
||||||
asm("goto DoneRS232_Tx");
|
asm("goto DoneRS232_Tx");
|
||||||
asm("bcf GPIO, 4"); // hardware start bit
|
asm("bcf GPIO, 4"); // hardware start bit
|
||||||
|
|
||||||
TxChar = TxBuf[TxIPtr++];
|
TxChar = TxBuf[TxIPtr++];
|
||||||
TxIPtr = TxIPtr & TxBUF_MASK;
|
TxIPtr = TxIPtr & TxBUF_MASK;
|
||||||
|
|
||||||
TxFlags = 8; // initialise bit count, clear FULL flag
|
TxFlags = 8; // initialise bit count, clear FULL flag
|
||||||
asm("bsf _TxFlags, 6"); // indicate we are sending data
|
asm("bsf _TxFlags, 6"); // indicate we are sending data
|
||||||
TxSkips = 3;
|
TxSkips = 3;
|
||||||
asm("goto DoneRS232_Tx");
|
asm("goto DoneRS232_Tx");
|
||||||
|
|
||||||
//here if we are already in the process of sending data
|
//here if we are already in the process of sending data
|
||||||
asm("Tx_Sending:");
|
asm("Tx_Sending:");
|
||||||
asm("decfsz _TxSkips, F"); // only waggle o/p every third intr.
|
asm("decfsz _TxSkips, F"); // only waggle o/p every third intr.
|
||||||
asm("goto DoneRS232_Tx");
|
asm("goto DoneRS232_Tx");
|
||||||
|
|
||||||
asm("btfsc _TxFlags, 5"); // time to send stop bit?
|
asm("btfsc _TxFlags, 5"); // time to send stop bit?
|
||||||
asm("goto Tx_Stop_Bit");
|
asm("goto Tx_Stop_Bit");
|
||||||
|
|
||||||
asm("bcf STATUS, 0"); // carry bit
|
asm("bcf STATUS, 0"); // carry bit
|
||||||
asm("rrf _TxChar, f");
|
asm("rrf _TxChar, f");
|
||||||
asm("btfss STATUS, 0");
|
asm("btfss STATUS, 0");
|
||||||
asm("goto Tx_Set_Bit");
|
asm("goto Tx_Set_Bit");
|
||||||
@ -308,13 +311,13 @@ void __interrupt()isr(void) {
|
|||||||
// here we have sent the data bit, decrement the bit counter
|
// here we have sent the data bit, decrement the bit counter
|
||||||
asm("Tx_Sent_Bit:");
|
asm("Tx_Sent_Bit:");
|
||||||
asm("movlw 3");
|
asm("movlw 3");
|
||||||
asm("movwf _TxSkips"); // reset Tx skip counter for 3 more intrs
|
asm("movwf _TxSkips"); // reset Tx skip counter for 3 more intrs
|
||||||
asm("decf _TxFlags, F"); // bit count in lower 3 bits
|
asm("decf _TxFlags, F"); // bit count in lower 3 bits
|
||||||
asm("movf _TxFlags, W");
|
asm("movf _TxFlags, W");
|
||||||
asm("andlw 7");
|
asm("andlw 7");
|
||||||
asm("btfss STATUS, 2"); // if result is zero
|
asm("btfss STATUS, 2"); // if result is zero
|
||||||
asm("goto DoneRS232_Tx");
|
asm("goto DoneRS232_Tx");
|
||||||
asm("bsf _TxFlags, 5"); // all data sent, sent stop bit next time
|
asm("bsf _TxFlags, 5"); // all data sent, sent stop bit next time
|
||||||
asm("goto DoneRS232_Tx");
|
asm("goto DoneRS232_Tx");
|
||||||
|
|
||||||
// here to send the stop bit and check if there''s more data
|
// here to send the stop bit and check if there''s more data
|
||||||
@ -323,15 +326,15 @@ void __interrupt()isr(void) {
|
|||||||
asm("bsf GPIO, 4");
|
asm("bsf GPIO, 4");
|
||||||
asm("movlw 3");
|
asm("movlw 3");
|
||||||
asm("movwf _TxSkips");
|
asm("movwf _TxSkips");
|
||||||
asm("bcf _TxFlags, 6"); // sending_data flag
|
asm("bcf _TxFlags, 6"); // sending_data flag
|
||||||
asm("bcf _TxFlags, 5"); // send_stop_bit flag
|
asm("bcf _TxFlags, 5"); // send_stop_bit flag
|
||||||
TxCount = 1 + TxOPtr - TxIPtr;
|
TxCount = 1 + TxOPtr - TxIPtr;
|
||||||
asm("decfsz _TxCount, F"); // counter of number of chars still to send
|
asm("decfsz _TxCount, F"); // counter of number of chars still to send
|
||||||
asm("goto Tx_More");
|
asm("goto Tx_More");
|
||||||
asm("goto DoneRS232_Tx"); // all sent
|
asm("goto DoneRS232_Tx"); // all sent
|
||||||
|
|
||||||
asm("Tx_More:");
|
asm("Tx_More:");
|
||||||
asm("bsf _TxFlags, 7"); // signify more data to send
|
asm("bsf _TxFlags, 7"); // signify more data to send
|
||||||
|
|
||||||
asm("DoneRS232_Tx:");
|
asm("DoneRS232_Tx:");
|
||||||
|
|
||||||
@ -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