MicroController Pros Home Page My Account  Cart Contents  Checkout  
  Store » EEDT6.0 Tutorial 3 My Account  |  Cart Contents  |  Checkout   
Vacation Notice: We are on vacation November 11th - 19th 2017. Any orders placed during that time frame will ship on November 20th.
Quick Find
 
Enter keywords to find the product you are looking for in the Quick Find field above

or use
Advanced Search
Categories
Accessory Boards->
8051->
ADI Blackfin
Arduino->
ARM->
Atmel AVR->
Cypress PSoC
Freescale->
FTDI->
Locktronics
Microchip PIC->
MIPS
Parallax->
Renesas
Silicon Labs
ST Microelectronics->
Texas Instruments->
Tibbo->
Books->
Displays->
E-Blocks->
EEPROM/EPROM/FLASH
Embedded Ethernet->
Embedded Software->
I/O Modules->
Parts & Components->
Pick & Place Tools
Programmable Logic (PLD)
Prototype PCBs->
Robotics
ROM/Flash Emulators
Test & Measurement->
Tutorial Software
Universal Programmers->
Wireless->
Information
Intro to Embedded Tools
Embedded News Digest
Useful Resources
Shipping & Returns
Warranty & Liability
Privacy Notice
Conditions of Use
Contact Us
Using Matrix Keypad with 89V51RD2

This is a tutorial for owners of the EEDT6.0 development board.

Recommended tools include the Keil C51 IDE and the included EM-P-NXP programmer with Flash Magic programming software. Usage of these was covered in the first tutorial (just install C51 the same way as you did MDK-ARM).


This program will display a pressed keypad's number on the second line of the LCD.

Setup and Connections

  • Remove the ATmega32 microcontroller from Socket U17 (Sec-17). This is important!
  • Insert the P89V51RD2 microcontroller to Socket U18 (Sec-13).
    (Sockets U17 and U18 share some pins, which is why you must not have a chip in both at the same time.)
  • Connect P0 to the LCD's data port: P0.0 through P0.7 to D0 through D7.
  • Connect P2.0, P2.1, and P2.2 to the RS, RW, and EN pins of the LCD section.
  • Connect all eight of the P1 port pins to the Keypad section's eight pins.
  • Power up the EEDT6.0 with 9V DC.
  • Test the code. Rather than copying the code below and compiling it yourself, you can download the full project code as source and compiled hex files.


Sample Program


#include <reg52.h> /* special function register declarations */
/* for the intended 8051 derivative */

#include <stdio.h> /* prototype declarations for I/O functions */


//LCD Defines
#define PDATA P0
sbit RS = P2^0;
sbit RW = P2^1;
sbit EN = P2^2;
sbit D7 = P0^7;

//LCD Functions
void Init_LCD(void);
void Clear_LCD(void);
void Wait_LCD(void);
void Write_Char(unsigned char c,int x, int y);
void Write_Text(char* str,int x, int y);


//Keypad defines
sbit COL_1 = P1^7;
sbit COL_2 = P1^6;
sbit COL_3 = P1^5;
sbit COL_4 = P1^4;

sbit ROW_1 = P1^0;
sbit ROW_2 = P1^1;
sbit ROW_3 = P1^2;
sbit ROW_4 = P1^3;

#define KEY_PORT P1

void Delay(void); //Function prototype declaration



void main (void) {

Init_LCD();
Clear_LCD();
Write_Text("Key number - ",0,1);

while(1) //End less while so that program never ends
{
KEY_PORT = 0xff;
COL_1=0;
if(ROW_1 == 0)
{
Write_Text(" ",0,2);
Write_Text("1",0,2);
while(ROW_1 == 0);
}
if(ROW_2 == 0)
{
Write_Text(" ",0,2);
Write_Text("2",0,2);
while(ROW_2 == 0);
}
if(ROW_3 == 0)
{
Write_Text(" ",0,2);
Write_Text("3",0,2);
while(ROW_3 == 0);
}
if(ROW_4 == 0)
{
Write_Text(" ",0,2);
Write_Text("4",0,2);
while(ROW_4 == 0);
}

KEY_PORT = 0xff;
COL_2=0;
if(ROW_1 == 0)
{
Write_Text(" ",0,2);
Write_Text("5",0,2);
while(ROW_1 == 0);
}
if(ROW_2 == 0)
{
Write_Text(" ",0,2);
Write_Text("6",0,2);
while(ROW_2 == 0);
}
if(ROW_3 == 0)
{
Write_Text(" ",0,2);
Write_Text("7",0,2);
while(ROW_3 == 0);
}
if(ROW_4 == 0)
{
Write_Text(" ",0,2);
Write_Text("8",0,2);
while(ROW_4 == 0);
}

KEY_PORT = 0xff;
COL_3=0;
if(ROW_1 == 0)
{
Write_Text(" ",0,2);
Write_Text("9",0,2);
while(ROW_1 == 0);
}
if(ROW_2 == 0)
{
Write_Text(" ",0,2);
Write_Text("10",0,2);
while(ROW_2 == 0);
}
if(ROW_3 == 0)
{
Write_Text(" ",0,2);
Write_Text("11",0,2);
while(ROW_3 == 0);
}
if(ROW_4 == 0)
{
Write_Text(" ",0,2);
Write_Text("12",0,2);
while(ROW_4 == 0);
}

KEY_PORT = 0xff;
COL_4=0;
if(ROW_1 == 0)
{
Write_Text(" ",0,2);
Write_Text("13",0,2);
while(ROW_1 == 0);
}
if(ROW_2 == 0)
{
Write_Text(" ",0,2);
Write_Text("14",0,2);
while(ROW_2 == 0);
}
if(ROW_3 == 0)
{
Write_Text(" ",0,2);
Write_Text("15",0,2);
while(ROW_3 == 0);
}
if(ROW_4 == 0)
{
Write_Text(" ",0,2);
Write_Text("16",0,2);
while(ROW_4 == 0);
}


}
}

