View previous topic :: View next topic |
Author |
Message |
Emon Guest
|
Want pin high for a moment |
Posted: Fri Mar 31, 2006 12:44 am |
|
|
hello,
Could anyone tell me how to make pin D high just for a moment/second when "Measuring..." is being displayed.The pin D0 should be high when mechanical switch is pressed.I tried using Output_high(PIN_D0) with the measuring display printf.The problem is this will keep pin DO high till the time 8 bit input is received.
I want D0 high just for a moment when mechanical switch is pressed and then low immediately.
Help me.
Emon
CODE::
void main()
{ int Num_output=10;
int8 result;
int8 value;
int top;
port_b_pullups(TRUE);
lcd_init();
delay_ms(1000);
lcd_init();
while(1)
{
value = input_b();
if(value != 255)
{
if(value & 0x80)
{
printf(lcd_putc,"\fERROR!!\n");
delay_ms(1000);
}
else
{result = value & 0x7F;
printf(lcd_putc,"\fDistance:\n");
printf(lcd_putc,"%u",result);
delay_ms(1000);
}
}
else
{
printf(lcd_putc,"\fMeasuring...\n");
delay_ms(1000); //I want pin DO high just for a moment when when mechanical switch pressed
}
}//while1
}//main |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Mar 31, 2006 7:24 am |
|
|
Try this
Code: |
else
{
printf(lcd_putc,"\fMeasuring...\n");
output_high(PIN_D0)
delay_ms(500);
output_low(PIN_D0)
delay_ms(500);
}
|
|
|
|
emon Guest
|
RE: |
Posted: Fri Mar 31, 2006 9:45 pm |
|
|
thanks mark.
The problem is the code you wrote will keep making D0 high and low till PORT B gets input.
I want DO to go high just once when switch is pressed.
Do i use some interrupt?Please guide me |
|
|
emon Guest
|
help |
Posted: Sat Apr 01, 2006 10:40 am |
|
|
can anyone help?? |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Sat Apr 01, 2006 10:57 am |
|
|
A couple of suggestions:
Provide more information. You mention a switch being depressed but your code doesn't give any indication of a switch being implemented and you only briefly mention it in your post. Even a section of pseudo-code would help the members of the forum understand what you're trying to accomplish.
Provide a complete program listing.
Insert your code using the 'code' feature.
If you're not getting the help you expect, you may be approaching the request in the wrong way. Mark's code snippet does exactly what you requested.
I think if you heed the previous advice you'll have people jumping at the opportunity to help.
Good luck,
John |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Apr 01, 2006 11:08 am |
|
|
It also sounds like a school project which I am not going to write your program for you. |
|
|
tavioman
Joined: 22 Feb 2006 Posts: 65
|
|
Posted: Sun Apr 02, 2006 6:08 am |
|
|
Try with some TIMER interrupt.
start timer........
led high............
timer interrupt..
led low.............
This shoul be very simple and fast.
If the timer overflow it's smaller than one second try with a remainder. |
|
|
|