Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Thread Closed: Off-topic

???
07/12/03 14:24
Read: times


 
#50549 - 16bit hex to 8bit bcd, key trapping?
hello ppl,
i could do with some help pls. my config is

keil/AT89C52 ( ansi C)
4 X 3 matrix keypad
LM016L LCD
DS1306 RTC
Flight32 micro controller trainer


my problem:
i want to convert 4 keypresses into 2 bcd bytes, my program is a state machine, the keypad is interrupt driven, i cant get my head round how to trap 4 keypresses, convert the keypresses into 2 bcd bytes.

IE if 2 keypress = 12 (0x31,0x32)
the rtc needs bcd bytes to be written to
so these two bytes need to be converted to one bcd byte

no problem
high_nibble=keypress & 0F;
keypress<<=4;

low_nibble=keypress & F0;
bcd_byte=high_nibble | low_nibble;

bcd_byte now equals 12 (bcd)

my problem is how do i trap the keypresses?

some code ive written is below

case ADMIN:
{
admin_choice = key;
delay(5);
switch(admin_choice)
{
case '1':
{
lcd_write_string("Update Time");
delay(3000);
lcd_write_cmd(0x01); //reset display
lcd_write_string("Enter time in this format XX.XX where X");
delay(2000);
for(loop = 0; loop < 32 ; loop++)
{
lcd_write_cmd(0x18);
delay(300);
}
lcd_write_string("is 00/23(hrs) & 00/59(mins)") delay(100);
for(loop = 0; loop < 29 ; loop++)
{
lcd_write_cmd(0x18);
delay(300);
}
lcd_write_cmd(0x01); //reset display
lcd_write_cmd(0x80);
delay(2000);
not sure what should happen here!!!!!
break;
}

//convert hex to BCD and write to rtc
void hex_to_bcd(byte )
{
byte data high_nibble=0,low_nibble=0,update_min_byte=0;
byte data update_hrs_byte=0;
byte data keypress1=0,keypress2;


delay(1000);
lcd_write_disp(key);
delay(500);
keypress1 = key;
high_nibble = key & 0x0F;
high_nibble<<=4;
delay(1000);
while(keypress1==key);
{
keypress2 = key;
lcd_write_disp(key);
delay(500);
low_nibble = key & 0x0F;
update_hrs_byte = high_nibble | low_nibble;
delay(1000);
}


//writing sequence of the real time clock
//time
write_3w(0x8F, 0x00); //disable write protect
write_3w(0x8F, 0x04);
//write_3w(0x82, update_byte); //write sec
write_3w(0x81, update_min_byte); //write min
write_3w(0x82, update_hrs_byte); //write hrs
write_3w(0x8F, 0x44); //enable write protect
}


thanks in advance, if ive left out any info please ask me, please ignore incorrect variables passed into write_3w

luigi


List of 8 messages in thread
TopicAuthorDate
16bit hex to 8bit bcd, key trapping?            01/01/70 00:00      
   RE: 16bit hex to 8bit bcd, key trapping?            01/01/70 00:00      
      RE: 16bit hex to 8bit bcd, key trapping?            01/01/70 00:00      
   RE: 16bit hex to 8bit bcd, key trapping?            01/01/70 00:00      
   16bit hex to decimal :            01/01/70 00:00      
      RE: 16bit hex to decimal :            01/01/70 00:00      
         RE: 16bit hex to decimal :            01/01/70 00:00      
            RE: 16bit hex to decimal :            01/01/70 00:00      

Back to Subject List