Presentation is loading. Please wait.

Presentation is loading. Please wait.

C HAPTER 2 PIC 16F887 M ICROCONTROLLER Eng. Hazem W. Marar.

Similar presentations


Presentation on theme: "C HAPTER 2 PIC 16F887 M ICROCONTROLLER Eng. Hazem W. Marar."— Presentation transcript:

1 C HAPTER 2 PIC 16F887 M ICROCONTROLLER Eng. Hazem W. Marar

2 P IC 16F887

3 P ORTS

4 A NALOG P INS

5 I N M IKRO C

6 A NSEL AND A NSELH

7 T URN LED ON void main() { TRISB = 0 ; // set PORTB as OUTPUT PORTB = 0xff; // turn all LEDs ON }

8 W RITE A CODE TO TOGGLE AN LED

9 D ELAYS void main( ) { TRISB = 0 ; // set PORTB as OUTPUT While(1) // forever { PORTB = 0xff ; // turn all LEDs ON Delay_ms(500) ; // wait 500 ms PORTB = 0 ; // turn all LEDs OFF Delay_ms(500) ; // wait 500 ms } }

10 U SE AN INPUT SIGNAL ( PUSH BUTTON ) TO CONTROL AN LED

11 I NPUT SIGNAL void main( ) { TRISB = 0x01 ; // set 1 st bit of PORTB as INPUT While(1) // forever { if(PORTB.F0 ==1) { PORTB.F1 = 1;} if(PORTB.F0 ==0) { PORTB.F1 = 0;}}

12 U SE AN INPUT SIGNAL ( PUSH BUTTON ) TO TOGGLE AN LED

13 TOGGLE unsigned short LastButton =0; void main(){ TRISC = 0x01 ; PORTC=0x00; while(1) { if(PORTC.F0 ==1 && LastButton ==0) { PORTC.F1=~PORTC.F1; LastButton=1;} else { LastButton = PORTC.F0; } } }

14 B OUNCING EFFECT unsigned short current; unsigned short debounce ( ) { current = PORTB.F0; if( LastButton != current) { delay_ms(5); current = PORTB.F0;} return current; }

15 U SE PUSH BUTTONS TO CHANGE FLASHING DELAYS

16 U SE A SINGLE PUSH BUTTON TO CHANGE FLASHING DELAYS

17 M ANAGING I NDIVIDUAL B ITS

18 U SE AN INPUT SIGNAL ( PUSH BUTTON ) TO CONTROL A LED MATRIX

19 U SE PUSH BUTTONS TO CONTROL MULTIPLE LED MATRICES

20 L AB EXERCISE Chapter 2


Download ppt "C HAPTER 2 PIC 16F887 M ICROCONTROLLER Eng. Hazem W. Marar."

Similar presentations


Ads by Google