By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

plaese correct the error

P: 5
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
unsigned int Humidity = 0;
unsigned int Temperature = 0;
82
short smoke = 0;
short human = 0;
short system = 0;
short stt1,stt2,stt3;
short sms_musk1;
long adc_rd = 0;
long Cnt_human = 0;
long cnt_sms=0;
char uart_rd;
#define Buzzer RC2_bit
#define Relay RD3_bit
#define ON 1
#define OFF 0
void Get_Humidity(void);
void Get_Temperature(void);
void Get_PIR_Sensor(void);
void Get_Gas_Sensor(void);
void System_Control(void);
void Send_Presense(void);
void SMS_Int(void);
void UART_Write_CText(const char *cptr)
{
char chr;
for ( ; chr = *cptr ; ++cptr ) UART1_Write(chr);
83
}
char SMS[] = "Human: . Smoke: . Temp: C. Hum: %";
void main()
{
TRISA = 0xFF;//all input
ADCON1 = 0x00;//all analog
TRISC2_bit = 0; // Set as output
TRISD3_bit = 0; //Set as output
Relay = OFF;
Buzzer = ON;
// LCD Initialization...
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); //clear LCD
Lcd_Cmd(_LCD_CURSOR_OFF); //Cusros Off
Lcd_Out(1,4,"SMART HOME ");
Lcd_Out(2,4,"AUTOMATION ");
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
Buzzer = OFF;
UART1_Init(9600);
Delay_ms(100);
while(1)
{
84
Get_Humidity(void);
Get_Temperature(void);
Get_Gas_Sensor(void);
Get_PIR_Sensor(void);
//main system control...
System_Control(void);
cnt_sms++;
if(cnt_sms>5000)
{
cnt_sms = 0;
SMS_Int(void);
UART1_Write_Text(SMS);
UART1_Write((char)26);//send Control + Z
UART1_Write((char)13);
UART1_Write((char)10);
}
}//while...(1)
}//void main
/************************************************** ***************************
********************** Get_Humidity ***********************************
************************************************** ***************************/
void Get_Humidity(void)
{
char hum[] = "RH: %";
85
int ii;
float voltage = 00.00;
ADCON0 = 0b00010001;// Select Channel 2
adc_rd = 0; //Clear Previous Data
for(ii=0;ii<20;ii++)
{
adc_rd += ADC_Read(2); //Take sample and add
}
adc_rd /= 20;// Get the average data
voltage = adc_rd*0.004883;// 5/1023
Humidity = (int)((3.71 * voltage * voltage * voltage) - (20.65 * voltage * voltage) + (64.81 *
voltage) - 27.44);
hum[3] = Humidity/10 + 48;
hum[4] = Humidity%10 +48;
Lcd_Out(1,1,hum);
// collect data...
SMS[37] = hum[3];
SMS[38] = hum[4];
}
/************************************************** ***************************
********************** Get_Temperature *********************************
************************************************** ***************************/
void Get_Temperature(void)
{
char Tmp[] = "Temp: C";
int jj;
float voltage = 00.00;
ADCON0 = 0b00011001;// Select Channel 3
86
adc_rd = 0; //Clear Previous Data
for(jj=0;jj<20;jj++)
{
adc_rd += ADC_Read(3); //Take sample and add
}
adc_rd /= 20;// Get the average data
voltage = adc_rd*0.004883;// 5/1023
Temperature = (int)((5.26 * voltage * voltage * voltage) - (27.34 * voltage * voltage) + (68.87
* voltage) - 17.81);
Tmp[5] = Temperature /10 + 48;
Tmp[6] = Temperature %10 +48;
Tmp[7] = 223;
Lcd_Out(1,8,Tmp);
// collect data...
SMS[27] = Tmp[5];
SMS[28] = Tmp[6];
SMS[29] = Tmp[7];
}
/************************************************** ***************************
********************** Get_Gas_Sensor *********************************
************************************************** ***************************/
void Get_Gas_Sensor(void)
{
Lcd_Out(2,1,"SMK:");
ADCON0 = 0b00001001;//select Channel 1
if(ADC_Read(1)>800)
{
smoke = 1;
87
Lcd_Out(2,5,"YES");
if(stt2 && smoke)//generate single pulse
{
Buzzer = ON;
SMS_Int(void);
UART_Write_CText("Smoke Found");
UART1_Write((char)26);//send Control + Z
UART1_Write((char)13);
UART1_Write((char)10);
Delay_ms(100);
Buzzer = OFF;
stt2 = 0;
}
SMS[17] = 'Y';
SMS[18] = 'E';
SMS[19] = 'S';
}
else
{
smoke = 0;
Lcd_Out(2,5,"No ");
stt2 = 1;
SMS[17] = 'N';
SMS[18] = 'O';
SMS[19] = ' ';
}
88
}
/************************************************** ***************************
********************** Get_PIR_Sensor ********************************
************************************************** ***************************/
void Get_PIR_Sensor(void)
{
Lcd_Out(2,9,"Man:");
ADCON0 = 0b00000001;//select Channel 0
if(ADC_Read(0)>512)
{
human = 1;
Lcd_Out(2,13,"YES");
if(stt1 && human)//generate single pulse
{
Buzzer = ON;
SMS_Int(void);
UART_Write_CText("Human Found");
UART1_Write((char)26);//send Control + Z
UART1_Write((char)13);
UART1_Write((char)10);
Delay_ms(100);
Buzzer = OFF;
stt1 = 0;
}
SMS[6] = 'Y';
SMS[7] = 'E';
89
SMS[8] = 'S';
}
else
{
human = 0;
Lcd_Out(2,13,"No ");
stt1 = 1;
SMS[6] = 'N';
SMS[7] = 'O';
SMS[8] = ' ';
}
// after movement hysteresis...
if(human == 1)
{
system = 1;
Cnt_human = 0;
}
else
{
if(Cnt_human<50)Cnt_human++;
while(Cnt_human>=49)
{
system = 0;
break;
}
}
90
}
/************************************************** ***************************
********************** Get_PIR_Sensor ********************************
************************************************** ***************************/
void System_Control(void)
{
if(system)
{
if(Temperature<60 && smoke ==0)
{
Relay = ON;
}
else
{
Relay = OFF;
if(Temperature>60 || smoke==1)
{
Buzzer = ~Buzzer;
Delay_ms(500);
}
}
}
else
{
Relay = OFF;
}
91
if(Temperature>60 || smoke==1)
{
Buzzer = ~Buzzer;
Delay_ms(500);
SMS_Int(void);
UART_Write_CText("Fire Found");
UART1_Write((char)26);//send Control + Z
UART1_Write((char)13);
UART1_Write((char)10);
}
}
/************************************************** ***************************
********************** SMS_Int ************************************
************************************************** ***************************/
void SMS_Int(void)
{
UART1_Write_Text("AT\r");
Delay_ms(500);
UART_Write_CText("AT+cmgf=1\r");
Delay_ms(500);
UART_Write_CText("AT+cmgs=");
UART1_Write((char)'"');
UART_Write_CText("01799251992");
UART1_Write((char)'"');
UART1_Write((char)13);
UART1_Write((char)10);
Delay_ms(500);
}
Jun 1 '16 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
I can answer questions and recommend solutions but I do not do debugging.

My suggestion here is that you step through the code using your debugger. Insert a breakpoint at each function call then start your program. When you hit a breakpoint start debugging just that function. When it works, remove the breakpoint and restart the program.

Gradually all the breakpoints will be removed and that will mean the program now works.
Jun 1 '16 #2

Expert 100+
P: 2,396
This is not Standard C. sbit and the decimal numbers 82-91 sprinkled throughout are not standard. Which nonstandard variant are you using?

Does the error occur at compile-time, link-time, or run-time?
Are you getting an error message?
If so, please provide the precise error message.
Does the program output differ from your expectations?

It would be a lot easier to read your code if you use CODE Tags. If you do, how do the line numbers in your post compare to line numbers in your input file? Knowing that will help interpret any compiler error messages.
Jun 1 '16 #3

Post your reply

Sign in to post your reply or Sign up for a free account.