Bascom and AVR, Led flasher.
The led flasher is sort of a 'hello world' Bascom/AVR application. It is a first phase you will have to
complete to demonstrate that all necessary elements are working.
You will already have built the ledflasher schematic on a breadboard if you have tested the
programmer and TWinAvr.
to start TWinAvr with the correct name of the bin-file it produces after a successful compilation.
Then proceed as follows:
- Start Bascom
- Select File/New:
In the textwindow that appears, enter the following Basic program:
(As you type Bascom will change the program text-color according to keywords it recognises)
In this simplest of programs, Portd of the AT90S2313 AVR is first configured to function as an output.
Then Portd is set to decimal value 255. All eight bits of Portd are now set to binary value 'one'.
Note that only the lower seven bits are externally available as pins PD0 up to PD6. If we connect any of these pins to a LED with
a current-limiting resistor to Ground, current will flow from the AVR to the LED. The LED is ON.
After waiting for 50 milliseconds, Portd is set to decimal value 0. Now, all pins are set to binary
value 'zero' and no current will flow from the AVR to the LED. The LED is OFF. After waiting for another
50 milliseconds, the cycle is repeated. The result is that the LED will flash on and off rapidly.
After entering the program text, select File/Save as and choose a location and name for the file. Let us assume you
select 'ledflasher.bas' as a filename. As Bascom generates
lots of files after a compile, it is a good idea to create separate directories for each Bascom project that
you work on.
Bascom can now be told about your AVR controller setup. Select Options/Compiler/Chip:
The chip is default set to AT90S2313:
Now, select tab Communication:
Default, clock speed is 10MHz, but as we use a 4MHz crystal, select 4000000 from the 'Frequency' list. Clock speed
should be set to the crystal speed used, as all wait loops are calculated according to the specified clock speed:
After the file is saved, select Program/Compile (F7). Bascom checks the program syntax and if no errors
are found, compiles the Basic program into a bin-file and while doing that reports on the amount of program
flash memory used for the chip selected:
Then, make sure your led flasher is
built on the breadboard
, power supply is on, programmer is connected to the
breadboard and the PC. In Bascom, select Program/Send to chip (F4). Bascom starts the TWinAvr program and tells it
to use the ledflasher.bin file it just generated. TWinAvr will then:
- stop the AT90S2313 in the breadboard (reset line is pulled down)
- connect the 74hct244 pins to the AT90S2313
- write the contents of ledflasher.bin into the AT90S2313 program flash memory
- verify the contents of the AT90S2313 program flash memory with ledflasher.bin
- disconnect the 74HCT244 pins from the AT90S2313
- release the reset line (10k resistor will pull it up to Vcc), so that the AT90S2313 will start running
While writing the program flash memory, TWinAvr shows a progress window:
After this programming sequence is concluded successfully, you will have to quit TWinAvr manually, Bascom will not
do that for you.
The result of all this should be a
rapidly flashing LED.(130 kB AVI file)
If you have tested your programming setup as
, you should not encounter any difficulties.
Now is the time to change your Bascom program. Modify the waitms values to a smaller or larger value to change the
LED on and off time. Recompile with F7 and reprogram the AT90S2313 with F4 and observe the results!
When you everything connected, you will
notice that the next time you start the PC, the controller in the breadboard will not run until TWinAvr runs.
This is because the PC holds the Reset line to the controller low and TWinAvr
will release that line after it his done a write or config read.