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.

HELP(keypad to 7segment multiplexing problem)

Status
Not open for further replies.

chychy

Newbie level 5
Joined
Jan 9, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,353
hello., nice eve everyone., we've been working on a project., but we got some problem in getting the data from the keypad., we need to get 8 numbers and display in the 7 segment using multiplexing:evil::evil:., can anyone help us in fixing the problem., here's our code below., thanks alot., we're really new in programming., so any help will be greatly appreciated.,


unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
} //case end
}
#include keypad.h
unsigned short kp,i,x,num1,ones, tens, hundreds, thousands, tthousands, hthousands, NUM;
void main() { // Reset counter
Keypad_Init(&PORTD); // Initialize Keypad
PORTB=0;
TRISB=0;
PORTC=0;
TRISC=0;
i=8;
x=100000;
num1=0;
do {
kp = 0; // Reset key code variable

// Wait for key to be pressed and released
do
kp = Keypad_Released(); // Store key code in kp variable
while (!kp);
switch (kp) {

case 1:kp=1; break; //
case 2:kp=2; break; // 2
case 3:kp=3; break; // 3
case 4: // kp = 65; break; // A for 4x4 pad
case 5:kp=4; break; // 4
case 6:kp=5; break; // 5
case 7:kp=6; break; // 6
case 8: //kp = 66; break; // B for 4x4 pad
case 9:kp=7; break; // 7
case 10:kp=8; break; // 8
case 11:kp=9; break; // 9
case 12:
case 13:
case 14: kp=0; break; // 0
case 15:
case 16: kp = 67; break; // D for 4x4 pad
}

x*=kp;
num1+=x;
x/=10;
i--;


} while (i!=0);
do {
NUM = num1; // initial value ra ni
ones = NUM%10; // Extract Ones Digit
tens = (NUM%100-3)/10; // Extract Tens Digit
hundreds = (NUM%1000-(tens*10)-ones)/100; // Extract Hundreds Digit
thousands = (NUM%10000-(hundreds*100)-(tens*10)-ones)/1000;
tthousands = (NUM%100000-(thousands*1000)-(hundreds*100)-(tens*10)-ones)/10000;
hthousands = (NUM%1000000-(tthousands*10000)-(thousands*1000)-(hundreds*100)-(tens*10)-ones)/100000;

ones = mask(ones);
tens = mask(tens);
hundreds = mask(hundreds);
thousands = mask(thousands);
tthousands = mask(tthousands);
hthousands = mask(hthousands);

PORTB = hthousands;
PORTC = 0b000001; // Select hundred thou Digit
delay_ms(500);
PORTB = tthousands;
PORTC = 0b000010; // Select ten thousands Digit
delay_ms(500);
PORTB = thousands;
PORTC = 0b000100; // Select thousands Digit
delay_ms(500);
PORTB = hundreds;
PORTC = 0b001000; // Select hundreds Digit
delay_ms(500);
PORTB = tens;
PORTC = 0b010000; // Select ten Digit
delay_ms(500);
PORTB = ones;
PORTC = 0b100000; // Select ones Digit
delay_ms(500);


} while(1);

}
 

Can you please elaborate that what do you want? are you experiencing some problem in code?
 

it wont display in the 8 7segment... for instance i press 702403... it only displays 000000.....

---------- Post added at 18:55 ---------- Previous post was at 18:52 ----------

i=6... i type it wrong...
 

whats that., ok., tnx., ill try to read whats on that link., :)
 

First of this is what I understand from your code......you have 4x4 matrix key boad connected to some port from which you are intersted to scan 8 digit entries from the keyboard and inteded to display it on seven segment display.....please correct me if I am wrong .....also I don't understand why are u doing this x*=kp; i.e. x= x*kp
where x =100000; i think it should be 10000000; to display 8 digit number by multplication....but will not fit if you do not make x as float variable....


In my view check the last do while(1); loop.....it look like that the conversion for bit that you are getting is with 0 values only.....do this rather than using unsigned short ...try to use unsigned int or unsinged char routine..... also in myview if you are using PORTC = 0b000001; for control then it should come before the PORTB = hthousands; bcz your 7 segment will not be ON upto the time where you are sending the the data....however your delay function should mask it out the situation.... for me this look like conversion problem than interfacing.....

