1 / 14

Chapter 3 I/Os

Chapter 3 I/Os . Eng. Hazem W. Marar. LCDs.

Download Presentation

Chapter 3 I/Os

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 3I/Os Eng. Hazem W. Marar

  2. LCDs Simply, the LCD consists of 6 panels. The most important part is a set of two transparent panels with a liquid crystal solution between them. Light is shined from behind the panels. Each crystal either allows light to pass through or blocks the light. The configuration of the crystals forms the image.

  3. LCD Pinout

  4. How to Interface the LCD?

  5. Code sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbitLCD_RS_Direction at TRISB4_bit; sbitLCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections char txt1[ ] = "LCD Example"; char i; // Loop variable void main(){ ANSEL = 0; // Configure AN pins as digital I/O ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,6,txt1); // Write text in first row // Moving text for(i=0; i<4; i++) { // Move text to the right 4 times Lcd_Cmd(_LCD_SHIFT_RIGHT); Delay_ms(1000); }}

  6. Write a code to check which pin is clicked in port d

  7. Keypad interfacing

  8. Keypad Code unsigned short kp = 0; char txt[6]; // Keypad module connections char keypadPort at PORTD; // End Keypad module connections void main() { Keypad_Init(); // Initialize Keypad ANSEL = 0; ANSELH = 0; while(1) { kp = 0; // Wait for key to be pressed and released while (!kp); { kp = Keypad_Key_Click();} // Store key code in kp variable switch (kp) { case 1: kp = 49; break; // 1 case 2: kp = 50; break; // 2 case 3: kp = 51; break; // 3 case 4: kp = 52; break; // 4 case 5: kp = 53; break; // 5 case 6: kp = 54; break; // 6 case 7: kp = 55; break; // 7 case 8: kp = 56; break; // 8 case 9: kp = 57; break; // 9 case 10: kp = 42; break; // '*' case 11: kp = 48; break; // '0' case 12: kp = 35; break; // '#' default: kp += 48; } }}

  9. Sample Code do { kp = 0; do kp = Keypad_Key_Click(); while (!kp); switch (kp) { case 1: kp = 49; break; // 1 case 2: kp = 50; break; // 2 case 3: kp = 51; break; // 3 case 5: kp = 52; break; // 4 case 6: kp = 53; break; // 5 case 7: kp = 54; break; // 6 case 9: kp = 55; break; // 7 case 10: kp = 56; break; // 8 case 11: kp = 57; break; // 9 case 13: kp = 42; break; // * case 14: kp = 48; break; // 0 case 15: kp = 35; break; // # } Lcd_Chr(1, 10, kp); // Print key ASCII value on LCD } while (1);

  10. Make a simple calculator • Hint: you may need WordToStr(unsigned short, txt); • OR IntToStr(int, txt);

  11. Relays

  12. How to interface relays with PIC ? • Remember transistor ?

  13. Make a lock/unlock system • Use relays to control the output signal

  14. Lab exercise Chapter 4

More Related