Sunday, 12 October 2014
Dialler working...
The dialler now works, I have hooked up the rotary dial unit from the GPO phone to the circuit and all numbers are decoded correctly (most of the time) and sent to the RS232 port.
I am waiting for a RS232 - RS232 cable to send the AT command straight to the GSM module.
I had problems with switch bounce from the rotary, but this is almost eliminated with the introduction of 10ms delays after the port on the PIC is read.
The code so far:
#include "C:\Users\Daddy\Documents\CCS\push_button.h"
#include <stdio.h>
#use delay(clock=8000000) // 8MHz
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5,bits=8)
void getNumber();
void checkOnHook(void);
void main(void)
{
printf("::main()\n\r");
// set stuff up
setup_adc_ports (NO_ANALOGS|VSS_VDD);
setup_adc (ADC_OFF);
setup_spi (FALSE);
setup_oscillator(OSC_8MHz);
// This is the main loop
while(true) {
checkOnHook(); // this will wait for an incomming call
getNumber(); // gets number from rotary and sends AT command
}
}
// Checks if the phone is on the hook via A1
void checkOnHook(void) {
BYTE flag=0;
printf("::checkOnHook()\n\r");
// RA1 the ON/OFF Hook detection
while(input(PIN_A1)){
// waiting for an incoming call
if(flag==0) {
printf("waiting for an incomming call!\n\r");
flag=1;
}
}
return;
}
// This function returns a char array that is the AT command
void getNumber() {
int16 x = 0;
int16 count = 0; // button press count
int32 timer; // This is the timer
BYTE status; // This if for detecting button state
char phoneNum[15] = ""; // A character array for the phone number
char num[3] = "AT"; // start of the dial string
strcat(phoneNum,num); // cp the start of the dial string to the phone num AT command
printf("::getNumber\n\r");
// do this while the phone is still off the hook
while (!input(PIN_A1)) {
if (!input (PIN_A0) && status == 0) //input button
{
status = 1;
delay_ms (10);
output_low(PIN_C3);
count++; }
if (input (PIN_A0))
{
delay_ms(10); // debounce?
output_high(PIN_C3);
status = 0;
timer = 0; //reset timer after a pulse has been received
}
// short delay for individual numbers
if (timer > 40000 && count > 0)
{
x++; // increment the index by one
count--;
if(count > 9)
count=0;
sprintf(num,"%ld",count); // makes count into a string
printf("count = %ld, %s\n\r",count,num);
strcat(phoneNum,num); // adds num to the phoneNumber
printf(">%s\n\r",phoneNum);
timer = 0;
count = 0; // reset the counter
}
// long delay before returning the AT command
if( timer > 100000 && x > 0 ) {
timer=0;
x=0;
count=0;
printf("%s;\n\r",phoneNum);
while(!input(PIN_A1)); // wait for on hook.
return;
}
timer++;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment