Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Someone can give me an example of switch active low..and active high...used for pic 16f877a..
ex:when we use active high circuit,so what about the program???example would help..thanks.
void main()
{
int i;
unsigned char state, oldstate;
trisc=1; // set port as a input
trisb=0; //set port b as output
while(1)
{
state = (portb & 0x2C) >> 2; // we need 2,3,4,5 so put them in low nibble
old state <<= 4; // added to oldstate
oldstate += state; // gives us 8 possible states needed
// other states can be implemented as you need them
switch(oldstate)
{
case 0x01: // switch on f2
output(1,5);
break;
case 0x02: // switch on f3
output(1,5);
break;
case 0x04: // switch on f4
output(1,5);
break;
case 0x08: // switch on f5
output(255,5);
break;
case 0x11: // switch on f2 ( again )
output(1,10);
break;
case 0x22: // switch on f3 ( again )
output(1,10);
break;
case 0x44: // switch on f4 ( again )
output(1,10);
break;
case 0x88: // switch on f5 ( again )
output(255,10);
break;
}
}
}
void output(char portval, char duration)
{
int i;
delay_ms(2000); //two second delay for next operation
for(i=0;i <= duration;i++) //use for to read funtion for duration ex;if led it will blink duration
{
portb = portval; //port bo on -siren or buzzer is on or LED's
delay_ms(500); //half second delay
portb = 0; //all of port b is off-alarm or buzzer is stop after sound for ten time.
delay_ms(500); //half secon delay
}
}
output(%0000001, 10);
void output(char portval, char duration);
void main()
{
int i;
unsigned char state, oldstate;
TRISC=255; // set port as a input
TRISB=0; //set port b as output
while(1)
{
state = (PORTB & 0x2C) >> 2; // we need 2,3,4,5 so put them in low nibble
oldstate <<= 4; // added to oldstate
oldstate += state; // gives us 8 possible states needed
// other states can be implemented as you need them
switch(oldstate)
{
case 0x01: // switch on f2
output(1,5);
break;
case 0x02: // switch on f3
output(1,5);
break;
case 0x04: // switch on f4
output(1,5);
break;
case 0x08: // switch on f5
output(255,5);
break;
case 0x11: // switch on f2 ( again )
output(1,10);
break;
case 0x22: // switch on f3 ( again )
output(1,10);
break;
case 0x44: // switch on f4 ( again )
output(1,10);
break;
case 0x88: // switch on f5 ( again )
output(255,10);
break;
}
}
}
void output(char portval, char duration)
{
int i;
DelayMs(2000); //two second delay for next operation
for(i=0;i <= duration;i++) //use for to read funtion for duration ex;if led it will blink duration
{
PORTB = portval; //port bo on -siren or buzzer is on or LED's
DelayMs(500); //half second delay
PORTB = 0; //all of port b is off-alarm or buzzer is stop after sound for ten time.
DelayMs(500); //half secon delay
}
}