Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help me check the source code pls...

Status
Not open for further replies.

jackson0215

Newbie level 4
Joined
Jan 8, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,391
thats is some problem when i compile this source code,can anyone of u help me check what is the problem and help me edit it?

#include <16F877A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //High speed Osc (> 4mhz)
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOPUT //No Power Up Timer
#FUSES DEBUG

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=GSM )
#use rs232(baud=1200,parity=N,xmit=PIN_C1,INVERT,rcv=PIN_E2,bits=8,stream=IRS1) // First IR Sensor
#use rs232(baud=1200,parity=N,xmit=PIN_C1,INVERT,rcv=PIN_D7,bits=8,stream=IRS2) // Second IR Sensor

#define LCD_DB4 PIN_C0 //LCD Data Pins
#define LCD_DB5 PIN_C1
#define LCD_DB6 PIN_C2
#define LCD_DB7 PIN_C3

#define LCD_E PIN_D1 //LCD Enable Pin
#define LCD_RS PIN_D0 //LCD RS Pin

#define IRLED PIN_E0
#define PIRLED PIN_D6
#define MEGLED PIN_D5
#define SMOKELED PIN_D4

#define PIRSENSOR PIN_A0
#define MEGSENSOR PIN_A3
#define SMOKESENSOR PIN_A2

#include "flex_lcd.c" //LCD Driver

#include <kbd1.c> //Keypad Driver

#include <stdlib.h> //Standard Libraries
#include <string.h> //

#define Buzzer PIN_E1 // Buzzer attached on pin 9
#define Sen 100 // IR Sensor Sensitivity i.e.
//greater the value.. lesser the sensitivity and vice versa

int sendSMS(void); // Method to send sms alert through T230 Mobile Phone
void checkSensors(); // IR Sensor Scanning through rs232
int waitResponse(unsigned int16); // AT Command Response Method

int1 timeoutFlg=0,SysActivated=0; // Tags and Flags
INT8 AlertFlg=0;
char buf[60]; // String buffer to recieve response string from mobile phone
char dtstr[60]={"ALERT!! SOMEBODY BREAKING INTO YOUR HOUSE.\0"}; // Aler message to be sent through sms
char sOK[] = {"OK"}; // Response Strings from Mobile phone
char sER[] = {"ERROR"};
char sSen[] = {"CMS ERROR"};
char nServer[] = {"00923014217397\0"}; // Receipent Cell Number
char password[]={"333\0"}; // Password entered throgh keypad
long timeout,timeout2,INDEX; // Time processing variables and General Index veriable




void main()
{
unsigned int c,c2;
int i;
char k,pass[]={"***\0"};
setup_adc_ports (No_ANALOGS); // All Ios are in digital mode
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);

lcd_init(); // Lcd Initialization
kbd_init(); // Keypad Initialization
lcd_gotoxy(1,1); // Startup string message on LCD for 1 second
lcd_putc("\fStart-Up");
delay_ms(1000);



while(1){
lcd_putc("\fSystem De-Activated"); // System needs 3 digit password in start to activate
lcd_gotoxy(8,2);
i=0;
AlertFlg=0;
timeout2=0;
output_low(pin_a1);
k=0;
output_high(PIN_A1); // LED to tell that system has powerd up and ready
AlertFlg=0;

while(!sysActivated){ // While untill system is not activated through password input
k=kbd_getc(); // Scan Keypad
if(k!=0){ // If some button is pressed
delay_ms(50); // De-Bounce Time
lcd_putc('*'); // Print astarick on lcd
pass=k; // Populate array index
i++;
}
if(i>=3){ // If keypad buttons are pressed three times
if(pass[0]==password[0] && pass[1]==password[1] && pass[2]==password[2] ){ // Check the password in three digits
lcd_putc("\f[Password OK]"); // If password matches
pass[0]=0;
pass[1]=0;
pass[2]=0;
lcd_gotoxy(2,2);
lcd_putc("System Activated"); // Activate system
output_Low(IRLED);
output_Low(PIRLED);
output_Low(MEGLED);
output_Low(SMOKELED);
delay_ms(2000);
SysActivated=1; // System Activation Flag
}else{
lcd_putc("\f [Access Denied]"); // If Password is worng then
delay_ms(2000);
lcd_putc("\fSystem De-Activated"); // System Still deactivated
lcd_gotoxy(8,2);
sysActivated=0;
i=0;
}
}
}



//If password was ok then start Scanning Sensors
lcd_putc("\f Scanning...."); // clear screen
while(1)
{
checkSensors(); // Scan sensor in a loop
if(AlertFlg>0) // If intrustion is there Stop Scanning
{break;}
}

lcd_putc("\f"); // clear screen
output_high(buzzer); // Alarm On
If(AlertFlg==1){
lcd_putc("\f*IR-Detection MSG*"); // clear screen & Intrusion detection message stays
output_high(IRLED);
}Else If(AlertFlg==2){
lcd_putc("\f*PIR-Detection MSG*"); // clear screen & Intrusion detection message stays
output_high(PIRLED);
}Else If(AlertFlg==3){
lcd_putc("\f*MEG Detection MSG*"); // clear screen & Intrusion detection message stays
output_high(MEGLED);
}Else If(AlertFlg==4){
lcd_putc("\f*SMOKE Detection MSG"); // clear screen & Intrusion detection message stays
output_high(SMOKELED);
}
sendSMS(); // Send Sms Alert


i=0;
lcd_gotoxy(8,2);
while(sysActivated){ // As far system is not reset through re-entering the password
k=kbd_getc(); // the buzzer will be on.
if(k!=0){
delay_ms(50);
lcd_putc('*');
pass=k;
i++;
}if(i>=3){
if(pass[0]==password[0] && pass[1]==password[1] && pass[2]==password[2] ){
lcd_putc("\f[Password OK]");
lcd_gotoxy(2,2);
lcd_putc("System De-Activated");
output_low(buzzer);
pass[0]=0;
pass[1]=0;
pass[2]=0;
delay_ms(2000);
SysActivated=0;
}else{
lcd_gotoxy(1,2);
lcd_putc(" ");
lcd_gotoxy(8,2);
sysActivated=1;
i=0;
}
}


}
}
}



