PIC16F887 controlled switch

Thread Starter

Alho

Joined Nov 3, 2011
12
hi, i am trying to write C code for a switch controlled by PIC16F887 microcontroller. i am using the internal 4MHz oscillator and i am using micrC for PRO.

the code i have written is pasted below:

void main()
{
ANSEL = 0;
ANSELH = 0;
C1ON_bit = 0;
C2ON_bit = 0;

TRISD3_bit = 1;
TRISD2_bit = 1;

TRISD.F0 = 0;
TRISD.F1 = 0;
TRISD.F4 = 0;

PORTD.F0 = 0;
PORTD.F4 = 0;
PORTD.F1 = 1;

while(1)
{
if (Button(&PORTD, 2, 1, 1))
{
PORTD.F0 = 1;
PORTD.F1 = 0;
}

if (Button(&PORTD, 3, 1, 1))
{
PORTD.F0 = 0;
PORTD.F1 = 1;
PORTD.F4 = 0;
}
}
}


so far its working, pressing button 1 turns on RED led and turns off GREEN LED. Pressing button 2, turns off RED led and turns on GREEN led.

the thing is i need to include a buzzer that beeps every 30 seconds as long as the RED led is on. and the same "button 1" should be used to turn off the buzzer without turning off the RED led. if i pressed button 2 the buzzer should turn off as with the RED led.

any help greatly appreciated....
10Q
 
Top