|
|
View previous topic :: View next topic |
Author |
Message |
Lion Guest
|
I am confused......... |
Posted: Tue May 26, 2009 11:16 pm |
|
|
Hello everyone,
First of all, I am so sorry to post my question again in new topic but I really can not figure out.
I am using PIC 16F877 and CCS 3.222 version, MPLAB V8.1 .
My question is that I am using UV tron flame detector.
When the sensor detect the fire, it will output_high.
I am using UV tron and Temperature sensor at the same time.
I know that I can use " while(! input(PIN_D5)) " to wait for the PIN_D5 go high or use "while(input(PIN_D5))" to wait for the PIN_D5 go low.
My question is that may I use "if" to do the same thing? I mean that I have two conditions for " if " loop. One is " Temp>30 " and the other one is the output_high of UV sensor .
May I use " if (Temp> 30 && input(PIN_D5))" ? ==> to check Temp>30 and wait for PIN_D5 output_high.
So far, I tried many ways but it can not get in the " if loop " Sometimes when Temp> 30 but PIN_D5 does not high. The code get in the loop.
I am confused. I use many "goto" command in my code. Does it damage the code structure?
In "Problem 1",(see the code) I try to check two conditions but it can not get in the "Problem 1" code in the beginning but I tries many method.
Now it always gets in the "Problem One" code but the flame detector do not detect the fire (if detect the fire, flame detector will output high). I do not understand why the code does not consider the condition?
My second question:
May I use the condition like (input(PIN_A2)!=0) or (input(PIN_A2)>1)
or (input(PIN_A2)==0)
The syntax is correct or not? If the PIN_A2 is used to check the flame detector output is high or low.
I really need someone help me to figure out.
Any help will be really really apprecitated.
Thank you so much
Code: |
#include <16F877.h>
#device ADC=10
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include<stdio.h>
#include <math.h> // for temperature sensor
void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(INT_TIMER1);
enable_interrupts(global);
//while(1)
//{
delay_ms(3000);
output_high(PIN_D0); //go forward ; this pin do not decide yet.
output_high(PIN_D1); // go forward ; this pin do not decide yet.
output_high(PIN_C0); //Start Fire Gun
output_high(PIN_C1); //Start barbette
delay_ms(5000); // initial ans settle down everything
start1:
//*** Temperature Sensor Code in this line ***///
printf("Temperature now is in start1 %d\n\r",Temp);
delay_ms(700);
Ultrasonic();
delay_ms(700);
if (Temp>29 && input(PIN_A2)) ==============> Problem 1
{
output_low(PIN_D0); //stop Mother Vehicle
output_low(PIN_D1); //stop Mother Vehicle
delay_ms(1000); //This delay is due to inertia of DC motor
output_low(PIN_C0); //
delay_ms(2000);
output_low(PIN_C1);
//printf("Find the Fire\n\r");
}
}
else if(Temp>29)
{
start2:
if(distance6<27&&distance6>16&&distance5>12&&distance5<19)
{
printf("Distance 6 and 5 are good .Temperature is %d \n\r ", Temp);
delay_ms(3000);
output_low(PIN_D0); // Stop Forward ;
output_low(PIN_D1); // Stop Forward ;
output_low(PIN_C0); // Stop Fire Gun;
output_low(PIN_C1); // Stop the barbette;
delay_ms(1000);
output_high(PIN_E0); //Open the door.
output_high(PIN_C2); //Open the door.
delay_ms(500);
output_low(PIN_C2);
//**now DV1 and DV2 come out **//
delay_ms(1500);
connect_again:
output_low(PIN_C5);
delay_ms(500);
output_high(PIN_C5);
delay_ms(1500);
//*** wireless connect code. I do not show in this line***//
delay_ms(3000);
if(kbhit())
{
TempDV1=getc();
delay_ms(2500);
output_low(PIN_C5); // For some function purpose
delay_ms(1000);
output_high(PIN_C5);// For some function purpose
delay_ms(1500);
//*** wireless connect code. I do not show in this line***//
delay_ms(3000);
}
if(kbhit())
{
TempDV2=getc(); //In here, maybe I need put TempDV2ACK=getc(); to get ACK return
delay_ms(2000);
output_low(PIN_C5);
}
if (TempDV1>28 && TempDV1<120 || TempDV2>28 &&
TempDV2<120)
{
if (TempDV2>TempDV1+3) //DV2 is higher than DV1
{
output_high(PIN_D3);
output_high(PIN_D4); //turn_right
delay_ms(7000);
output_low(PIN_D3); //stop turn_right ;
output_low(PIN_D4); //Stop turn_right ;
delay_ms(1500); //for relay, it needs time to release.
output_high(PIN_D0); // go_straight();
output_high(PIN_D1); // go_straight();
output_high(PIN_C0);
output_high(PIN_C1);
DV1_Detect:
if ( Temp>29&& input(PIN_A2))
{
output_low(PIN_D0); //stop();
output_low(PIN_D1);
delay_ms(1000); //This delay is due to inertia of DC
//motor
output_low(PIN_C0); //Stop Fire Gun
delay_ms(2000); //this delay is due to inertia of DC
//motor
output_low(PIN_C1); //Stop the barbette
}
else
{
goto DV1_Detect;
}
}
else if(TempDV1>TempDV2+3)
{
output_high(PIN_B3); //turn_left();
output_high(PIN_C3); //turn_left();
delay_ms(7000);
output_low(PIN_B3); //stop turn_left;
output_low(PIN_C3); //Stop turn_left;
delay_ms(1500);
output_high(PIN_D0); // go_straight();
output_high(PIN_D1); // go_straight();
output_high(PIN_C0);
output_high(PIN_C1);
DV2_Detect:
if( Temp>29 && input(PIN_A2)) //Detect Temp>29 and check
//flame detector is
//output_high
{
output_low(PIN_D0); //stop();
output_low(PIN_D1); //stop();
delay_ms(1000); //This delay is due to inertia of DC
//motor
output_low(PIN_C0); //
delay_ms(2000); //this delay is due to inertia of DC
//motor
output_low(PIN_C1); //Stop the barbette
printf("Find the FIRE ")
}
else
{
goto DV2_Detect;
}
}
else
{
goto connect_again;
}
}
else
{
goto connect_again;
}
}
else
{
goto start2;
}
}
else
{
delay_ms(1000);
goto start1;
} |
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed May 27, 2009 10:25 am |
|
|
If you can cut your program down to 20 or 30 lines you will get more help.
I would start by drawing a simple flowchart of your code, and maybe read a book about programming structure. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Guest
|
|
Posted: Wed May 27, 2009 4:23 pm |
|
|
SherpaDoug wrote: | If you can cut your program down to 20 or 30 lines you will get more help.
I would start by drawing a simple flowchart of your code, and maybe read a book about programming structure. |
Hello,
Thank you for your suggestion.
I will cut it down and ask them in next topic.
Thank you so much. |
|
|
Ttelmah Guest
|
|
Posted: Thu May 28, 2009 2:33 am |
|
|
No.
Don't keep launching new topics. Doing so, will not help, and makes it impossible for people to see what has 'passed'.When you add a post to the old topic, it automatically moves up the board, so keep the questions about a single problem, in a single thread. Only launch a new topic, once the problem is abandoned or solved, and you are asking about something else.
Launching new topics about the same question, is a way to annoy some of the people here, and reduce the chance of getting answers....
Best Wishes |
|
|
apcaye
Joined: 22 May 2009 Posts: 29 Location: Brazil
|
|
Posted: Thu May 28, 2009 10:31 am |
|
|
Totally agreed, Ttelmah. I was trying to help Lion in a previous thread with the same problem as this one, but now I don't feel motivated to continue supporting him/her.
Adriano. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|