Complete program which was develop by my sister's friend.
#include <16f877a.h> //use pic16f877a pic
#device adc=8 //use 8 bit adc
#use delay(clock=20000000) //speed 20mhz
#fuses hs, noprotect, nowdt, nolvp //default setting
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,PARITY=N)//gsm setting
#define use_portb_lcd TRUE //use portb for lcd
#include <lcd.c> //call lcd.c library
//pic port address
#byte porta=5
#byte portb=6
#byte portc=7
#byte portd=8
#byte porte=9
void main()
{
int ir_in;
int sms_mod=1;
int ir_en=1;
long int sp=3;
long int count=0;
int c0_sta=1;
int c1_sta=1;
int c2_sta=1;
//set i/o pin for pic
set_tris_a(0b00000001);
set_tris_b(0b00000000);
set_tris_c(0b10000111);
set_tris_d(0b00000000);
set_tris_e(0b00000000);
setup_port_a(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
//initialize lcd
lcd_init();
lcd_putc("\fAutomatic");
lcd_putc("\nMailbox");
output_high(pin_d6); //on buzzer
output_high(pin_a1); //on red led
output_high(pin_a2); //on green led
delay_ms(1000);
output_low(pin_d6); //off buzzer
delay_ms(20000);
//send sms out to annouce system started
printf("AT+CMGF=1\r");
delay_ms(1000);
printf("AT+CMGD=1\r");
delay_ms(1000);
printf("AT+CMGF=1\r");
delay_ms(1000);
printf("AT+CMGD=1\r");
delay_ms(1000);
printf("AT+CMGS=");
putc(0x22);
printf("+60179272562");
putc(0x22);
putc(0x0D);
delay_ms(500);
printf("Automatic Mailbox Started");
putc(0x1A);
delay_ms(2000);
printf("AT+CMGD=1\r");
delay_ms(1000);
output_low(pin_a1); //off red led
output_high(pin_a2); //on green led
do
{
//read ir sensor
ir_in=read_adc();
if(ir_in>=90 && ir_en==1) //if letter detected
{
count=count+1; //up count counter
if(count>=sp) //if letter full
{
if(sms_mod==1) //if sms mode activated
{
//send sms out to annouce system started
printf("AT+CMGS=");
putc(0x22);
printf("+60179272562");
putc(0x22);
putc(0x0D);
delay_ms(500);
printf("Total letter:%03lu",count);
putc(0x1A);
delay_ms(2000);
printf("AT+CMGD=1\r");
delay_ms(1000);
}
}
else
{
output_low(pin_d6); //off buzzer
}
ir_en=0;
}
else if(ir_in<100)
{
ir_en=1;
}
if(input(pin_c0)==0 && c0_sta==1) //if upcount button pressed
{
if(sp<1000) //up count sp
{
sp=sp+1;
}
else
{
sp=0;
}
c0_sta=0;
}
else if(input(pin_c0)==1) //if upcount button released
{
c0_sta=1;
}
if(input(pin_c1)==0 && c1_sta==1) //if down count button pressed
{
if(sp>0) //down count sp
{
sp=sp-1;
}
else
{
sp=0;
}
c1_sta=0;
}
else if(input(pin_c1)==1) //if down button released
{
c1_sta=1;
}
if(input(pin_c2)==0 && c2_sta==1) //if change mode button pressed
{
if(sms_mod==0) //toggle mode
{
sms_mod=1;
}
else
{
sms_mod=0;
}
c2_sta=0;
}
else if(input(pin_c2)==1) //if down button released
{
c2_sta=1;
}
if(sms_mod==1) //if sms mode activated
{
output_low(pin_d6); //off buzzer
}
else //if sms mode not activated
{
if(count<sp) //if not reached set point
{
output_low(pin_d6); //off buzzer
}
else
{
output_high(pin_d6); //on buzzer
}
}
if(count>=sp)//if set point reached
{
output_high(pin_a1); //on red led
output_low(pin_a2); //off green led
}
else
{
output_low(pin_a1); //off red led
output_high(pin_a2); //on green led
}
printf(lcd_putc,"\fTot Letter:%03lu",count);
printf(lcd_putc,"\nSP:%03lu SMS:%u",sp, sms_mod);
delay_ms(250);
}while(1);
}