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.

display units and tens

Status
Not open for further replies.

hhhsssmmm

Member level 1
Joined
May 14, 2009
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,732
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

hhhsssmmm

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

The least significant digit of the seconds is stored in the lower 4 bits (0-3). In your code for the 'units' you are shifting it into the upper 4 bits before adding the '0'. Remove the line " seconds = seconds << 4;" and it should work.
 

i recommend to use separate bytes for unit and ten.
 

thank you so all so much for ur kind input

I have solved the problem and here is the 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...

problem was simply not breaking up the BCD bytes properly into the respective nibbles

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
hhhsssmmm
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top