Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

display units and tens

Status
Not open for further replies.

hhhsssmmm

New Member
hello

I have successfully interfaced a PIC18F4423 and DS1307 via I2C interface using C18. For now I can read the seconds ticking away and can partailly dispay them on a 20x2 LCD.

Now let me explain my problem.

I can not get the 'units' (right most digit of the second) to roll over back to '0' after it passes '9'. I know i have to break the byte variable in to two nibbles but i try and i get garbage with 'units' after the count passes 9....it starts showing HEX numbers A to F and then random ASCII characters. The left most digit ('tens') I can display perfectly and they even roll over after passing '5' ... (0 - 5).

Below is my code segment where im breaking the 'seconds' byte variable into two nibbles...plz can someone take a look at it and kindly sugget a fix for this problem.

Thank you

Haseeb

Code:
//DISPLAYING the 'TENS' of the second
        HIGH_nibble = seconds;        
        HIGH_nibble = HIGH_nibble >> 4;
        //convert ASCII
        HIGH_nibble += '0';     
        SendLCD(0x80,0); //activate LCD line 1 ... Column 1                         
        //display on LCD
        SendLCD(HIGH_nibble,1);  
       


        //DISPLAYING the 'UNITS' of the second
        seconds = seconds << 4;
        //convert ASCII
        seconds += '0';     
        SendLCD(0x81,0); //activate LCD line 1 ... Column 2                     
        //display on LCD
        SendLCD(seconds,1);
 
hello

I have successfully interfaced a PIC18F4423 and DS1307 via I2C interface using C18. For now I can read the seconds ticking away and can partailly dispay them on a 20x2 LCD.

Now let me explain my problem.

I can not get the 'units' (right most digit of the second) to roll over back to '0' after it passes '9'. I know i have to break the byte variable in to two nibbles but i try and i get garbage with 'units' after the count passes 9....it starts showing HEX numbers A to F and then random ASCII characters. The left most digit ('tens') I can display perfectly and they even roll over after passing '5' ... (0 - 5).

Below is my code segment where im breaking the 'seconds' byte variable into two nibbles...plz can someone take a look at it and kindly sugget a fix for this problem.

Thank you

Haseeb

hi,
I use asm not 'C' but the method is the same.

If you have a binary value for the seconds 00 thru 59 [ 0x00 thru 0x3b]
Take the modulus of 10 so, Unitsecs= seconds MOD 10 [0x0a] this will give the seconds units, so convert to ascii

Now dividing the seconds by 10 [0x0a] will give you the tens of seconds, convert to ascii
 
Last edited:
If the "seconds" variable is indeed in "packed BCD" format then this line;
Code:
seconds = seconds << 4;
should be changed to this;
Code:
seconds = seconds & 15;
 
Last edited:
hello and thank you so much for all your inputs


However...

pasanlaksiri wrote...

Hi, You have to Convert BCD to Decimals.

I do not understand this since the DS1307 already provides BCD format and all we have to do is convert it to ASCII and dump the output to LCD.

Can you please clearify??

Anyway here is my fixed code and im now happy that the seconds are displaying very nicely and ticking away from 00-59 and then rolling over again to 00 and starting again...


Code:
//EXTRACTING the 'TENS' of the second & converting it to ASCII for LCD
		HIGH_nibble = BCD; 		
		HIGH_nibble = (HIGH_nibble >> 4) + '0';		
	
		//EXTRACTING the 'UNITS' of the second & converting it to ASCII for LCD
		BCD = (BCD & 0x0F) + '0';

		//activate LCD line 1 & display 'TENS' in Column 1 
	    SendLCD(0x80,0);                      			
		SendLCD(HIGH_nibble,1);   	
		
		//activate LCD line 1 & display 'UNITS' in Column 2	
	    SendLCD(0x81,0); 
		SendLCD(BCD,1);

Thanks so much again
Haseeb
 
hi haseeb,
The DS1307 outputs packed BCD, so your 'unpack' and convert to ASCII routine looks ok.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top