caramoan tour package

caramoan tour package

Author Topic: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a  (Read 775 times)

Offline garvs

  • LR44 Battery
  • *
  • Posts: 0
  • Pogi/Ganda Points: 0
good day....hi...

may nakakaalam po ba ng circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a?...pwede po bang magpatulong???...kasi po hindi ko po talaga alam kung paano bubuuin at sisimulan ang circuit na ito...pasensiya na po at maraming salamat na rin po...
  :-[ :-[

Philippine Electronics Forum


Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #1 on: December 31, 2010, 05:28:56 PM »

Philippine Electronics Forum

Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #1 on: December 31, 2010, 05:28:56 PM »

Offline garvs

  • LR44 Battery
  • *
  • Posts: 0
  • Pogi/Ganda Points: 0
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #2 on: January 01, 2011, 04:30:20 PM »
Hi Sir or Ma'am

Para 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!!!...
 :-[ :-[ :-[

Philippine Electronics Forum

Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #2 on: January 01, 2011, 04:30:20 PM »

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #3 on: January 01, 2011, 05:26:55 PM »
Hi Sir or Ma'am

Para 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!!!...
 :-[ :-[ :-[

pwd na po yan wala na, nilagay ko lang yan pang monitor ng pulse..

Philippine Electronics Forum

Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #3 on: January 01, 2011, 05:26:55 PM »

Offline tiktak

  • Gas Turbine
  • **
  • Posts: 2859
  • Pogi/Ganda Points: 203
  • Gender: Male
    • Tiktakx's Blog
Interfacing 4x3Keypad and LCD to PIC
« Reply #4 on: January 01, 2011, 07:28:14 PM »
mabait lang ako sa bagong taon  ;D

Project is based on Keypad routines by Sir Paranz found here:
 http://www.electronicslab.ph/forum/index.php?topic=7613.msg299536#msg299536
LCD routines is based on the LCD routines found in the samples folder of HI-TECH C



main.c
Code: [Select]
/******************************************************************************
    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.c
Code: [Select]
/*
 * 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
}

keypad.h
Code: [Select]
#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 connections
void InitKeypad(void);

//Read Keypad Routine, return key bit pattern
unsigned char ReadKeypad(void);

//Convert the key bit pattern to corresponding Ascii character
unsigned 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
lcd.c
Code: [Select]
#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 */

void
lcd_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
 */

void
lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(2);
}

/* write a string of chars to the LCD */

void
lcd_puts(const char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}

/* write one character to the LCD */

void
lcd_putch(char c)
{
LCD_RS = 1; // write characters
lcd_write( c );
}


/*
 * Go to the specified position
 */

void
lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}

/* initialise the LCD - put into 4 bit mode */
void
lcd_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.h
Code: [Select]
/*
 * 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)

8051 stuff

Philippine Electronics Forum

Interfacing 4x3Keypad and LCD to PIC
« Reply #4 on: January 01, 2011, 07:28:14 PM »

Offline garvs

  • LR44 Battery
  • *
  • Posts: 0
  • Pogi/Ganda Points: 0
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #5 on: January 01, 2011, 08:20:14 PM »
Hi Sir tiktak at Sir jov3n,

thanks po sa mga reply niyo...Pag-aralan ko na lang po kung paano nangyari ang mga ganon sa design niyo..may nakita rin po kasi ako sa net na circuit design, may konting similarities...sa connection po kasi ng keypad at lcd doon po nag-iba...hmm...thanks po...

@ sir tiktak...sabi mo mabait ka sa bagong taon...ibig sabihin po ba niyan mabait kayo sa buong bagong taon???... ;D

thanks ulit!!!

Offline tiktak

  • Gas Turbine
  • **
  • Posts: 2859
  • Pogi/Ganda Points: 203
  • Gender: Male
    • Tiktakx's Blog
Re: Interfacing 4x3Keypad and LCD to PIC
« Reply #6 on: January 01, 2011, 08:22:02 PM »
Demo


8051 stuff

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #7 on: January 01, 2011, 08:22:56 PM »
hehehe,, welcome, ano gagawin mo?.. gagawa k ng password?..

Offline garvs

  • LR44 Battery
  • *
  • Posts: 0
  • Pogi/Ganda Points: 0
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #8 on: January 01, 2011, 08:36:45 PM »
hehehe,, welcome, ano gagawin mo?.. gagawa k ng password?..

para po sa thesis po...napunta po sa akin ang part na ito ng thesis namin eh hindi ko ganon ka-gets ang pic kaya po back to basic ko pa pong pag-aaralan ito eh dapat complicated things na ang alam ko kasi nga thesis na kami....

Offline garvs

  • LR44 Battery
  • *
  • Posts: 0
  • Pogi/Ganda Points: 0
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #9 on: January 01, 2011, 08:41:34 PM »
@ sir tiktak... hmmm....ganon pala yun..sa proteus niyo po ba ginawa ang simulation???...at sir tiktak...since kailangan ko ay 4x4 keypad eh di mababago din po ang buong connection doon sa 3x4 keypad sample circuit na binigay niyo po???...thanks ulit...pasensiya at madaming tanong... :-[ :-[ :-[

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #10 on: January 01, 2011, 08:46:18 PM »
try this, palitan mo lng ng PIC,   ;) ;) ;)


Offline tiktak

  • Gas Turbine
  • **
  • Posts: 2859
  • Pogi/Ganda Points: 203
  • Gender: Male
    • Tiktakx's Blog
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #11 on: January 01, 2011, 08:48:18 PM »
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
8051 stuff

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #12 on: January 01, 2011, 08:52:58 PM »
since marami ka na idea, try mo kung san ka ma hiyang,, .. Happy New Year to all..

Offline garvs

  • LR44 Battery
  • *
  • Posts: 0
  • Pogi/Ganda Points: 0
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #13 on: January 01, 2011, 09:04:12 PM »
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

hmmm...I see...thanks po sa info!!!...happy new year...

Offline garvs

  • LR44 Battery
  • *
  • Posts: 0
  • Pogi/Ganda Points: 0
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #14 on: January 01, 2011, 09:05:23 PM »
since marami ka na idea, try mo kung san ka ma hiyang,, .. Happy New Year to all..

thanks sir...sige po...thanks po ulit!!!!

Offline reconnect0013

  • LR44 Battery
  • *
  • Posts: 0
  • Pogi/Ganda Points: 0
Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #15 on: January 29, 2011, 10:40:51 AM »
goodam po mga sir! :) nakita kopo ung pic lcd simulation video dito,ask ko po kung posible po ba na ung key pad eh gawing ps/2 keyboard un po kasi ung problem ko eh, sana po matulungan nyo ko, thanks

Philippine Electronics Forum

Re: circuit design for 4x20 lcd and 4x4 keypad connected to pic16f877a
« Reply #15 on: January 29, 2011, 10:40:51 AM »

 

Privacy Policy

Contact Us: elabph@yahoo.com