int waitResponse(unsigned int16 t){ // This method simply recieves the rs232 response from phone
// while sending the AT-Commands to cell phone
int r;

TIMEOUT = T;
timeoutFlg = 1;
Index = 0;

do{
if (kbhit()){
buf[index] = fgetc(GSM);
index++;
}
delay_ms(1);
TIMEOUT--;
}while(TIMEOUT > 0 && TIMEOUT < 31000 && index<60);
BUF[INDEX]='\0';

r = 0 ;
if(STRstr(BUF,sSen)>0){ // error
r = 4;
}else if(STRstr(BUF,SER)>0){ // error
r = 2;
}else if(STRstr(BUF,SOK)>0){ // datasent ok
r = 1;
}

if(r>0){
return r;
}else{
return 0;
}

}

int sendSMS(){ // Sms Sending routine throgh AT-Commands

CHAR ctrlZ = 26,c=34,resp;
lcd_gotoxy(2,2);
lcd_putc("Sending SMS Alert..");
fprintf(GSM,"AT\n\r"); //AT Command Start from here
waitResponse(2000);
fprintf(GSM,"AT+CMGF=1\n\r"); //SMS Text Mode On
waitResponse(2000);
fprintf(GSM,"AT+CMGS=%C%S%C\n\r",c,nServer,c); // SEND SMS COMMAND
waitResponse(2000); // no error.
If(AlertFlg==1){
fprintf(GSM,"IR %s",dtstr); // Giving str i.e. alert message to send
}Else if(AlerTFlg==2){
fprintf(GSM,"PIR %s",dtstr); // Giving str i.e. alert message to send
}Else if(AlerTFlg==3){
fprintf(GSM,"MEGNATIC %s",dtstr); // Giving str i.e. alert message to send
}Else if(AlerTFlg==4){
fprintf(GSM,"SMOKE %s",dtstr); // Giving str i.e. alert message to send
}

waitResponse(1000);
fprintf(GSM,"%c",ctrlZ); // Send it with ctrlZ character
resp = waitResponse(5000); // Wait for Send OK response
if(resp!=4 && resp!=2){ // If not any error then
fprintf(GSM,"AT\n\r");
waitResponse(1000); // SMS Alert has been sent successfully
AlertFlg=0;
return 1;
}
lcd_putc("SMS Send Error.."); // Other wise display error
return 0;
}

void CheckSensors(){ // System Scanning
byte c=0,c2=0;
AlertFlg=0;
if(kbhit(IRS1)) // Check First Sensor
{c = fgetc(IRS1);}
if(kbhit(IRS2)){ // Check Second Sensor
c2 = fgetc(IRS2);}

lcd_gotoxy(1,2);
printf(lcd_putc,",%d ",c); // If some thing is recived show progress on lcd
if(c==0 && c2==0){ // If there was intrusion then data will not recieved i.e. 0
timeout2++; // Increament time
}else{
timeout2=0;
}
if(timeout2>Sen){ // if time crosses the sensitiveity value
AlertFlg=1; // Then this is alert condition i.e. intrusion detected.
timeout2=0;
break;
}
if(input(PIRSENSOR)==1){
AlertFlg=2;
BREAK;
}else if(input(MEGSENSOR)==1){
AlertFlg=3;
BREAK;
}else if(input(SMOKESENSOR)==1){
AlertFlg=4;
BREAK;
}

}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top