ATMega128 Coding help with GLK240128-25

LK/ELK/VK/PK/OK/MX/GLK/EGLK/GVK/GLT Series

Moderators: Henry, Mods

illusion29
LCD!
Posts: 13
Joined: Mon Mar 15, 2010 5:36 pm

ATMega128 Coding help with GLK240128-25

Post by illusion29 »

Hey,

Not strong with coding yet as I am just getting use to the micro-controller

Was just wondering if there are some working sample codes I can look at or tutorials that will give me a good start? :)

From looking at the Manual

to send commands i.e. draw a line, it is simply just going:

txbuffer[] = { 0xfe 0x6c 1 1 1 1 };

and send that through serial to the LCD?

Thanks

Raquel
Matrix Orbital
Matrix Orbital
Posts: 796
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hello,

Thank you for posting on the forum.

I tried searching the forum for some coding samples for the ATmega128, but could not find any, but found this one.

What I suggest that you try first is to get your serial port working. Test it using a terminal emulator on a PC, eg Hyperterminal and see if you are successfully sending data from your Atmel. Once you have that going, then we can start looking at communicating with the display.
Raquel Malinis
Design and Development
Matrix Orbital

illusion29
LCD!
Posts: 13
Joined: Mon Mar 15, 2010 5:36 pm

Post by illusion29 »

Thanks for reply

I got it to communicate to the PC
and able to send one character

#include <avr/io.h>
#include <avr/interrupt.h>

#define BAUD 9600
#define SYSUBRR (F_CPU/16/BAUD-1)

#define BUF_SIZE 64

unsigned char txBuffer[BUF_SIZE];
unsigned char txindex;

// Function Declaration

void initUsart(void);
void initUsartTimer(void);
void SendUsart(unsigned char);


// ISR

void udreIsr(void);


ISR(USART0_UDRE_vect)

{

udreIsr();

}



// Main Program

int main(void)

{

txindex =0;
initUsart();
sei();


while(1)

{
//Loop forever
}




}

void initUsart()
{

//Set Baud Rate
UBRR0H = (unsigned char)(SYSUBRR>>8);
UBRR0L= (unsigned char)SYSUBRR;

//Enable Tx and Rx

UCSR0B =(1<<TXEN)|(1<<RXEN);

//Set Frame format : 8data, 1 stop bit, no parity

UCSR0C=(3<<UCSZ00);

// Set Interrupt for data register empty

UCSR0B |= (1<<UDRIE0);



}


void initUsartTimer()

{



}

void SendUsart(unsigned char data)

{

// Put data into Buffer and send the data

UDR0 = data;

}

void udreIsr()

{

SendUsart(txBuffer[txindex++]);

UCSR0B |=(1<<UDRIE0);



}





I am having trouble sending a text string
Tried declaring it as txBuffer[] = ' Hello World'
But doesnt seem to like that

Does anyone know how to do so?

Raquel
Matrix Orbital
Matrix Orbital
Posts: 796
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

There is a sample code in the ATmega128 on page 178. Try if that will make it better. I see that it needs to check UDRE bit in UCSRA register before writing to the UDR.
Raquel Malinis
Design and Development
Matrix Orbital

illusion29
LCD!
Posts: 13
Joined: Mon Mar 15, 2010 5:36 pm

Post by illusion29 »

Thanks for the reply

I got communication between PC and HyperTerminal
Able to send text string and receive input from the keyboard - so the transmit and receive USART is working

Now hooking it up to the LCD

Can I just powerup the LCD with the 4 pin connections i.e. 0 and 5 volts
and connect the RS232 to transmit/receive via Serial?

Or I have to choose one method, i.e. power at the 4 header but have to go serial with TTL or power through RS232 and serial through RS232?

On startup, the LCD is on the 'Matrix Obital Logo screen', How do I erase it so I can get the blank screen ? I don't mind the logo, but just want to go blank after 2 seconds or so.

Like say for the clear command, reading the manual says

Hex : 0xFE 0x58

At the moment my code is loading:

txstring[0] = 0xFE
txstring[1] = 0X58

and sending that through serial but the screen doesn't response to anything

I am able to send text to the Hyperterminal and it would display texts I am sending but connecting it to the LCD, the texts don't appear

Any sample code or help please

My code provided below:

Code: Select all


#include <avr/io.h>
#include <avr/interrupt.h>

#define BAUD 9600
#define SYSUBRR (F_CPU/16/BAUD-1)

#define BUF_SIZE  64

