1 / 20

Chapter 2 PIC 16F887 Microcontroller

Chapter 2 PIC 16F887 Microcontroller . Eng. Hazem W. Marar. Pic 16F887. Ports. Analog Pins. In MikroC. Ansel and Anselh. Turn LED on. void main() { TRISB = 0 ; // set PORTB as OUTPUT PORTB = 0xff; // turn all LEDs ON }. Write a code to toggle an LED. Delays.

verdi
Download Presentation

Chapter 2 PIC 16F887 Microcontroller

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2PIC 16F887 Microcontroller Eng. Hazem W. Marar

  2. Pic 16F887

  3. Ports

  4. Analog Pins

  5. In MikroC

  6. Ansel and Anselh

  7. Turn LED on • void main(){TRISB = 0 ; // set PORTB as OUTPUT PORTB = 0xff; // turn all LEDs ON}

  8. Write a code to toggle an LED

  9. Delays • 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. Use an input signal (push button) to control an LED

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

  12. Use 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. Bouncing effect unsigned short current; unsigned short debounce ( ) { current = PORTB.F0; if( LastButton != current) { delay_ms(5); current = PORTB.F0;} return current; }

  15. Use push buttons to change flashing delays

  16. Use a single push button to change flashing delays

  17. Managing Individual Bits

  18. Use an input signal (push button) to control a LED matrix

  19. Use push buttons to control multiple LED matrices

  20. Lab exercise Chapter 2

More Related