Friday, May 3, 2013

GSM BASED DOOR LOCKING SYSTEM WITH PIC MICRO CONTROLLER


INTERFACE WITH 4×4 keypad and 2×16 LCD This 16-button keypad provides a useful human interface component for micro controller projects. Convenient adhesive backing provides a simple way to mount the keypad in a variety of applications. Matrix keypads use a combination of four rows and four columns to provide button states to the host device, typically a micro-controller. Underneath each key is a push button, with one end connected to one row, and the other end connected to one column. see the image from the link below. http://tutorial.cytron.com.my/wp-content/uploads/2012/08/keypad.jpg In order for the micro-ocontroller to determine which button is pressed, it first needs to pull each of the four column either low or high one at a time, and then poll the states of the four rows. Depending on the states of the rows, the micro controller can tell which button is pressed. CONNECTION ————————————————————————————————————————————————————————- Connection in between SK40C and 4×4 keypad are only required 9 wires which are 5V(VDD) and Port C0-C7. Additional 4 of 10k ohm resistors were used to pull out the 4 columns of the keypad.. see the image from the link below. http://tutorial.cytron.com.my/wp-content/uploads/2012/08/SK40C_4x4-keypad_LCD.jpg see the schematic diagram from the link below http://tutorial.cytron.com.my/wp-content/uploads/2012/08/SK40C_4x4-keypad_LCD_Schematic.png ADDITIONAL INFORMATION ————————————————————————————————————————————————————————- 4×4 Keypad pin can directly connect to microcontroller or keypad decoder IC for decode purpose. However, DIY scanning of keypad consumes a lot of understanding in programming and more program space. The better way to interface a keypad to the PIC is to use a keypad encoder in between the keypad and the microcontroller. One of the Keypad Encoder is theMMC74C922. Simply hook up all the row and the column pins directly to the encoder and it will output a HIGH pulse on the Data Available pin whenever a key is pressed. After that, the encoder will output 4 bits of data to the PIC. Feature Ultra-thin design Adhesive backing Excellent price/performance ratio Easy interface to any microcontroller Example programs provided for the BASIC Key Specifications Maximum Rating: 24 VDC, 30 mA Interface: 8-pin access to 4×4 matrix Operating temperature: 32 to 122 °F(0 to 50°C) Dimensions:64x62x8 mm Application Ideas Security systems Menu selection Data entry for embedded systems CODE OVERVIEW ————————————————————————————————————————————————————————- system.h http://tutorial.cytron.com.my/wp-content/uploads/2012/08/button.jpg In this part of the source code, the pins which were connected to the columns and the rows of the 4×4 keypad were initialized at here. keypad.c http://tutorial.cytron.com.my/wp-content/uploads/2012/08/p11.jpg This part of source code will determined which 4×4 keypad button being pressed. e.g: KP_R1 = 0; KP_R2 = 1; KP_R3 = 1; KP_R4 = 1; __delay_us(30); It will test whether the 1st row of the keypad being pressed or not. If not, it will goto to 2nd row to check for the button pressed. If the button of the 1st row was being pressed, it will test which column is the location. if (KP_C1 == 0) return ’1′; if (KP_C2 == 0) return ’2′; if (KP_C3 == 0) return ’3′; if (KP_C4 == 0) return ‘A’; If the 1st column, it will return 1 in ASCII form. If it was 2nd column, 2 in ASCII form being return. Same go to column 3 and 4. return 0xFF; If the keypad does not being pressed, this function will return 0xFF to the function which will used it. http://tutorial.cytron.com.my/wp-content/uploads/2012/08/wait2.jpg unsigned char keypad_wait(); This function will test whether the keypad button being pressed or not. do{c_pressed_key = keypad_read();}while (c_pressed_key == 0xFF); If the keypad_read() function does not return anything(return 0xFF only) to the c_pressed_key, it will wait at here until it accept one of the 16 characters on the keypad from keypad_read(). return c_pressed_key; Return the accepted data(character in ASCII form) back to main function. MAIN PROGRAM http://tutorial.cytron.com.my/wp-content/uploads/2012/08/init.jpg unsigned char key_get; It is an unsigned char variable used to store the data get from the 4×4 keypad. TRISC = 0b00001111; Initialize the PORTC<7:4> as output, PORTC<3:0> as input lcd_initialize(); Please refer here for the SK40C with lcd tutorial. http://tutorial.cytron.com.my/wp-content/uploads/2012/08/while3.jpg while(1) While loop used in here in order the micro-controller can always read the data from the keypad LED1 = 1; LED2 = 0; Set the LED1 and LED2 light up and off at first respectively. lcd_putstr(“ Enter Word:”); Display Enter Word on the first row of the 16×2 lcd lcd_2ndline(); Go to 2nd row of the 16×2 lcd for(unsigned int i = 0; i < 17; i++) This loop used in order for the LCD to displayed 16 characters key_get = keypad_wait(); The variable key_get will store the data from keypad_wait() function. LED1 ^= 1; LED2 ^= 1; The led will be toggle each time for the button of the keypad being pressed. Either LED1 on and LED2 off or vice versa. lcd_clear(); Clear the LCD