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.

[SOLVED] Cannot update time on LCD

Status
Not open for further replies.

Raady Here

Full Member level 5
Joined
Jun 8, 2013
Messages
242
Helped
26
Reputation
52
Reaction score
26
Trophy points
28
Location
India
Activity points
1,571
Cannot display properly on LCD

Hi,

I am trying to update time on LCD,
a structure ClockTime has variable Seconds, Minutes and Hours.
XLCDCommand and XLCDPutRamString are default syntax for command mode and send string to LCD respectively given by Microchip.

I wrote a loop as below

No Time is being displayed.

I tried converting int to char in three ways
(char) i
i + '0'
i + 48
but nothing works :-x
where can I be wrong ??


Code:
unsigned char Clock(void)
{
	if (ClockTime.Seconds < 59 ){          	// to check if seconds < 59?
		Delay_10ms(100);					// Delay of 1 sec
		++ClockTime.Seconds;               	// update seconds
	}
	else {                         			// if seconds => 59     
		ClockTime.Seconds = 0;          	// seconds = 0 and check minutes
		if ( ClockTime.Minutes < 59 )      	// if check minutes < 59?
			++ ClockTime.Minutes;           // updates minutes  
		else                     			// if minutes => 59
		{
			ClockTime.Minutes = 0;      	// minutes = 0 and check hours
			if ( ClockTime.Hours < 23 )    	// check if hours < 23
				++ClockTime.Hours;        	// update hours
			else ClockTime.Hours = 0;    	// Reset time	  
		}
	} 
	XLCDCommand(0xC8);
	XLCDPutRamString((char)ClockTime.Hours);
	XLCDCommand(0xCA);
	XLCDPutRamString(":");
	
	XLCDCommand(0xCB);
	XLCDPutRamString(ClockTime.Minutes+'0');
	XLCDCommand(0xCD);
	XLCDPutRamString(":");
	
	XLCDCommand(0xCE);
	XLCDPutRamString(ClockTime.Seconds+48);
}


I have warning as

timer.c:64: warning: passing argument 1 of 'XLCDPutRamString' makes pointer from integer without a cast
timer.c:69: warning: passing argument 1 of 'XLCDPutRamString' makes pointer from integer without a cast
timer.c:74: warning: passing argument 1 of 'XLCDPutRamString' makes pointer from integer without a cast
 
Last edited:

A few points come to mind ::

1) are you using a 16x2 LCD or a 16x1 LCD ? The commands & codes you have used are for the 2nd half of the 2nd line in a 2-line display. If you are using a 16x1 LCD, the you need to change "Cx" codes by "8x" codes everywhere.

2) If you ARE using a 16x2 and not getting any display at all, then this is most likely because you have not adjusted the contrast voltage properly. It is essential to adjust the contrast for getting any display.
 

I am using 16x2 LCD and I am trying to display in second line of code

In Second Line after running the program I see output as

Time : : ! ! : &! instead of Time: 00 : 59 : 00 ..

values are going in there but something conversions are going wrong way !!
 

You are converting integer like 59 which is wrong. 5 + '0' = '5' and 9 + '0' = '9'. 59 + '0' = 59 + 48 = 107.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
XLCDCommand(0xC8);
XLCDPutRamString((char)ClockTime.Hours/10 + '0');
XLCDCommand(0xC9);
XLCDPutRamString((char)ClockTime.Hours%10 + '0');
XLCDCommand(0xCA);
XLCDPutRamString(":");
XLCDCommand(0xCB);
XLCDPutRamString(ClockTime.Minutes/10 + '0');
XLCDCommand(0xCC);
XLCDPutRamString(ClockTime.Minutes%10 + '0');
XLCDCommand(0xCD);
XLCDPutRamString(":");
XLCDCommand(0xCE);
XLCDPutRamString(ClockTime.Seconds/10 + 48);
XLCDCommand(0xCF);
XLCDPutRamString(ClockTime.Seconds%10 + 48);

 

Ah good.

In that case, you should take serious note of the Warning messages at the end of your code list. Clearly the routine is expecting a pointer, but you are passing it a character. The routine nevertheless interprets this as a pointer & naturally the outputs garbage.

Secondly, each of your hours/ minutes/ seconds variables can consist of data ranging from '00' upto '59'
Note that this is TWO asciis symbols and not one ascii symbol.

You have to break-up the the number into 'tens' and 'units', add 48 to each and only THEN pass the concatenated 2 character string to the LCD routines via a pointer.

Think about it for a while ... i'm sure you'll get it.
 

In that case, you should take serious note of the Warning messages at the end of your code list. Clearly the routine is expecting a pointer, but you are passing it a character. The routine nevertheless interprets this as a pointer & naturally the outputs garbage.

Thank you guys for help,

I copied the data to a pointer variable and sent to LCD and that working.

I declared
char* Linebuf;

I modified as
sprintf(Linebuf,"Time: %.2d:%.2d:%.2d",ClockTime.Hours,ClockTime.Minutes,ClockTime.Seconds);
XLCDCommand(0xC0);
XLCDPutRamString(Linebuf);

Regards,
Raady.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top