void Delay(void)
{
int j;
int i;
for(i=0;i<10;i++)
{
for(j=0;j<10000;j++)
{
}
}
}

void Write_Text(char* str,int x, int y)
{
while(*str!='')
{
Write_Char(*str,x,y);
x++;
str++;
}
}

void Init_LCD(void)
{
RS = 0; //CLR RS
PDATA = 0x34; //MOV PDATA,#00110100b
EN = 1; //SETB EN
EN = 0; //CLR EN
Wait_LCD(); //LCALL WAIT_LCD

RS = 0; //CLR RS
PDATA = 0x3C; //MOV PDATA,#00111100b
EN = 1; //SETB EN
EN = 0; //CLR EN
Wait_LCD(); //LCALL WAIT_LCD

RS = 0; //CLR RS
PDATA= 0x0C; //MOV PDATA,#0Ch
EN = 1; //SETB EN
EN = 0; //CLR EN
Wait_LCD(); //LCALL WAIT_LCD

RS = 0; //CLR RS
PDATA= 0x06; //MOV PDATA,#06h
EN=1; //SETB EN
EN=0; //CLR EN
Wait_LCD(); //LCALL WAIT_LCD
}


void Clear_LCD(void)
{
RS = 0; //CLR RS
PDATA = 0x01; //MOV PDATA,#01h
EN = 1; //SETB EN
EN = 0; //CLR EN
Wait_LCD(); //LCALL WAIT_LCD

}


void Wait_LCD(void)
{
EN = 0; //CLR EN
RS = 0; //CLR RS
RW = 1; //SETB RW
D7 = 1; //MOV PDATA,#0FFh
EN = 1; //SETB EN
while(D7)
{
EN = 0;
EN = 1;
}
//MOV A,PDATA
//JB ACC.7,WAIT_LCD
EN = 0; //CLR EN
RW = 0; //CLR RW
}

void Write_Char(unsigned char c,int x, int y)
//x is 0 to 15 horizontal position of character.
//y is 1 for first line, 2 for second line.
{
int location;
if(y==1)
{
location = 0x80 + x;
}

if(y==2)
{
location = 0x80 + 0x40 + x;

}
RS = 0; //CLR RS
PDATA=location; //MOV PDATA,#0C4h
EN = 1; //SETB EN
EN=0; //CLR EN
Wait_LCD(); //LCALL WAIT_LCD

RS = 1; //SETB RS
PDATA = c; //MOV PDATA,A
EN = 1; //SETB EN
EN = 0; //CLR EN
Wait_LCD(); //LCALL WAIT_LCD
}


Shopping Cart more
0 items
What's New? more
Flowcode 7 for PIC, AVR, Arduino, ARM - Academic 50 User
Flowcode 7 for PIC, AVR, Arduino, ARM - Academic 50 User
US$1,727.00
Specials more
2N3906 PNP Transistor, 200mA/40V, TO-92 (10 pack)
2N3906 PNP Transistor, 200mA/40V, TO-92 (10 pack)
US$1.10
US$0.59
Bestsellers
01. RFID ISO Card Tag, 125kHz, EM4102 Read-only
02. PIC16F628A-I/P Microcontroller, 18 DIP, 20 MHz
03. Atmel ATtiny2313-20PU AVR Microcontroller, 20 DIP, 20 MHz
04. LCD 4-mux, 7 digits x 14 segments, progress bar, arrows
05. LCD 4-mux, 7.1 digits x 7 segments, progress bar, arrows
06. USB Universal In-Circuit Programmer PIC AVR ARM MSP 8051 EEPROM
07. ARM JTAG Debugger & Programmer, parallel port
08. Power Supply 3-12V DC, US/UK/Euro/AU Plugs, 100-240VAC
09. Power Supply 3-12V DC, U.S. plug, 6 connection tips
10. Atmel AVR JTAG In-Circuit Debugger & Programmer, USB
Reviews more
Microchip PIC Prototyping PCB with RS232 and ICSP, 40-pin, 20MHz
Can't beat the price for an assembled proto board ready to r ..
5 of 5 Stars!
  Saturday 18 November, 2017   List of all our Products

Copyright © 2003-2017 MicroController Pros LLC
Powered by osCommerce