Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

controlling array of leds from hex keypad

Status
Not open for further replies.

chaudhryali55

Member level 2
Joined
Jan 18, 2011
Messages
43
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Location
gujrat,pakistan
Activity points
1,529
Hi!

M newbie to this microcontroler programming .I need a help of how to control an array of led ..it is in programmer board,and m using mplab hi tech c compiler and ponyprog programm to burn it into the pic16f877


so all i need is that how can i write a c program to switch between leds that i want .for example from the hex keypad i press 1.when 1 is pressed the 1st led should be on and other leds should remain off..hex-keypad is included in my project.only i want to know how control individual led on the board..means the c programm ...thanks in advance
 

hi chaudhryali55,

you need to write the program that checks for the raws and column for the hex keypad

first u can check the raw
when raw is known you can check for column by knowing that the pressed key will be detected

---------- Post added at 12:54 ---------- Previous post was at 11:17 ----------

here is the sample code for hex keypad the code may not be exact but you can get idea through it


#define r1 PORTBbits.RB0 //raws of hex keypad
#define r2 PORTBbits.RB1
#define r3 PORTBbits.RB2
#define r4 PORTBbits.RB3

#define c1 PORTBbits.RB4 //columns
#define c2 PORTBbits.RB5
#define c3 PORTBbits.RB6
#define c4 PORTBbits.RB7

#define led1 PORTAbits.RA0
#define led2 PORTAbits.RA1
#define led3 PORTAbits.RA2
#define led4 PORTAbits.RA3
#define led5 PORTAbits.RA4
#define led6 PORTAbits.RA6



void main()
{
unsigned int key=0;
while(1)
{

if (r1==1) // checking raws
{
if(c1==1) //checking columns
key=1;
else if(c2==1)
key=2;
else if(c3==1)
key=3;
else
key=4;
}
else if(r2==1)
{
if(c1==1)
key=5;
else if(c2==1)
key=6;
else if(c3==1)
key=7;
else
key=8;
}
else if(r3==1)
{
if(c1==1)
key=9;
else if(c2==1)
key=0;
else if(c3==1)
key=a;
else
key=b;
}
else
{
if(c1==1)
key=c;
else if(c2==1)
key=d;
else if(c3==1)
key=e;
else
key=f;
switch(key) //displaying leds according to hex keypad
{
case1:led1=1;led2=0;led3=0;led4=0;led5=0;led6=0;
case1:led1=0;led2=1;led3=0;led4=0;led5=0;led6=0;
case1:led1=0;led2=0;led3=1;led4=0;led5=0;led6=0;
case1:led1=0;led2=0;led3=0;led4=1;led5=0;led6=0;
case1:led1=0;led2=0;led3=0;led4=0;led5=1;led6=0;
case1:led1=0;led2=0;led3=0;led4=0;led5=0;led6=1;
}
}
}
 
thnks sheryas it really help me ..but can we implement it this code ? and other question i have that does the programming of lcd differs for diffrent manufactures? and wat it his best and most used programmer board ?
 

yes chaudhryali,
the code can be easily implemented with some changes.
and about the programmer board, i am using PICKit3 its easy to use.
 

thanks sheryas ..m using mikro c Pro compiler along with pic simulator ide it is really going well with me...thanks again it really helped me...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top