HELP(keypad to 7segment multiplexing problem)

Thread Starter

chychy1

Joined Jan 9, 2012
2
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 6 numbers and display in the 7 segment using multiplexing ., 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.,
(e.g. when the inputted data from the keypad is 702403 the our 6 7 segments only displays 000000):confused:

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=6;
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);

}
 

RiJoRI

Joined Aug 15, 2007
536
(1) Use the [ code ] and [ /code ] markers (without the spaces) to make your code more legible.
(2) What is the size (in bits) of a short?
(3) What are you trying to accomplish with
Rich (BB code):
		x *= kp;
		num1+=x;
		x/=10;
(4) Surely there is a better algorithm for what you are trying to do than
Rich (BB code):
		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;
--Rich
 
Top