CHAPTER 3 I/OS Eng. Hazem W. Marar 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. LCD PINOUT HOW TO INTERFACE THE LCD? 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; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_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); }} WRITE A CODE TO CHECK WHICH PIN IS CLICKED IN PORT D KEYPAD INTERFACING KEYPAD CODE unsigned short kp = 0; char txt[6]; // Keypad module connections char keypadPort at PORTD; // End Keypad module connections void main() { Keypad_Init(); Keypad ANSEL = 0; ANSELH = 0; // Initialize 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; } }} SAMPLE CODE do { case 9: kp = 55; break; // 7 kp = 0; case 10: kp = 56; break; // 8 do case 11: kp = 57; break; // 9 kp = Keypad_Key_Click(); case 13: kp = 42; break; // * while (!kp); case 14: kp = 48; break; // 0 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 15: kp = 35; break; // # } Lcd_Chr(1, 10, kp); // Print key ASCII value on LCD } while (1); MAKE A SIMPLE CALCULATOR HINT: YOU MAY NEED WordToStr(unsigned short, txt); OR IntToStr(int, txt); RELAYS HOW TO INTERFACE RELAYS WITH PIC ? Remember transistor ? MAKE A LOCK/UNLOCK SYSTEM USE RELAYS TO CONTROL THE OUTPUT SIGNAL LAB EXERCISE Chapter 4