unsigned char txBuffer[BUF_SIZE]= " Poopy head I am the greatest";
unsigned char txBufferIndex;



// Function Declaration

void initUsart(void);
void initUsartTimer(void);
void SendUsart(unsigned char);


// ISR

void udreIsr(void);


ISR(USART1_UDRE_vect)

{

	udreIsr();

}



// Main Program

int main(void)

{

	OSCCAL = 0xC5;   // my particular 8MHz factory calibration.
	

	
	initUsart();
	sei();            


	while(1)

	{
		//Loop forever
	}




}

void initUsart()
{

// Setting some TxBuffer Values



//Set Baud Rate
UBRR1H = (unsigned char)(SYSUBRR>>8);
UBRR1L= (unsigned char)SYSUBRR;

//Enable Tx and Rx

UCSR1B |=(1<<TXEN1)|(1<<RXEN1);

//Set Frame format : 8data, 1 stop bit, no parity 

UCSR1C=(3<<UCSZ10);

// Set Interrupt for data register empty

txBufferIndex=0;

UCSR1B |=(1<<UDRIE1);   



}


void initUsartTimer()

{



}

void SendUsart(unsigned char data)

{

/* Wait for empty transmit buffer */
//	while ( !( UCSR1A & (1<<UDRE1)) )

			

				// Put data into Buffer and send the data

				UDR1 = data;

			

}

void udreIsr()

{

	if(txBuffer[txBufferIndex] != '\0')
		{

		SendUsart(txBuffer[txBufferIndex++]);

		}

	else

	{

		UCSR1B ^= (1<<UDRIE1);


	}

}	



Raquel
Matrix Orbital
Matrix Orbital
Posts: 796
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hi,

The display speed is default at 19200, I see that you have your code set at 9600. As for the 4 pin connector:

Vcc - connect this to 5V
RX - connect this to the TX of the ATmega128 via a RS232 transceiver
TX - connect this to the RX of the ATmega128 via a RS232 transceiver
Gnd - connect this to GND

or, you can put the display to TTL (take the 3 0-ohm res in 232 and put 2 in TTL, please see manual for this):

Vcc - connect this to 5V
RX - connect this to the TX of the ATmega128 (no need for transceiver)
TX - connect this to the RX of the ATmega128 (no need for transceiver)
Gnd - connect this to GND

Let me know how it goes.
Raquel Malinis
Design and Development
Matrix Orbital

illusion29
LCD!
Posts: 13
Joined: Mon Mar 15, 2010 5:36 pm

Post by illusion29 »

Hey thanks for the reply

I changed the Baud in MOGD# to 9600, so shouldn't be a problem there

Looking at the connections you provided,

Would I be able to connect the power through the 4 pin headers
Vcc : connect to 5V
GND : connect to ground

And for serial transfers, I'm not using the 4 pin header but using the RS232 port on the back of the LCD to a serial port on my ATMega development board STK500.

Would that still work?

Also, reading the troubleshooting area in the LCD manual for no text being shown. It mentions about uploading fonts onto the LCD, are defaults font already on the board?

Or I have to manually do it cause I assume there were fonts already on it since I was able to type text onto it using MODG#. When I attempt to upload a font, I get this screen pop up

Another question : If I switch to TTL mode, can I still connect the LCD to PC via the RS232 to use MOGD# or I would need to set the jumpers again to RS232 before doing so?

Cheers
Attachments
uploaderror.jpg
uploaderror.jpg (68.99 KiB) Viewed 14715 times

