How to control a display (Batron MDL16265) with an ATmega microcontroller

Download display.c (4.3 KB)

Description

This code allows you to control a Batron MDL16265 LCD with an ATmega-µC (tested with ATmega128).
The display was available at Pollin Electronic.
It has two lines with 16 characters and is controlled via a 14pin cable.

To use this display, connect it this way to the controller:
Display pin 4 (RS) 5 (R/W) 6 (E) 7 (D0) 8 (D1) 9 (D2) 10 (D3) 11 (D4) 12 (D5) 13 (D6) 14 (D7)
Controller pin PD0 PD2 PD4 PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7

Of course you can change this pin assignment - in this case you'll need to change the port definitions in the source code too.

Note

This code was developed with an Atmel ATmega128 on a Ethernut board.
Nut/OS was used as the controllers operation system.
Links: www.ethernut.de, www.egnite.de

PWM with ATmega128 microcontroller

Description

This code activates the PWM function of the ATmega.
The PWM resolution is 8 bit and prescaling is set to the smallest value to reach a maximum frequency.
I tested it with an ATmega128 at 14MHz and achieved a PWM frequency about 57kHz.
If you need a lower frequency (e.g. for servo applications), just set the prescaler to a adequate value (see ATmega128 data sheet (3MB) → TCCR1B [Bit 3:0]).

Code

PHP-Code:
And before the main() function, you need to declare the function prototypes and the array to store the PWM values of the three ports OCR1[A..C]:
PHP-Code:

Multitasking with ATmega128 microcontroller

Description

I was looking for a multitasking OS for the ATmega128 when I found FreeRTOS, a small open source realtime kernel for various platforms.
The FreeRTOS download includes to each supported system an example program.
But unfortunately this examples are quite complex and hard to understand for beginners.
So I wrote this small example program, to show you how to reach with minimum time and effort multitasking with FreeRTOS in combination with WinAVR.

What you'll need

You only need a running WinAVR IDE, the knowledge to write own simple programs and flash them to an ATmega128.
WinAVR is a development environment for AVR controllers, consisting in the editor (Programmers Notepad 2), a modified GCC compiler and a linker.

How to

You can download FreeRTOS here: FreeRTOSv3.2.2. download (2.3 MB)
Extract this zipfile in the WinAVR folder.
E.g. X:\WinAVR\FreeRTOS\
The next step ist to create a AVR_ATMega128_WinAVR folder in the Demo directory of FreeRTOS.
Now, extract this example program (7 KB) in the AVR_ATMega128_WinAVR folder.

Almost done. Now compile the main.c with WinAVR (make all from Programmers Notepad 2) and flash it to the controller.

What does the program do?

The example program does nothing more than to flash two LEDs on pins PB0 and PB2.
Not really impressive, you may say...
- but don't forget: each LED is controlled by its own thread!
I designed this program as simple and minimal as possible to make it easy to understand.
It should now be no problem for you to realize other functions instead of flashing LEDs. Maybe you should also have a look at the next code snippet where I used FreeRTOS for the ATmega8 of an ASURO robot...

Links and downloads


FreeRTOS website
WinAVR website
FreeRTOSv3.2.2. download (2.3 MB)
Example program - simple multitasking (7 KB)

Multitasking with the ASURO robot

Description

ASURO is a small sized mobile robot, designed for education purposes at the German DLR organisation.
http://www.dlr.de/st_op/aktuelles/pressemitteilungen/2003-006-ASURO (press article in German)
The construction set includes a few push-buttons, optical sensors, two wheels and an Atmel ATmega8. The controller can be programmed in C with WinAVR.

I just played with FreeRTOS on an ATmega128 (see previous code snippet) when I got an ASURO kit to build for the university of Offenburg. So it seemed to be obvious to try this on the ASUROs ATmega8 too.

What you'll need

You need a running ASURO robot, WinAVR and the program to flash the controller (Flash.exe) from the ASURO-CD.
It also makes sense, to become familiar with WinAVR and the flash tool and to write some own programs before.

How to

First of all, you need to download FreeRTOS here: FreeRTOSv3.2.2. download (2.3 MB) Extract this zipfile in the WinAVR folder.
E.g. X:\WinAVR\FreeRTOS\
The next step ist to create a ASURO folder in the Demo directory of FreeRTOS.
Now, extract this example program (157 KB) in the ASURO folder.

And finally you need to load the main.hex to the controller with the flash tool.
Flashing via IR can take a few minutes - the file size is about 18KB...
If the file reached the controller without any problems, switch-off the ASURO and switch it on again.
And action!

What does the example program do?

The program runs three tasks. One task does nothing more than to flash the both red LEDs on the robot rear.
The 2nd task controls the motors. It continuously reads a global variable is_collison.
When this variable is unequally 0 the task will stop the ASURO, makes it turn 90°, continue driving forward and reset is_collison back to 0.
And the 3rd task continuously checks the buttons in front of the robot. When the ASURO collides with something, one of the buttons will be pressed and the task will set is_collison to 1.
You'll find a complete documentation in the subfolder /html/, file index.html.

Links and files

FreeRTOS website
WinAVR website
FreeRTOSv3.2.2. download (2.3 MB)
Example program - multitasking with ASURO (157 KB)