Hi Sir or Ma'amPara saan po yung dalawang bagay na malapit doon sa lcd???...i-momodify ko na lang po ba itong circut na ito???...Pasensya na po at sobrang naguguluhan po ako sa pagbuo ng circuit na may pic...Thanks!!!...
/****************************************************************************** This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>*****************************************************************************/#include <pic.h>#include <htc.h>#include "lcd.h"#include "keypad.h"#ifndef _XTAL_FREQ #define _XTAL_FREQ 4000000#endif__CONFIG(XT & WDTDIS & BORDIS & PROTECT); void main (void){ unsigned char key_bit_patterns = 0x00; unsigned char key_ascii = 0x00; InitKeypad(); lcd_init(); lcd_goto(0); lcd_puts("4x3 Keypad and LCD"); lcd_goto(0x40); lcd_puts("Interface Demo"); lcd_goto(0x14); lcd_puts("by Tiktak"); lcd_goto(0x54); lcd_puts("electronicslab.ph"); __delay_ms(250); __delay_ms(250); __delay_ms(250); __delay_ms(250); lcd_clear(); while(1) { lcd_goto(0x00); if(IsKeyPress()) { key_bit_patterns = ReadKeypad(); key_ascii = GetKeyAscii(key_bit_patterns); if(key_ascii == '1'){ lcd_puts("Number 1"); } else if (key_ascii == '2'){ lcd_puts("Number 2"); } else if (key_ascii == '3'){ lcd_puts("Number 3"); } else if (key_ascii == '4'){ lcd_puts("Number 4"); } else if (key_ascii == '5'){ lcd_puts("Number 5"); } else if (key_ascii == '6'){ lcd_puts("Number 6"); } else if (key_ascii == '7'){ lcd_puts("Number 7"); } else if (key_ascii == '8'){ lcd_puts("Number 8"); } else if (key_ascii == '9'){ lcd_puts("Number 9"); } else if (key_ascii == '0'){ lcd_puts("Number 0"); } else if (key_ascii == '#'){ lcd_clear(); lcd_puts("hash"); } else if (key_ascii == '*'){ lcd_puts("star"); } } }}
/* * Keypad Routines for PIC * * Rows and Columns are on the same PORT. * - COLUMNs --> PORTx<6:4> * - ROWs --> PORTx<3:0> * * Franz Duran - 12/17/2009 */#include "keypad.h"#include <htc.h>#ifndef _XTAL_FREQ // Unless already defined assume 4MHz system frequency // This definition is required to calibrate __delay_us() and __delay_ms() #define _XTAL_FREQ 4000000#endif//edit to match PORTx used#define KEYPADTRIS TRISB#define KEYPADPORT PORTB#define KEYPAD_COLUMN_MASK 0b01110000 //column mask, since the keypad column are in PORTx<6:4> pins#define KEYPAD_ROW_MASK 0b00001111 //column mask, since the keypad column are in PORTx<6:4> pins#define ROWS_TOTAL 4 //number of rows/* * Initialize Keypad pins */void InitKeypad(void){ KEYPADTRIS = 0xF0; //PORTx<6:4> input, COLUMNS //PORTx<3:0> output, ROWS KEYPADPORT |= 0x0F; //PORTx<3:0> initially high return;}/* * Scan keypad routine */static unsigned char ScanKeypad(void){ unsigned char column_bits = 0x00; unsigned char current_row; //scan rows, from ROW0 to ROW3, while reading COLUMNs for(current_row=0;current_row < ROWS_TOTAL;current_row++) { KEYPADPORT = ~(1 << current_row); //scan row __delay_us(50); //short delay to make signal stable column_bits = KEYPADPORT & KEYPAD_COLUMN_MASK; //read column bit pattern, PORTx<6:4> //to detect for a key press if (column_bits != KEYPAD_COLUMN_MASK) //if a keypress was detected { return (column_bits | current_row); //return this value indicating what key was pressed //current_row = the row being currently scanned //column_bits = store the column bit patterns } } return 0; //no key detected}/* * Read Keypad Routine */unsigned char ReadKeypad(void){ unsigned char key1=0,key2=0; if ( key1 = ScanKeypad() ) //detect if a key was pressed { __delay_ms(10); //software debounce key2 = ScanKeypad(); //read again while(ScanKeypad()); //wait until button is released if (key1==key2) //if both readings are equal, a valid return key1; //keypress was detected so return key value else return 0; //not a valid key, return 0 } else return 0; //if no key, return 0}/* * Convert the key values to corresponding Ascii */unsigned char GetKeyAscii(unsigned char key_val){ switch(key_val) { case KEY1: return '1'; case KEY2: return '2'; case KEY3: return '3'; case KEY4: return '4'; case KEY5: return '5'; case KEY6: return '6'; case KEY7: return '7'; case KEY8: return '8'; case KEY9: return '9'; case KEYSTAR: return '*'; case KEY0: return '0'; case KEYHASH: return '#'; } return 0; }/* * Check if a key is pressed */unsigned char IsKeyPress(void){ //all rows are logic low KEYPADPORT &= ~KEYPAD_ROW_MASK; //if any columns are low, then keypress is detected if( (KEYPADPORT & KEYPAD_COLUMN_MASK) != KEYPAD_COLUMN_MASK ) return 1; //keypress detected else return 0; //no keypress detected}
#ifndef _KEYPAD_H_#define _KEYPAD_H_#include <pic.h>//tested with 4x4 Keypad from E-gizmo/* * Edit key bit patterns below to match application * PORTx<7:4> are columns and PORTx<3:0> are rows*///row0 keys#define KEY1 0x60#define KEY2 0x50#define KEY3 0x30//#define KEYA 0x70//row1 keys#define KEY4 0x61#define KEY5 0x51#define KEY6 0x31//#define KEYB 0x71//row2 keys#define KEY7 0x62#define KEY8 0x52#define KEY9 0x32//#define KEYC 0x72//row3 keys#define KEYSTAR 0x63#define KEY0 0x53#define KEYHASH 0x33//#define KEYD 0x73//#define KEYNONE 0x00//Initialize Keypad pins. Check code file to edit port connectionsvoid InitKeypad(void);//Read Keypad Routine, return key bit patternunsigned char ReadKeypad(void);//Convert the key bit pattern to corresponding Ascii characterunsigned char GetKeyAscii(unsigned char key_val);//Detect any key press, return True if a keypress is detected; False if none.unsigned char IsKeyPress(void);#endif
#ifndef _XTAL_FREQ // Unless specified elsewhere, 4MHz system frequency is assumed #define _XTAL_FREQ 4000000#endif#include <htc.h>#include "lcd.h"#define LCD_RS RC4//#define LCD_RW RA2#define LCD_EN RC5#define LCD_DATA PORTD#define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))/* write a byte to the LCD in 4 bit mode */voidlcd_write(unsigned char c){ __delay_us(40); LCD_DATA = ( ( c >> 4 ) & 0x0F ); LCD_STROBE(); LCD_DATA = ( c & 0x0F ); LCD_STROBE();}/* * Clear and home the LCD */voidlcd_clear(void){ LCD_RS = 0; lcd_write(0x1); __delay_ms(2);}/* write a string of chars to the LCD */voidlcd_puts(const char * s){ LCD_RS = 1; // write characters while(*s) lcd_write(*s++);}/* write one character to the LCD */voidlcd_putch(char c){ LCD_RS = 1; // write characters lcd_write( c );}/* * Go to the specified position */voidlcd_goto(unsigned char pos){ LCD_RS = 0; lcd_write(0x80+pos);} /* initialise the LCD - put into 4 bit mode */voidlcd_init(){ char init_value;// ADCON1 = 0x06; // Disable analog pins on PORTA init_value = 0x3; TRISC=0; TRISD=0; LCD_RS = 0; LCD_EN = 0;// LCD_RW = 0; __delay_ms(15); // wait 15mSec after power applied, LCD_DATA = init_value; LCD_STROBE(); __delay_ms(5); LCD_STROBE(); __delay_us(200); LCD_STROBE(); __delay_us(200); LCD_DATA = 2; // Four bit mode LCD_STROBE(); lcd_write(0x28); // Set interface length lcd_write(0b1100); // Display On, Cursor On, Cursor Off lcd_clear(); // Clear screen lcd_write(0x6); // Set entry Mode}
/* * LCD interface header file * See lcd.c for more info *//* write a byte to the LCD in 4 bit mode */extern void lcd_write(unsigned char);/* Clear and home the LCD */extern void lcd_clear(void);/* write a string of characters to the LCD */extern void lcd_puts(const char * s);/* Go to the specified position */extern void lcd_goto(unsigned char pos); /* intialize the LCD - call before anything else */extern void lcd_init(void);extern void lcd_putch(char);/* Set the cursor position */#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)
hehehe,, welcome, ano gagawin mo?.. gagawa k ng password?..
for 4x4 keypad please refer to the original thread by sir paranz posted above, just add the fourth column and the pull up, connect it to RB7
since marami ka na idea, try mo kung san ka ma hiyang,, .. Happy New Year to all..