Raquel
Matrix Orbital
Matrix Orbital
Posts: 796
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hi,
Would I be able to connect the power through the 4 pin headers
Yes, this is how you power the display. Please see page 6 of the manual regarding the 4 pin connector (marked #5).
And for serial transfers, I'm not using the 4 pin header but using the RS232 port on the back of the LCD to a serial port on my ATMega development board STK500.
Yes, you can just use the 4 pin connector for power and gnd, and use the DB9 for RS232 communication, but please make sure you use a NULL serial cable to connect your STK500 to the display.
Also, reading the troubleshooting area in the LCD manual for no text being shown. It mentions about uploading fonts onto the LCD, are defaults font already on the board?
There should be 2 fonts pre-uploaded on the display.

For now, I will get you to do the following:
1. Make sure that the display is still on RS232 mode.
2. On your PC, open up Hyperterminal, 19200, 8 bits, no parity, 1 stop bit, no flow control
3. Power the display using the 4 pin connector.
4. Connect the display to the PC using a straight thru serial cable.
5. Start typing on hyperterminal and you should see the characters on the display.

Let me know how it turns out. We can then move on to connecting to the STK500 when you have successfully done the suggested steps above.

Thank you,
Raquel
Raquel Malinis
Design and Development
Matrix Orbital

illusion29
LCD!
Posts: 13
Joined: Mon Mar 15, 2010 5:36 pm

Post by illusion29 »

Hey thanks for the reply

What is a Null serial cable?

That might be the problem I am having, it could be the cable I am using to connect between the STK500 and the LCD. I am currently using a male to male serial cable between the STK500 and LCD. Cause the STK500 has a female DB9 output and the LCD has that too. If I just connect a male to male serial cable between the two? Would that work, or does it have to be a Null cable for it to work?

If so, not sure how to check...

About the Hyperterminal setup, so I just type on the Hyperterminal and it should start displaying text on the display?

Is there any extra setup I must do on the Hyperterminal? Like set it to echo what I am typing etc etc?

UPDATE : Connecting it to Hyperterminal is fine, I am able to type into Hypeterminal and it will appear on the LCD no problems

Raquel
Matrix Orbital
Matrix Orbital
Posts: 796
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

I clipped this from Wikipedia:

A null modem cable is an RS-232 serial cable where the transmit and receive lines are crosslinked. In many situations a straight through serial cable is used, together with a null modem adapter. The adapter contains the necessary crosslinks between the signals.

So, to check what you have, get an ohm-meter and check that pins 2 and 3 are cross linked on the two ends (instead of pin 2 of one end is connected to pin 2 of the other end, it should be connected to pin 3).

Good to hear that you are able to send characters via Hyperterminal. No need to worry about the mogd# problem for now, since you know that there is a font available for use.

I think a null modem cable / adapter is all you need.
Raquel Malinis
Design and Development
Matrix Orbital

illusion29
LCD!
Posts: 13
Joined: Mon Mar 15, 2010 5:36 pm

Post by illusion29 »

Well good news

Finally the board is communicating with the LCD and it now printing text to it.

Now for the fun part.

I want to do some simple animation on the LCD. I want to be able to animate a long rectangle block 180 degrees. Similar to a windscreen wiper on a car going back and forth.

What would you recommend the best approach to that ?

At the moment, would it just a frame by frame situation and erasing the previous frame?

Is there a command to erase only a certain section of the LCD or is it just using cheap methods like fill rectangle white a certain section of the screen ? :P

Cheers

Clark
Matrix Orbital
Matrix Orbital
Posts: 881
Joined: Fri Aug 17, 2007 10:58 am
Location: Matrix Orbital
Contact:

Post by Clark »

Hi Illusion29,

Great to hear you finally have your display up and running! The great part now is that the rest is up to you; you can create just about anything you can imagine, in any way you like.

But, for the purposes of your question, I have found that there are two extremes to creating animation on screen. First you can rely on the screen itself, saving a bunch of images to memory and calling them up one after another. At the other end, you can leave everything on the host side and make routines that paint out shapes by drawing pixels.

Generally, your first option is limited by display memory and the size of the animation and the second by your controller, communication speed, and coding ability.

I'd recommend some experiments with the draw filled, rectangle, line, and pixel commands, especially changing the color. Again, in the end what you create depends largely upon what you're comfortable with, so try out all of the commands available and see where they take you.

~Troy
Troy Clark
Design & Development
Matrix Orbital

illusion29
LCD!
Posts: 13
Joined: Mon Mar 15, 2010 5:36 pm

Post by illusion29 »

Thanks for the reply
and thanks for everyone that has helped me since the beginning

I shall give it a try

And post some images if I get it working

If I need help, shall post again

Cheers

illusion29
LCD!
Posts: 13
Joined: Mon Mar 15, 2010 5:36 pm

Post by illusion29 »

Another question:

I want to change the startup picture(Matrix Orbital logo) to another image.

1. Can I use MOGD# to upload an image?
2. Uploading a bitmap, does it resize the image file size?
3. How do I set it up as the startup image when I powerup on the LCD?
4. If I can't set it as startup, what command do I use to upload image to LCD through software?
5. If I replace the startup image, would I be able get the Matrix Orbital image back again?

Cheers
Last edited by illusion29 on Wed May 05, 2010 6:19 am, edited 1 time in total.

illusion29
LCD!
Posts: 13
Joined: Mon Mar 15, 2010 5:36 pm

Post by illusion29 »

*BUMP*

Post Reply