Sunday 16 September 2012

WEEK 30 - WEEK 32

Objectives:
  • Programming for the GSM
Content:
  • For make the programming for GSM can interface with the hardware from the sending message from mobile phone.
#define PUSH_BUTTON
#define ADC
#define UART
#define I2C
#define HD44780
#define GSM_MODEM
#define PULSE 9000
#define SEL RC0

#include <htc.h>
#include "LibraryHardware.h"
#include "LibraryPeripheral.h"
#include "LibraryUniversalDisplay.h"
#include "LibraryAtCommand.h"
#include "LibraryDS1307.h"

void pic_init(void);
char read_button(void);
char sms(void);

unsigned int counter[3];

__EEPROM_DATA('0','1','3','6','2','8','9','8');
__EEPROM_DATA('4','4',1,1,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);

static void interrupt isr(void)
{
if(RCIF==1){
counter[0]=0;
get_phone_message();}
if(TMR0IF==1){
TMR0IF=0;
reset_yz();
if(counter[0]<PULSE) counter[0]++;
else counter[0]=0;
}
}

main()
{
unsigned char button,temp,disp=0,mode=0;
unsigned char set=0,mo[12]={31,28,31,30,31,30,31,31,30,31,30,31};
unsigned char sec,min,hrs,date,month,year,time[2];
int i,j,voltage,current;
pic_init(); //initialize PIC
uart_init(9600);         //initialize UART
i2c_init(10); //initialize I2C
lcd_init(); //initialize LCD
phone[0]='+';
phone[1]='6';
for(i=0;i<=9;i++) phone[i+2]=eeprom_read(i);
phone[12]=0xFF;
for(i=0;i<=1;i++) time[i]=eeprom_read(i+10);
case 2:{
lcd_goto(0,0);
lcd_string("    PHONE NUMBER    ");            // LCD will be display "PHONE NUMBER"
lcd_goto(0,1);
lcd_string("     ");
for(i=0;i<=9;i++){
if(((i+1)==set)&(counter[0]<PULSE/2)) lcd_string(" "); // Set the Phone number
else lcd_write(phone[i+2]);}
lcd_string("     ");

switch(button){
case 1:{
mode++;
set=0;
delay(200);
break;}
case 2:{
if(set<10) set++;
else set=0;
delay(200);
break;}
case 4:{
if(phone[set+1]<'9') phone[set+1]++;
else phone[set+1]='0';
eeprom_write(set-1,phone[set+1]);
delay(200);
break;}
case 8:{
if(phone[set+1]>'0') phone[set+1]--;
else phone[set+1]='9';
eeprom_write(set-1,phone[set+1]);
delay(200);
break;}
}
break;}

case 3:{
lcd_goto(0,0);
lcd_string("     SEND TIME      ");  // LCD will be display "  SEND TIME "
lcd_goto(0,1);
lcd_string("       ");
if((set==1)&(counter[0]<PULSE/2)) lcd_string("  ");
else lcd_number(time[0],10,2);
lcd_string(":");
if((set==2)&(counter[0]<PULSE/2)) lcd_string("  ");
else lcd_number(time[1],10,2);
lcd_string("        ");

switch(button){
case 1:{
mode++;
set=0;
delay(200);
break;}
case 2:{
if(set<2) set++;
else set=0;
delay(200);
break;}
case 4:{
if(set==1){
if(time[0]<23) time[0]++;
else time[0]=0;
eeprom_write(10,time[0]);}
if(set==2){
if(time[1]<59) time[1]++;
else time[1]=0;
eeprom_write(11,time[1]);}
delay(200);
break;}
case 8:{
if(set==1){
if(time[0]>0) time[0]--;
else time[0]=23;
eeprom_write(10,time[0]);}
if(set==2){
if(time[1]>0) time[1]--;
else time[1]=59;
eeprom_write(11,time[1]);}
delay(200);
break;}
}
break;}

case 5:{
counter[1]=0;
LCD_LIGHT=1;
lcd_goto(0,0);
lcd_string("      MESSAGE       ");  // LCD will be display "   MESSAGE   "
lcd_goto(0,1);
lcd_string("      RECEIVE       "); // LCD will be display "   RECEIVE  "

text_mode();
sms_read(1,1);
temp=sms();
sms_delete(1);

switch(temp){
case 1:{
sms_send();
uart_string("Voc(hrs:V)");
uart_transmit(0x0D);           //Enter
for(j=hrs;j>=0;j--){
uart_number(j,10,2);
uart_string(":");
voltage=256*eeprom_read(16+2*j)+eeprom_read(17+2*j);
uart_number(voltage/100,10,2);
uart_transmit(0x0D);  //Enter
}

for(j=23;j>hrs;j--){
uart_number(j,10,2);
uart_string(":");
voltage=256*eeprom_read(16+2*j)+eeprom_read(17+2*j);
uart_number(voltage/100,10,2);
uart_transmit(0x0D); //Enter
}

uart_transmit(0x1A); //Ctrl+Z
break;}

case 2:{
sms_send();
uart_string("Isc(hrs:mA)");
uart_transmit(0x0D); //Enter
for(j=hrs;j>=0;j--){
uart_number(j,10,2);
uart_string(":");
current=256*eeprom_read(64+2*j)+eeprom_read(65+2*j);
uart_number(current,10,2);
uart_transmit(0x0D); //Enter
}
for(j=23;j>hrs;j--){
uart_number(j,10,2);
uart_string(":");
current=256*eeprom_read(64+2*j)+eeprom_read(65+2*j);
uart_number(current,10,2);
uart_transmit(0x0D); //Enter
}
uart_transmit(0x1A); //Ctrl+Z
break;}

default:{
sms_send();
uart_string("Unrecognized Code");
uart_transmit(0x1A); //Ctrl+Z
break;}
}
mode=0;
delay(1000);
break;}

case 6: case 7:{
counter[1]=0;
LCD_LIGHT=1;
lcd_goto(0,0);
lcd_string("      SENDING       ");
lcd_goto(0,1);
lcd_string("      MESSAGE       ");

text_mode();

if(mode==6){
sms_send();
uart_string("Voc(hrs:V)");
uart_transmit(0x0D); //Enter
for(j=hrs;j>=0;j--){
uart_number(j,10,2);
uart_string(":");
voltage=256*eeprom_read(16+2*j)+eeprom_read(17+2*j);
uart_number(voltage/100,10,2);
uart_transmit(0x0D); //Enter
}
for(j=23;j>hrs;j--){
uart_number(j,10,2);
uart_string(":");
voltage=256*eeprom_read(16+2*j)+eeprom_read(17+2*j);
uart_number(voltage/100,10,2);
uart_transmit(0x0D); //Enter
}
uart_transmit(0x1A); //Ctrl+Z
}
if(mode==7){
sms_send();
uart_string("Isc(hrs:mA)");
uart_transmit(0x0D); //Enter
for(j=hrs;j>=0;j--){
uart_number(j,10,2);
uart_string(":");
current=256*eeprom_read(64+2*j)+eeprom_read(65+2*j);
uart_number(current,10,2);
uart_transmit(0x0D); //Enter
}
for(j=23;j>hrs;j--){
uart_number(j,10,2);
uart_string(":");
current=256*eeprom_read(64+2*j)+eeprom_read(65+2*j);
uart_number(current,10,2);
uart_transmit(0x0D); //Enter
}
uart_transmit(0x1A); //Ctrl+Z
}
for(i=0;i<=9;i++) phone[i+2]=eeprom_read(i);
delay(1000);
mode=0;
break;}

default:{
mode=0;
break;}
}
}
}

void pic_init(void)
{
TRISA=0b00000011;
TRISB=0b11110000;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;
ANSEL=0b00000000;
ANSELH=0b00000000;
OPTION_REG=0b00001000;
INTCON=0b11100000; //Enable Global, TMR0 Interrupt
PIE1=0b00100000;         //Enable RX interrupt
PORTA=0b00000001;
PORTB=0b00000000;
PORTC=0b00000000;
PORTD=0b00000000;
PORTE=0b00000000;
}

char read_button(void)
{char i=0;
if(PB1==0) i=i+8;
if(PB2==0) i=i+4;
if(PB3==0) i=i+2;
if(PB4==0) i=i+1;
if(i>0){
counter[2]=0;
LCD_LIGHT=1;}
return i;
}

char sms(void)
{
char i,j=0;

Result and Analysis

The programming for the gsm and hardware not successful for interfacing. The data from hardware can be send to mobile phone, but from the mobile phone send the message to gsm for asking the parameter solar cannot be reply from hardware.

Conclusion:
As a conclusion, i think hardware cannot read for asking from the mobile phone or programming conflict for the programming send to mobile phone. i will find out what the problem in this case as soon as possible.

No comments:

Post a Comment