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.

preferred C compiler?

Status
Not open for further replies.

ManTic

New Member
Hey... I've been playing a bit with PIC16F877A and C, but with the compiler I use, i cannot send variables to the LCD...

The function i use looks like this:

Code:
void lcd_display(const char *buf)
{	
	char i;
	i = 0;
	while(buf[i] != 0)
	{
		wrdata(buf[i++]);
	}
}

Where wrdata is:

Code:
void wrdata (char data)
// Write a Character to the LCD Display. 
 { trisb = 0;
   portb = data;
   
   porte = LCD_DATA_WR;
   porte |= E_PIN_MASK;
   nop();
   porte &= ~E_PIN_MASK;
   
   lcd_wait();
 }

And lcd_wait(), just waits for the busy flag to go down...

It works with constants.. of course - but it would be nice if I could write a variable to the LCD - results of calculations and stuff..
 
Which compiler?
 
SourceBoost C/C++ compiler, but I found a way around my problem, thanks anyway.
 
Its fairly easy to write a simple printf function to write to your LCD.

Code:
void xprintf(unsigned char* fmt, ...)
{
	va_list ap;				//Argument Pointer
	unsigned char* p;
	unsigned char Bval;
	unsigned int ival, temp;
	unsigned long lval;
	va_start(ap, fmt);
	p = fmt;
	while (*p)
	{

		switch (*p)
		{
			case '\n':
				EA = 0;
				putchar('\n');
				putchar(0x0D);
				EA = 1;
				break;
			case '%':
				
				p++;
				switch (*p)
				{
					case 'x':
						ival = va_arg(ap,int);
						//if ((unsigned char) ival >> 8)
						//{
							EA = 0;
							PrintHex((unsigned char) (ival >> 8));
							EA = 1;
						//}
						/*
						EA = 0;
						PrintHex((unsigned char) ival);
						*/
						EA = 1;
						break;
					case 'd':
						ival = va_arg(ap, int);
						EA = 0;
						putint(ival);
						EA = 1;
						break;
					case 'l':
						lval = va_arg(ap, long);
						//if ((unsigned char) lval >> 24)
						//{
							EA = 0;
							PrintHex((unsigned char) (lval >> 24));
						//}
						//if ((unsigned char) lval >> 16)
						//{
							PrintHex((unsigned char) (lval >> 16));
						//}
						//if ((unsigned char) lval >> 8)
						//{
							PrintHex((unsigned char) (lval >> 8));
						//}
						PrintHex((unsigned char) lval);
						EA = 1;
						break;
					case '%':
						EA = 0;
						putchar('%');
						EA = 1;
						break;
				}
			break;

			default:
				EA = 0;
				putchar(*p);
				EA = 1;
				break;

			}
			p++;

	}
	va_end(ap);
}

just replace all the putchars and printhexes with you LCD writing code

Brent
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top