Wednesday, 3 October 2012

WEEK 33


Objectives:
  • Re-Programming for the GSM for find out the problem
Content:
  • For make the programming for GSM can interface with the hardware from the sending message from mobile phone correctly.
#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;


i=0;
if((message[0]=='V')|(message[0]=='v')) i++;
if((message[1]=='O')|(message[1]=='o')) i++;
if((message[2]=='L')|(message[2]=='l')) i++;
if((message[3]=='T')|(message[3]=='t')) i++;
if((message[4]=='A')|(message[4]=='a')) i++;
if((message[5]=='G')|(message[5]=='g')) i++;
if((message[6]=='E')|(message[6]=='e')) i++;
if(i==7) j=1;

i=0;
if((message[0]=='C')|(message[0]=='c')) i++;
if((message[1]=='U')|(message[1]=='u')) i++;
if((message[2]=='R')|(message[2]=='r')) i++;
if((message[3]=='R')|(message[3]=='r')) i++;
if((message[4]=='E')|(message[4]=='e')) i++;
if((message[5]=='N')|(message[5]=='n')) i++;
if((message[6]=='T')|(message[6]=='t')) i++;
if(i==7) j=2;

return j;
}

Result and Analysis

The programming for the gsm and hardware is successful for interfacing. The data or result from solar hardware can be send to the mobile phone via gsm on 7.00pm for average voltage and current result automatically. This program also can send the result manually with sending the message to the gsm "voltage" for voltage result and "current" for current result in every time. This programm will be reply for each message to the mobile phone.

Conclusion:
As a conclusion, this program is successfully and can interfacing with the solar hardware. I know how to learn programming for two way communication using gsm to the mobile phone or otherwise. For next step, i will make the design for the poster.

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.

Sunday, 26 August 2012

WEEK 26 - WEEK 29

Objective:

  • Program for the push button for set the time

Contents:
  • Make a programming for push button to select the time 
  • Load to PIC16F887 


 switch(mode){
 case 0: case 1:{
  lcd_goto(0,0);                  //select first line in LCD // will show at first line LCD
  lcd_string("Time     : ");
  if((set==1)&(counter[0]<PULSE/2)) lcd_string("  ");
  else lcd_number(hrs,10,2);
  lcd_string(":");
  if((set==2)&(counter[0]<PULSE/2)) lcd_string("  ");
  else lcd_number(min,10,2);
  lcd_string(":");
  if((set==3)&(counter[0]<PULSE/2)) lcd_string("  ");
  else  lcd_number(sec,10,2);
  lcd_string(" ");

  lcd_goto(0,1);              //select second line in LCD // will show at second line LCD
  lcd_string("Date     : ");
  if((set==4)&(counter[0]<PULSE/2)) lcd_string("  ");
  else  lcd_number(date,10,2);
  lcd_string("/");
  if((set==5)&(counter[0]<PULSE/2)) lcd_string("  ");
  else  lcd_number(month,10,2);
  lcd_string("/");
  if((set==6)&(counter[0]<PULSE/2)) lcd_string("  ");
  else   lcd_number(year,10,2);
  lcd_string(" ");

  if(mode==0){
   if(button==3){
    set=1;
    mode++;
    delay(200);}}
  else if(mode==1){
   switch(button){

                         case 1:{
                             mode++;
                             set=0;
                             delay(200);
                             break;}

                             case 2:{
if(set<6) set++;
else set=1;
delay(200);
break;}

case 4:{
switch(set){
case 1:{
if(hrs<23) hrs++;
else hrs=0;
rtc_set(2,hrs);               //set hours
break;}

case 2:{
if(min<59) min++;
else min=0;
rtc_set(1,min);           //set min
break;}

case 3:{
sec=0;
rtc_set(0,sec);           //set sec
break;}

case 4:{
if(date<mo[month-1]) date++;
else date=1;
rtc_set(4,date);                       //set date
break;}

case 5:{
if(month<12) month++;
else month=1;
rtc_set(5,month);               //set month
break;}

case 6:{
if(year<99) year++;
else year=0;
rtc_set(6,year);                  //set year
break;}
}
delay(200);
break;}

case 8:{
switch(set){

case 1:{
if(hrs>0) hrs--;
else hrs=23;
rtc_set(2,hrs);              //set hours
break;}

case 2:{
if(min>0) min--;
else min=59;
rtc_set(1,min);         //set min
break;}

case 3:{
sec=0;
rtc_set(0,sec); //set sec
break;}

case 4:{
if(date>1) date--;
else date=mo[month-1];
rtc_set(4,date);              //set date
break;}

case 5:{
if(month>1) month--;
else month=12;
rtc_set(5,month);                //set month
break;}

case 6:{
if(year>0) year--;
else year=99;
rtc_set(6,year);                     //set year
break;}
}
delay(200);
break;}
}
}
break;}

Conclusion:
              The programming for the push button has been successful to load into PIC. For next step, i will programming for the GSM.
  

Saturday, 4 August 2012

Week 23- Week 25

Objectives: 

  • Start to programming for LCD string
  • To show output in LCD


Contents: 

  • For make sure this programming suitable in LCD 4x16



//Project: GSM Solar Monitoring
//Programmer:Khairul Hasnadi Mohmad
//PIC: PIC16F887
//Crystal Frequency: 20MHz
//Compiler: HI-TECH ANSI C V9.83
//Last Modified: 14 August 2012
//Website: http://hasnady.blogspot.com

#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');                     //memory data can save 256 Byte
__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){                                                                     // Receive message 
counter[0]=0;
get_phone_message();}
if(TMR0IF==1){                                                                // Time Receive message 
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);

