Tag Archive: STK500


Wireless Remote Module #2: LCD Display

Ahh, it’s been too long since I’ve updated this. As you can guess from the title, module #2 for my wireless media remote is complete. Well, module #3 is ready too, but I’ll put that in another post later on. (Don’t tell anyone, but so is module #4. I’m actually up to building it on prototype boards as opposed to my bread board)

A few weeks ago, I went down to Jaycar and picked up a few things. One of them being a 16×2 LCD character display. Key code QP-5512.
As it turns out, this particular LCD character display from Jaycar, has no datasheet. Which is quite in convenient for anyone, especially someone just learning about micro-controllers. After many hours of research, I found this: Oz electronic forums where several board members figured out its wiring and instruction sets. For the PICAXE.
Now this is wonderful…Except its code is in PICAXE Assembly syntax.

First things first, let’s wire up the circuit. I opted for 460 ohm current limiting resistors because that’s just what I had with me.

D0 -> D3 are the data lines. Because i opted to use the LCD in 4 bit mode, we only need 4 of the data lines for data transmission. EN is the enable line and RS is register select. The 10k trim pot on line 3 is contrast adjustment.

Onto the code. Once again, I would like to point out that this isn’t exactly all my code. The structure and implementation of it in C is, but the enabling and writing to the LCD logic is thanks to SABorn at ozeleforum (See above link).

LCDSource

Compile it, upload it and run it. Works a charm eh?

Note it is displaying the current playing song from my PC. See the serial connection? I’m tying them slowly together… More on this in later posts though.

I have actually found that on the enable pulses, you can decrease the delay to 35 us. This may cause some slight unstable reactions, but I have never had a problem with it. Just don’t go any faster.

Now, I liked this so much, I decided to put my screen on a prototype board.

So that’s pretty much it for now. Chew on that while I get bothered to write up more on the next few modules.

EDIT:
Here is the instruction set for the LCD screen:
DisplayOff = 8
DisplayOn = 12
Home = 2
Clear = 1
Start of line 1 = 128
End of line 1 = 145
Start of line 2 = 192
End of line 2 = 209
Master reset = 0
Scroll screen left to right = 5
Scroll screen right ot left = 7
Screen off = 4
Display top line only = 32
Display both lines = 44
Cursor on = 14
Cursor off = 12
Cursor Blink = 15

Thanks to SABorn @ Oz Electronic Forum.

Nothing amazing here really. This kinda stuff you can do from numerous walk throughs on the interwebs.

The AtMega8515L was the chip used connected to a STK dev board. If you want to use just the chip on your own bread board, you will need a MAX232 chip to convert the TTL logic levels to the +30V required for serial data transmission. Thankfully the STK does this for me while I wait for my MAX232 chips to arrive.

PORTD pins 0 and 1 are the USART data transmission lines that need to be connected to the MAX and then through to the Serial connector.
Next I used PORTA for input into my micro controller. Utilising the onboard switches from the STK. It should be noted that the switches are active-low. Refer to the STK500 user manual for the wiring diagram to set it up switches on a separate breadboard.

Once all this is wired up, it’s time for some maths! 😀

Here, we need to calculate the UBRRL register that corresponds to our “Baud” rate of our serial communications. This is basically the bits per second that the data will be transmitted.

Ok.

Lets  pick an arbitrary baud rate. Say, 9600 b/s. Good number, commonly used in serial communications. Makes things easier to do when it’s the standard.
Right, using a formula in the AtMega8515L user manual we get:

UBRRL = (f_osc)/(16*baud) – 1

See? It’s simple really. f_osc is the frequency that our chip is running. So in my case, 3.6864 MHz.
We throw all this in together and what do we get? 23!

Oh, if your lazy, there is a table of common baud rates, clock freqs and UBRRL values on page 160… But knowing that formula makes you seem that much smarter…

Right, We’ve done the maths, done the hardware, let’s do the code!
First, let’s get the AtMega8515L sending data.

Fire up AVR Studio and make a AVRGCC project. In this case I decided to steer clear from assembly just because I can do conditional things easier in C.

ok, source code!

Source

The USART initialisation and transmit functions are supplied from the AtMega8515L user manual, I take no credit for either of these two functions.
As you can see I’m setting the USART active with the baud setting of “23” (remember calculating that?) and initialising it. Then in an infinite loop (Sorry, no interrupts yet) I grab input from PORTA and compare it to masks set up. Then transmits an ASCII code to the Serial interface. The “trans” if/else statement is to ensure the data is only sent once, at the initial key stroke. Just makes receiving the data a bit easier.

Ok. Flash the program into your board! Hook it up to your PC using a serial cable, or in my case a serial to USB adapter, and turn it on!

Remember, its not going to do anything yet! Nothing on the computer is waiting for input.
At this point, download and install “hyperterminal“. Just use the free 30 day trial for now, if you use it more and more, why not grab it for real, yo? Or if you want the free open source option (My choice) use “Putty“.

Ok, install, open, create a connection to your comport. Mine was comm3, but yours may be different. The set up is 9600 baud, no parity bit, 8 bytes of data and stop bit is 2. Hit connect.

Now, this is the fun bit, press a button and see if the corresponding ASCII code turns up on the screen. If so, Well done! If not, Get your troubleshooting hat on and go for it. 🙂 I’m not gonna do everything for ya.

Right, The micro controller is talking to the PC, Now, lets make the PC do something with the commands!

For this, I chose to use Visual Basic 6.0. Out dated, yes, but a simple language that easily allows comport data retrieval. Also, I’m using it to control my music. Now I use a slightly obscure media player called MediaMonkey. I highly recommend it, but that’s a different conversation entirely. MediaMonkey has an importable object that allows VB programs to control it and get data from it, handy actually.

Ok, Create a new .EXE. Import the MSCOMM object, add to the form a MSCOMM object and a timer. Set timer interval to, say, 100. Enter in the code given below.

Source

As you can see, I’m using a timer to ask the MSCOMM object if something is new. I tried it on the data receive event, but for some reason all I got was garbage. I’m gonna look into that a lot more in the coming days…

Right, Simple eh?

Works? Music changes? (For Media Monkey Users it should). Add your own commands! Play around.

Next on the cards is a wireless media remote that displays the current playing song via a 2×16 LCD display. This one’s gonna take me a while…
I’ll keep you posted!

Have Fun.

UPDATE: Fixed up some code, added more comments to code.