0% found this document useful (0 votes)
3 views3 pages

Keypad

The document outlines the code for a project involving a keypad and LED control using a PIC16F887 microcontroller. It includes initialization of ports, a function to scan a 4x4 keypad, and a main loop that responds to specific key presses. The code is designed to execute different functions based on the key pressed, with specific actions tied to the keys '1' through '5' and '*'.

Uploaded by

hainguyen02196
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Keypad

The document outlines the code for a project involving a keypad and LED control using a PIC16F887 microcontroller. It includes initialization of ports, a function to scan a 4x4 keypad, and a main loop that responds to specific key presses. The code is designed to execute different functions based on the key pressed, with specific actions tied to the keys '1' through '5' and '*'.

Uploaded by

hainguyen02196
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

/******************************************************************************

* Project : EX6 - KEYPAD LAB - LED 7D

* MCU : PIC16F887

* Xtal : 4Mhz

* Complier: Hitech PIC C V9.83

******************************************************************************/

#define _XTAL_FREQ 4000000

#define KEY PORTC

#define LED_PORT PORTB

#define col_0 RC4

#define col_1 RC5

#define col_2 RC6

#define col_3 RC7

//-------------------------------------------------------//

void Port_Init()

ANSEL=0;

ANSELH=0;

TRISB=0;

TRISC=0xf0;

TRISD=0;

TRISA=0;

TRISE=0;

PORTA=0;

PORTB=0;

PORTC=0xff;

PORTD=0;

PORTE=0;}
//-------------------------------------------------------//

// READ KEYPAD 4x4 FUNCTION

//-------------------------------------------------------//

char scan_key()

{ char key_tab[4][4]= { '1', '2', '3', 'A',

'4', '5', '6', 'B',

'7', '8', '9', 'C',

'*', '0', '#', 'D'};

char scan_row[4]={0b00001110, 0b00001101, 0b00001011, 0b00000111};

char row=0;

for (row=0;row<4;row++)

KEY=scan_row[row];

if(col_0==0) { while(col_0==0); return key_tab[row][0]; };

if(col_1==0) { while(col_1==0); return key_tab[row][1]; };

if(col_2==0) { while(col_2==0); return key_tab[row][2]; };

if(col_3==0) { while(col_3==0); return key_tab[row][3]; };

return '\0';

}
//=======================================================//

// MAIN FUNCTION //

//=======================================================//

void main()

{ Port_Init();

PORTD=0xff;

while(1)

while(key_code!='1'&&key_code!='2'&&key_code!='3'&&key_code!='4'&&key_code!='5
'&&key_code!='*')

key_code = scan_key();

switch (key_code)

case '1': sangdan(); break;

case '2': sangduoi(); break;

case '3': sangtat(); break;

case '4': sangra2ben(); break;

case '5': sang2benvaotrong(); break;

case '*': tattled(); key_code='\0'; break;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy