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.

Unicorn GLCD demo.

Status
Not open for further replies.
As far as I am aware the only changes I have made to the original code are making i local and adding the circle routine. Anyway, good to see it's now working.

Edit, if you put back the ClearScreen you should have the image from earlier.

Mike.
 
Last edited:
Pommie when the bars go up when the percentage rises, thats okay. However when i pull down the percentage values, the previous bars are still sticking out there. Should i call ClearScreen each time i update them, have tried this but it flicks a lot this way :(
 
To stop flicker try,
Code:
void PutBars(unsigned char x,unsigned char y,unsigned char Percent){
unsigned char i,j;
        for(i=0;i<10;i++){
            if(i<(100-Percent)/10){
                for(j=x+i;j<x+11;j++)
                    unplot(j,y+2*i);
            }else
                vline(x+i,x+10,y+2*i);
        }            
}

You will also have to add unplot,
Code:
void unplot(unsigned char x,unsigned char y){
unsigned char d;
    if(x>127 || y>63)
        return;
	if(x>63){
		b_GLCD_GCS1=0;
		b_GLCD_GCS2=1;
		x-=64;
	}
	else
	{
		b_GLCD_GCS1=1;
		b_GLCD_GCS2=0;
	}
	GLCD_Write_Cmd(0x40+x);			//write column address
	GLCD_Write_Cmd(0xb8+(y>>3));	//write row address
	d=GLCD_Read_Data();				//dummy read
	d=GLCD_Read_Data();
	GLCD_Write_Cmd(0x40+x);			//write column address again
	d=d|(1<<(y&7));
	GLCD_Write_Data(d);
}

Mike.
 
pommie has a point.. if you get time wire up your lcd and try it... if you cant then ill try to later on after work...

Its working now Atom :) Even on Proteus. Also he sent images of his LCD which proves both are working (Proteus and Hardware)

I think my GLCD library was old. As soon as i included his files, the code he sent for bars started working.
 
hey it had to be something :D glad it works and great job pommie... one thing tho? can you post updated code pommie :)

update: i would love to port it over to other lcds
 
Last edited:
heh i didnt even notice all the post above silly me.. my browser was either slow or you all wrote so quick heh

pommie 1 thing... no complaint but for header files i would recommend you use:

#include <p18cxxx.h>

for easy porting
 
Hi Jason,

I should really rewrite all of it. It's all a bit flaky and there are some routines I should add. Did you have a look at the circle routine, that is a tricky one to work out.

Mike.
 
pommie the code looks minimal but very effective :) i would have never got it... i guess these are things ill learn when i goto college (some math) heh
 
just saying great job again pommie i tried this code and it looks so cool:
Code:
        for(i=0;i<11;i++){
            PutBars(108,40,(i*10));
            Delay10KTCYx(10);
        }

        for(i=11;i>0;i--){
            PutBars(108,40,((i-1)*10));
            Delay10KTCYx(10);
        }
 
just saying great job again pommie i tried this code and it looks so cool:
Code:
        for(i=0;i<11;i++){
            PutBars(108,40,(i*10));
            Delay10KTCYx(10);
        }

        for(i=11;i>0;i--){
            PutBars(108,40,((i-1)*10));
            Delay10KTCYx(10);
        }

You catch on fast. That's a good demonstration.

Mike.
 
Code:
void main (void)
{
	int i;
	unsigned int temp;
	unsigned float temperature;
	char str[40];
	
	ADCON0 = 0x01;
	ADCON1 = 0x0e;
	ADCON2 = 0xbe;
	CMCON=7;
	
	TRISAbits.TRISA0 = 1;
	
	glcd_Init();

	while (1)
	{
		// Clear LCD screen
		glcd_ClearScreen();
		glcd_SetPosition(0, 0);
		
		// Do A/D conversion
		ADCON0 |= 0x02;
		while(ADCON0 & 0x02);
		
		// Read higher part of digital data
		temp = (unsigned int) ADRESH;	// Always zero since LM35 outputs only 0.18V
		
		// Multiply by 256
		     if (temp == 1) temp = 256;
		else if (temp == 2) temp = 512;
		else if (temp == 3) temp = 768;
		
		// Add lower part
		temp += (unsigned int) ADRESL;
		
		// Convert digital data to Celcius
		temperature = 0.48828f * (unsigned float) temp;
		
		// Format the string
		//sprintf(str, "The temp is: %u", (unsigned int) temperature);
		sprintf(str, "The temp is: %f", (signed float) temperature);
		
		// Show temperature on the screen
		glcd_PrintRAMString(str);	// Print the string on the LCD
		
		// Delay before next update
		for (i=0; i<5; i++) Delay10KTCYx(0);
	}
}

This one doesn't work:
Code:
	// Format the string
		//sprintf(str, "The temp is: %u", (unsigned int) temperature);
		sprintf(str, "The temp is: %f", (signed float) temperature);
Output: "The temp is:"

Since this one works:
Code:
	// Format the string
		sprintf(str, "The temp is: %u", (unsigned int) temperature);
		//sprintf(str, "The temp is: %f", (signed float) temperature);
Output: "The temp is: 17"

I know this question will not be related to this topic, but why can't I convert float variables to string using sprintf()?
 
Last edited:
Unfortunately, the C18 version of sprintf does not support floating point.

Mike.
 
Unfortunately, the C18 version of sprintf does not support floating point.

Mike.

Code:
unsigned float temp, frac;
unsigned int decimal, fraction;
char str[7];

temp = 1.2345f;					// A sample temperature value
decimal = (unsigned int) temp;		// Get decimal part of temperature
frac = temp - (unsigned float) decimal;	// Get fractional part of temperature
fract *= 10000;					// 4-digits after period
fraction = (unsigned int) fract;		// Convert fractional part to integer

glcd_PutMessage((rom char *) "The temperature is: ");
sprintf(str, "%d", decimal);
glcd_PutRAMMessage(str);
glcd_PutChar('.');
sprintf(str, "%d", fraction);
glcd_PutRAMMessage(str);

This is a solution I found at the moment. Unfortunately I am not able to try it right now, I'm at work now. Do you have any other suggestion?
(Note: glcd_PutRAMMessage() is same as PutMessage(), the only difference is that it prints a string which is in RAM memory.)
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top