Please help! ..URGENT...

Started by kaps_iit May 4, 2004
Hello friends,

I need ur help urgently. I am new to pic micros.

I have ccs c compiler .i made very simple programs but it is
not working as expected.
1. program 1. ....PINB.2 is connected to ground always.

#include <16f877.h>

#byte PORTB = 6

#byte PORTA = 5

#use delay(clock000000)

main()

{

while(TRUE)

{

set_tris_b(0x0F );

while( !input ( PIN_B2))

{

output_high(PIN_B7);

delay_ms(500);

output_low(PIN_B7);

delay_ms(500);

}

}

}

the above program( 1) is running perfectly.No probs..
2..program 2.

#include <16f877.h>

#byte PORTB = 6

#byte PORTA = 5

#use delay(clock000000)

main()

{

while(TRUE)

{

set_tris_b(0x0F );

while( !input ( PIN_B2))

{

output_high(PIN_B7);

delay_ms(2000);

output_low(PIN_B7);

delay_ms(2000);

}

}

}

In the second program I just changed the delay from 500ms to
2000ms .but its not working properly.The pinb.7 is low for
very very short time ( very much less than 2000ms).Pinb.2 is
connected to ground always.please tell me why this is
happening.
3.

#include <16f877.h>

#byte PORTB = 6

#byte PORTA = 5

#use delay(clock000000)

main()

{

while(TRUE)

{

set_tris_b(0x0F );

while( !input ( PIN_B2))..............1

{

delay_ms(1000);

while( !input ( PIN_B2))................2

{

output_high(PIN_B7);

delay_ms(500);

output_low(PIN_B7);

delay_ms(500);

}

}

}

}

In the above program the pinb.7 is low for 1000+50000
ms ..my question is when the program enters the second(2)
while loop then why 1000ms is added everytime to delay..it
shouldnot come out of second while loop.SO 1000ms should be
there only once and as soon as program enters the second
while loop the pinb.7 should be high and low for 500ms
only..but why it is low for 1500 ms EVERYTIME.

Please tell me where I am going wrong.I am really very
confused ..Don?/SPAN>t knw what to do..

Please Help!!

Thanks

Amit