Sunteți pe pagina 1din 5

/*Project Name: LED Chaser with 0.5 second delay*/ #include<16F84A.

h> #use delay(clock=4mhz) /*defines type of device to include device files*/ /* defines crystal frequency 4MHz */

#fuses xt, nowdt, noprotect, noput /* xt oscilator used and no watch dog timer, no code protection, no power up timer is used */ #byte portb=6 /* defines memory location of register */

void main() { byte c,d; set_tris_b(0x00); /* it sets the portb as output port */ while(true) { c = 0; /*initialize the count c equal to zero */ d = 0x01; /* assigns the content of d to 0x01 */ while(c<8) { portb = d; /*sends content of d to portb to turn-on the first LED*/ delay_ms(500); /* creates half second delay between LED on/off*/ d = d << 1; /* shifts the value of data to the left by 1 using shift left operator(<<) */ c++; /* increments the value of c by 1*/ } } }

/* Project Name: PushButton to Turn ON Led */ #include<16F84A.h> #use delay(clock=4mhz) /*defines type of device to include device files*/ /* defines crystal frequency 4MHz */

#fuses xt, nowdt, noprotect, noput /* xt oscilator used and no watch dog timer, no code protection, no power up timer is used */ #byte portb=5 #byte portb=6 /* defines memory location of register */ /* defines memory location of register */

void main() { set_tris_a(0x01); /* it sets the portA RA0 as input port */ set_tris_b(0x00); /* it sets the portB RB0 as output port */ while(true) { if(porta == 0x01) { portb = 0x01; /*assigns content of portB RB0 to 0x01 for turn-on Led*/

} else { portb = 0x00; /*assigns content of portB RB0 to 0x00 for turn-off Led*/ } } }

/* Project Name: PushButton to Turn Led on/off */ #include<16F84A.h> #use delay(clock=4mhz) /*defines type of device to include device files*/ /* defines crystal frequency 4MHz */

#fuses xt, nowdt, noprotect, noput /* xt oscilator used and no watch dog timer, no code protection, no power up timer is used */ #byte portb=5 #byte portb=6 /* defines memory location of register */ /* defines memory location of register */

void main() { set_tris_a(0x01); /* it sets the portA RA0 as input port */ set_tris_b(0x00); /* it sets the portB RB0 as output port */ while(true) { if(porta == 0x01) { if(portb = 0x01) { /*assigns content of portB RB0 to 0x00 for turn-off Led*/ portb = 0x00; } else{ portb = 0x01; } /*assigns content of portB RB0 to 0x01 for turn-on Led*/ } delay_ms(200); } } /* Project Name: Push Button for Blinking Led */ #include<16F84A.h> #use delay(clock=4mhz) /*defines type of device to include device files*/ /* defines crystal frequency 4MHz */

#fuses xt, nowdt, noprotect, noput

/* xt oscilator used and no watch dog timer, no code protection, no power up timer is used */ #byte portb=5 #byte portb=6 /* defines memory location of register */ /* defines memory location of register */

void main() { set_tris_a(0x01); /* it sets the portA RA0 as input port */ set_tris_b(0x00); /* it sets the portB RB0 as output port */ while(true) { if(porta == 0x01) /* if switch pressed Led starts Blinking*/ { while(true) { portb = 0x01; /*assigns portB RB0 to 0x01 for turn-on Led*/ delay_ms(250); portb = 0x00; /*assigns portB RB0 to 0x00 for turn-off Led*/ delay_ms(250); if(porta == 0x01) /* if switch pressed again Led stops Blinking*/ { break; /* comes out of the loop*/ } } } } } /* Project Name: PushButton for Disco Led */ #include<16F84A.h> #use delay(clock=4mhz) /*defines type of device to include device files*/ /* defines crystal frequency 4MHz */

#fuses xt, nowdt, noprotect, noput /* xt oscilator used and no watch dog timer, no code protection, no power up timer is used */ #byte portb=5 #byte portb=6 /* defines memory location of register */ /* defines memory location of register */

void main() { set_tris_a(0x01); /* it sets the portA RA0 as input port */ set_tris_b(0x00); /* it sets the portB RB0 as output port */ while(true) { if(porta == 0x01) /* if switch pressed starts Disco Led */ { while(true) { portb = 0xAA; /*assigns portB RB0 to 0xAA to turn-on 1st Alternate-Led*/ delay_ms(250);

} }

portb = 0x55; /*assigns portB RB0 to 0xAA to turn-on 2nd Alternate-Led*/ delay_ms(250); if(porta == 0x01) /* if switch pressed again stops Disco Led*/ { portb = 0x00; /*assigns portB RB0 to 0x00 for turn-off Led*/ break; /* comes out of the loop*/ } } }

/* Project Name: PushButton for Led Chaser */ #include<16F84A.h> #use delay(clock=4mhz) /*defines type of device to include device files*/ /* defines crystal frequency 4MHz */

#fuses xt, nowdt, noprotect, noput /* xt oscilator used and no watch dog timer, no code protection, no power up timer is used */ #byte portb=5 #byte portb=6 /* defines memory location of register */ /* defines memory location of register */

void main() { byte c,d; set_tris_a(0x01); /* it sets the portA RA0 as input port */ set_tris_b(0x00); /* it sets the portB RB0 as output port */ while(true) { if(porta == 0x01) /* if switch pressed starts Disco Led */ { while(true) { c = 0; /*initialize the count c equal to zero */ d = 0x01; /* assigns the content of d to 0x01 */ while(c < 8) { portb = d; /*sends content of d to portb to turn-on 1st Led*/ delay_ms(250); /* creates 0.25 second delay */ d = d << 1; /* shifts the value of data to the left by 1*/ c++; /* increments the value of c by 1*/ } if(porta == 0x01) /*if switch pressed again stops DiscoLed*/ { portb = 0x00; /*assigns portB RB0 to 0x00 to turn-offLed*/ break; /* comes out of the loop*/ } } }

S-ar putea să vă placă și