- Bohack - https://www.bohack.com -

Bascom-AVR and the Atmel ATtiny2313

Back in April I attended the Notacon the hacker-art convention up in Cleveland Ohio. The hardware hacking room had a number of little project kits they were giving out to teach people how to solder. These project kits included the chips, resistors, LEDs, serial connector and everything except the solder. They ran labs and the last day they just wanted to get rid of these project kits. So I grabbed a couple that caught my eye. One kit had an Atmel AVR programmable chip, eight LEDs and sported a 9-pin serial connector. The kit is the Mini-POV3 sold by http://www.adafruit.com/ for $17.50, it’s all you need to get started with programmable chips!

So I got home that Sunday and my son and I put the Mini-POV3 kit together, it took all of 30 minutes. It is a persistence of view kit, so when you wave the device it spells a word or words out. This concept unfortunately is not something that a 4 year old can grasp and he is like “Wow, what else does it do?”

The heart of the kit is an Atmel AVR ATtiny2313 8-bit RISC Microcontroller; it has programmable inputs and outputs, 2KB of flash memory and can be programmed in-system. The design was ahead of its time and AVR stands for the two designers’ names “Alf and Vegard’s Risc”. The kit also comes with a 9-pin Serial connector. So a couple of tasks to program this thing…

  1. Build the project (takes about 30 minutes).
  2. Get a straight thru serial cable or directly plug it into the serial port.
  3. Download WinAVR from http://www.sourceforge.net/
  4. Download Bascom-AVR Demo from http://www.mcselec.com/
  5. Learn some QBasic and the inner workings of the Atmel AVR.

Install the WinAVR program, this program will allow you to program the in-system Microcontroller. When you install it: change the path to “c:\WinAVR” and make sure that it puts the AVR binaries in the global path variable; you will be prompted during the install. Now we need to install the Bascom-AVR program which is the IDE or Integrated Development Environment and the Bascom BASIC to machine code complier. To install the Bascom-AVR program accept all defaults during the install, we will set it up next…

Inside of the Bascom-AVR program click on the ‘Options’ menu item and select ‘Programmer’. This is where we setup the tie between the WinAVR program called AVRDude.exe and the Bascom IDE for one click programming. Although you always have the option to find the BIN file and flash it via command line. Click the pull-down menu for Programmer and select ‘External programmer’ now in the tab below called ‘Other’ set the ‘Program’ to the path of the avrdude.exe; so it should look like this “C:\WinAVR\bin\avrdude.exe”. In the ‘Parameter’ field put “-p t2313 -P com1 -c dasa -U flash:w:{FILE}:a”; which tells avrdude.exe to write to a tiny2313, via comport 1, using direct access (dasa) and write to flash, substitute {FILE} for the filename and program it automatically. You can always Google ‘avrdude man’ for the manual page for the avrdude program or just type mine in.

Bascom Options for Programmers

Now let’s compile and program the equivalent of a hello world application… However if you want to backup the original program drop to a command prompt and type “avrdude -p t2313 -P com1 -c dasa -U flash:r:backup.hex:i” and you can always write it back via “avrdude -p t2313 -P com1 -c dasa -U flash:w:backup.hex:i”. Now open a new project in Bascom-AVR by clicking File-New and type the program in below, then hit ‘F7’ to compile and ‘F4’ to program to the chip. During this process the power switch must be in the ‘On’ position, remember you are programming a single chip computer!

The outcome when disconnected from the serial port is: a sequential lighting of the LEDs in 2 second intervals. Now it is time for you to learn some Bascom BASIC and play with the programming yourself. Start by downloading the Bascom-AVR PDF file and reading it. You can also customize my program to make the lights blink back and forth. Start by changing the timing to 1 second, then set your next goal and learn some of the language. Happy Hacking and visit some of my sponsors for deals on AVR products (I get paid when you visit them).

'Sequence LEDs
Dim X As Byte
Config PortB = Output
PortB = 0

For X = 0 To 7
 Wait 2
 PortB.X = 1
Next X