Also one request ....put your schematic too so that we can get better idea of what you are doing....may be we will able to solve the problem faster.....



Good Luck
 

First of this is what I understand from your code......you have 4x4 matrix key boad connected to some port from which you are intersted to scan 8 digit entries from the keyboard and inteded to display it on seven segment display.....please correct me if I am wrong .....also I don't understand why are u doing this x*=kp; i.e. x= x*kp
where x =100000; i think it should be 10000000; to display 8 digit number by multplication....but will not fit if you do not make x as float variable....


In my view check the last do while(1); loop.....it look like that the conversion for bit that you are getting is with 0 values only.....do this rather than using unsigned short ...try to use unsigned int or unsinged char routine..... also in myview if you are using PORTC = 0b000001; for control then it should come before the PORTB = hthousands; bcz your 7 segment will not be ON upto the time where you are sending the the data....however your delay function should mask it out the situation.... for me this look like conversion problem than interfacing.....

Also one request ....put your schematic too so that we can get better idea of what you are doing....may be we will able to solve the problem faster.....



Good Luck

its not 8. its 6., mistype. sorry., we use x*=kp so that the value of kp will be stored to x*100000 on the first loop...then on the 2nd loop the value of x*10000+num1 and so on and so forth.... thanks for the advice., heres our schematic diagram..
Untitled.png
 

I understood you logic ....I can suggest you to check the values of once tens hudrads etc when u enter the number in degug mode ....let say entered num is 1234 then u should get once-4, tens-3,hundrads-2 and thousands -1 in your whil(1) loop.....one small things is there is if your Keypad_Released function dose not operate on interrupt then you will not get the output in may cases.....what I will suggest you to modify you code like this....


void main() { // Reset counter
Keypad_Init(&PORTD); // Initialize Keypad
PORTB=0;
TRISB=0;
PORTC=0;
TRISC=0;
i=8;
x=100000;
num1=0;
do {
do {
kp = 0; // Reset key code variable

// Wait for key to be pressed and released
do
kp = Keypad_Released(); // Store key code in kp variable
while (!kp);
switch (kp) {

case 1:kp=1; break; //
case 2:kp=2; break; // 2
case 3:kp=3; break; // 3
case 4: // kp = 65; break; // A for 4x4 pad
case 5:kp=4; break; // 4
case 6:kp=5; break; // 5
case 7:kp=6; break; // 6
case 8: //kp = 66; break; // B for 4x4 pad
case 9:kp=7; break; // 7
case 10:kp=8; break; // 8
case 11:kp=9; break; // 9
case 12:
case 13:
case 14: kp=0; break; // 0
case 15:
case 16: kp = 67; break; // D for 4x4 pad
}

x*=kp;
num1+=x;
x/=10;
i--;


} while (i!=0);

NUM = num1; // initial value ra ni
ones = NUM%10; // Extract Ones Digit
tens = (NUM%100-3)/10; // Extract Tens Digit
hundreds = (NUM%1000-(tens*10)-ones)/100; // Extract Hundreds Digit
thousands = (NUM%10000-(hundreds*100)-(tens*10)-ones)/1000;
tthousands = (NUM%100000-(thousands*1000)-(hundreds*100)-(tens*10)-ones)/10000;
hthousands = (NUM%1000000-(tthousands*10000)-(thousands*1000)-(hundreds*100)-(tens*10)-ones)/100000;

ones = mask(ones);
tens = mask(tens);
hundreds = mask(hundreds);
thousands = mask(thousands);
tthousands = mask(tthousands);
hthousands = mask(hthousands);

PORTB = hthousands;
PORTC = 0b000001; // Select hundred thou Digit
delay_ms(500);
PORTB = tthousands;
PORTC = 0b000010; // Select ten thousands Digit
delay_ms(500);
PORTB = thousands;
PORTC = 0b000100; // Select thousands Digit
delay_ms(500);
PORTB = hundreds;
PORTC = 0b001000; // Select hundreds Digit
delay_ms(500);
PORTB = tens;
PORTC = 0b010000; // Select ten Digit
delay_ms(500);
PORTB = ones;
PORTC = 0b100000; // Select ones Digit
delay_ms(500);


} while(1);

}


taking do loop outside will mostly solve your problem as what is happening even you can pressed any key the it is going to while(1) loop with the best of my geasue....

Good Luck
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top