AddThis

Bookmark and Share

Tuesday, 20 July 2010

GSM SMS Controller Using Bluetooth Cellular Phone and BTSerial1

The project is a GSM SMS Controller without using any GSM modem. This is using the BTSerial1 module which wirelessly connects to a Bluetooth cellular phone to the PIC16LF876A’s serial port.

It accepts commands from an SMS incoming message and also respond via SMS on a read command request.

The valid SMS commands that are:

LED1 ON - turns ON LED1

LED1 OFF - turns OFF LED1

LED2 ON - turns ON LED2

LED2 OFF - turns OFF LED2

LED3 ON - turns ON LED3

LED3 OFF - turns OFF LED3

LED4 ON - turns ON LED4

LED4 OFF - turns OFF LED4

READ ADC - will respond back to the sender the current ADC reading

The project is using tthreads as its multitasking engine. And the SMS sending and receiving is using PDU mode for compatibility with more Bluetooth phones.

The following are excerpts from the full source code:

static void pack7(unsigned char bank2 *msg)

{

unsigned char i, h, c;

i=0;

h=0;

while(msg[i])

{

c = (msg[i+1] << (7-h)) | (msg[i] >> h);

bts1_putch(bin2bcd(c>>4));

bts1_putch(bin2bcd(c));

++h;

++i;

if (h==7)

{

h=0;

++i;

}

}

}

void bts1_interface_sms_recv(unsigned char c)

{

static unsigned char state = SMS_DECODE_START;

static unsigned char skip_chars = 0;

static unsigned char v, t, bits;

if (c==’r’ || c==’n’ || c==0)

{

if (state >= SMS_MESSAGE1)

{

sms_decoded(0);

}

state = SMS_DECODE_START;

skip_chars = 0;

return;

}

if (skip_chars)

{

–skip_chars;

return;

}

switch(state)

{

case SMS_DECODE_START:

v = bcd2bin(c);

v <<= 4;

++state;

break;

case SMS_GET_SMS_CENTER_LEN:

v += bcd2bin(c);

++state;

skip_chars = (v + 1) * 2;

break;

case SMS_GET_SENDER_LEN1:

send_buffer[0] = c;

v = bcd2bin(c);

v <<= 4;

++state;

break;

case SMS_GET_SENDER_LEN2:

send_buffer[1] = c;

v += bcd2bin(c);

if (v & 1)

++v;

v += 2;

send_buffer_len = 2;

++state;

break;

case SMS_GET_SENDER:

send_buffer[send_buffer_len] = c;

++send_buffer_len;

–v;

if (v==0)

{

send_buffer[send_buffer_len] = 0;

skip_chars = 20;

bits = 0;

v = 0;

t = 0;

++state;

}

break;

case SMS_MESSAGE1:

v = bcd2bin(c) <<>

++state;

break;

case SMS_MESSAGE2:

v += bcd2bin(c);

t += ((v & (bit_mask[7-bits]-1)) <<>

sms_decoded(t);

t = v >> (7-bits);

++bits;

if (bits>=7)

{

sms_decoded(t);

bits = 0;

t = 0;

}

–state;

break;

}

}

Download Project Zip with Source Code

0 comments:

Post a Comment