lcd_goto(0,0); //select first line
lcd_string("     GSM MODEM      ");                          // Show the " GSM MODEM" in first line
while(gsm_ready()==0) continue;
lcd_goto(0,1); //select second line
lcd_string("       READY        ");                                                 // Show "READY" in second line
sms_delete(1);
delay(1000);

#if defined (PCD8544)
/* initialise the GLCD */                                                         //we use the LCD 4x16
void glcd_init(void)
{
GLCD_RST=1;                                                                      // graphical LCD
__delay_ms(15);
glcd_write(0x21); //function set
glcd_write(0xC0); //set Vlcd
glcd_write(0x13); //set Bias System
glcd_write(0x20); //function set
glcd_write(0x0C); //sets display configuration
}

/* write serial byte to the GLCD */
void glcd_write(unsigned char c)
{int i;
GLCD_CS=0;
for(i=0;i<=7;i++){
GLCD_SDA=(c>>(7-i))&1;
GLCD_SCLK=0;
GLCD_SCLK=1;}
GLCD_CS=1;
}

/* go to the specified x&y location */
void glcd_goto(char x, char y)
{
GLCD_DC=0;
glcd_write(0x80+x);
glcd_write(0x40+y);
GLCD_DC=1;
}

/* write a character to the LCD */
void glcd_char(char c)
{int i;
if((c<32)|(c>127)) c=' ';
for(i=0;i<5;i++) glcd_write(FontLookup[c-32][i]);
glcd_write(0x00);
}

/* write a string of chars to the GLCD */
void glcd_string(const char *s)
{
GLCD_DC=1;
while(*s)
glcd_char(*s++);
}

void glcd_number(unsigned int no, char base, char digit)
{char i,j,di[10];
for(i=0;i<=9;i++) di[i]=0;
i=0;
do{
di[i]=no%base;
no=no/base;
i=i+1;}
while(no!=0);
for(j=digit;j>0;j--){
if(di[j-1]<=9) glcd_char(di[j-1]+'0');
else glcd_char(di[j-1]-10+'A');}
}
#endif

Result&Analysis



  • Programming successful for LCD screen 2X16 when the compiler in mp lab not detect another problem in the programming.

Conclusion
  • As a conclusion, i know how to program of the LCD screen in PIC 16F887. For next step, i need to program for the push button for select the time.


Saturday, 7 July 2012

Week 19 - Week 22

Objectives: How to use Proteus 7





 Standart View


Find the component


 Design the circuit(Counter circuit)


 Find the Program


 Put the Program


Click button play for successful or not