
Wiring Alternative for Arduino - BASCOM-AVR
- Tutorial
Well, I do not like this one of your Wiring. And for some reason, he compiles me very slowly, and then thinks for a long time before the firmware.
I will try to talk about an alternative environment for programming AVR controllers, which combines a code editor, a compiler, and a debugger simulator. In addition, in recent versions the environment without unnecessary gestures can be used with the Arduino bootloader (i.e., without altering the board, flashing the bootloader, etc.)

Installation
We go to Offsite , or simply click on the second link at the end of the topic - a demo version of the environment (30Mb) will immediately start loading. The demo only means that it will allow you to collect projects whose weight in compiled form does not exceed 4Kb. For most projects this is enough (yeah, especially for Attiny2313 ), and if not, you will have to buy a crack for the latest version on the rutracker , since it costs not very expensive - 89 euros .
The installation is completely normal, if someone does not start in Win7 or higher, set the compatibility mode to XP. Under the vine works perfectly fine. Actually, you don’t need to install it - just copy the folder, it's quite a portable version.
Using
Main window:

All buttons are provided with hints, and I think there is no need to explain what and where is located.
In the latest versions, it was very decent translated into Russian, which can be included in Options - Environment - IDE - Language - Russian.
Here I have a copy of the Arduino Nano board that I used for a long time during debugging, flashing directly through the programmer’s connector, because of dislike for the Arduino IDE.

Let's try to write something for her. First you need to set the type of MK - Atmega168, this is done with this line:
Why is the line like this, thinking clearly. Of course, you can set the type of controller in Settings - Compiler - MK, but in the text it’s more convenient. You can see what files are called for different controllers in the program folder (c: \ Program Files \ MCS Electronics \ BASCOM-AVR \ *. Dat).
Set the clock frequency:
16 MHz. It does not affect anything, except for the countdown of time intervals (waitms). Does not set the frequency for the controller. You still have to expose it yourself, I program the Fuse-block. However, for Arduino this can not be bothered.
Configure ports:
No license pins, only hardcore. We look in the datasheet for a specific controller, and we see the port names:

PD1 = portd.1, pb4 = portb.4
You can also set each port individually, but simply write: Config Portb = Output
Run an unconditional loop (you can also without it, then the program will execute only once when starting the controller)
And inside it, for example, blink the LED:
Portb.5 is the same as pin 13 in arduino. Correspondence (if you are used to such a name for the ports) can be found here:

The syntax is very simple and reminds basic. 7 types of variables: Bit, Byte, Integer, Word, Long, Single, String.
Which are announced at the beginning of the program like this: Dim A as Single
Very simple connection to the screens on the HD44780 controller:
And the same simple conclusion to the text on them:
But despite its simplicity, there is cursor control, a built-in character editor, Cyrillic support.
Simple sound generation:
Which means to issue a meander on PB0 with a frequency of 500Hz and a duration of 100ms.
DTMF Tone Generation:
15th tone for 100ms.
Work with UART (both with iron, and software):
Work with interrupts:
With timers:
Arduino firmware
In the latest version, the developers added support for the Arduina bootloader, and we only need to make a few settings.
Options - Programmer - ARDUINO . Then specify the com-port, and speed.

In my case, the speed had to be specified exactly 19200, otherwise the board was not flashed. You can view the parameters of all the boards in a file at arduino-1.0.1 \ hardware \ arduino \ boards.txt
By the way, there is also a memory size and a chip frequency:
An alternative way to download (I do not like the built-in flasher for its slowness) is using AVRDUDE, the most powerful console programmer.
Download the latest version from here , for example avrdude-5.11.tar.gz . Unpack it into the program folder.
We go to Options - Programmer - External Programmer , and specify in the after Programm the path to the executable file:
"C: \ Program Files \ MCS Electronics \ BASCOM-AVR \ ARVDUDE \ avrdude.exe"
And in the following, the parameters are as follows:
- C "C: \ Program Files \ MCS Electronics \ BASCOM-AVR \ ARVDUDE \ avrdude.conf" -p atmega168 -P com2 -c arduino -b 19200 -U flash: w: {FILE}: i
Everything is clear from the names, we show where the config is, we indicate the type of controller, port, protocol, speed, working with flash, recording, and file. We tick Use HEX file.
For the greatest joy, you can also note the item Program after compile - to compile and flash with one button.
During assembly, the program displays the consumption of the available flash:

And then ARVDUDE starts: You

can also enable help on the pins of the selected controller from the side (by default, and if not, then View - Pin Layout is turned on ):

When you hover over the pin, it shows its name and description .
If this is not enough, then you can download the datasheet and enable View - PDF Viewer :

Another cool thing is the built-in debugger with a simulation of iron, break points and step-by-step execution.

It is turned on by pressing a button with a red microcircuit, of course, you must first compile the program.
And on the sweet side - the code compiled in bascom is much smaller and often runs faster than the code from the Arduino IDE.
For example, standard blink (flashing LED):
For Arduino:
It is compiled into hex with a size of 3078 (!!!) bytes, and yanks a pin with a frequency of 210 kHz:

And in Bascom, written like this:
It occupies 553 bytes (five times less) hex, and flashes already at a frequency of 1.6 MHz:

References:
I will try to talk about an alternative environment for programming AVR controllers, which combines a code editor, a compiler, and a debugger simulator. In addition, in recent versions the environment without unnecessary gestures can be used with the Arduino bootloader (i.e., without altering the board, flashing the bootloader, etc.)

Installation
We go to Offsite , or simply click on the second link at the end of the topic - a demo version of the environment (30Mb) will immediately start loading. The demo only means that it will allow you to collect projects whose weight in compiled form does not exceed 4Kb. For most projects this is enough (yeah, especially for Attiny2313 ), and if not, The installation is completely normal, if someone does not start in Win7 or higher, set the compatibility mode to XP. Under the vine works perfectly fine. Actually, you don’t need to install it - just copy the folder, it's quite a portable version.
Using
Main window: 
All buttons are provided with hints, and I think there is no need to explain what and where is located.
In the latest versions, it was very decent translated into Russian, which can be included in Options - Environment - IDE - Language - Russian.
Here I have a copy of the Arduino Nano board that I used for a long time during debugging, flashing directly through the programmer’s connector, because of dislike for the Arduino IDE.

Let's try to write something for her. First you need to set the type of MK - Atmega168, this is done with this line:
$regfile = "m168def.dat"
Why is the line like this, thinking clearly. Of course, you can set the type of controller in Settings - Compiler - MK, but in the text it’s more convenient. You can see what files are called for different controllers in the program folder (c: \ Program Files \ MCS Electronics \ BASCOM-AVR \ *. Dat).
Set the clock frequency:
$crystal = 16000000
16 MHz. It does not affect anything, except for the countdown of time intervals (waitms). Does not set the frequency for the controller. You still have to expose it yourself, I program the Fuse-block. However, for Arduino this can not be bothered.
Configure ports:
Config Portb.5 = Output
No license pins, only hardcore. We look in the datasheet for a specific controller, and we see the port names:

PD1 = portd.1, pb4 = portb.4
You can also set each port individually, but simply write: Config Portb = Output
Run an unconditional loop (you can also without it, then the program will execute only once when starting the controller)
Do
Loop
And inside it, for example, blink the LED:
Toggle Portb.5
Portb.5 is the same as pin 13 in arduino. Correspondence (if you are used to such a name for the ports) can be found here:

The syntax is very simple and reminds basic. 7 types of variables: Bit, Byte, Integer, Word, Long, Single, String.
Which are announced at the beginning of the program like this: Dim A as Single
Very simple connection to the screens on the HD44780 controller:
Config lcd = 16*2
Config lcdpin = PIN, DB4 = PORTB.1,DB5=PORTB.2,DB6=PORTB.3,DB7=PORTB.4,E=PORTB.5,RS=PORTB.6
Config lcdmode = PORT
And the same simple conclusion to the text on them:
Lcd "Hello, habr! " ; time
But despite its simplicity, there is cursor control, a built-in character editor, Cyrillic support.
Simple sound generation:
Sound, Portb.0, 100, 500
Which means to issue a meander on PB0 with a frequency of 500Hz and a duration of 100ms.
DTMF Tone Generation:
Dtmfout, 15, 100
15th tone for 100ms.
Work with UART (both with iron, and software):
Dim Name as String * 10
$Baud = 9600
Input "Hello, print you name", Name
Print "Name: " ; Name
Work with interrupts:
On Int0 Button - Имя подпрограммы
Config Int0 = Low Level - Прерывание по низкому уровню
Enable Interrupts - Включить прерывания
Enable Int0
Button:
Incr Cntr
Return
With timers:
Config Timer0 = Timer , Prescale = 64 - Настраиваем таймер и предделитель
On Timer0 Pulse: - Имя подпрограммы
Enable Interrupts - Включить прерывания
Enable Timer0
Pulse:
Incr Cntr
Return
Arduino firmware
In the latest version, the developers added support for the Arduina bootloader, and we only need to make a few settings. Options - Programmer - ARDUINO . Then specify the com-port, and speed.

In my case, the speed had to be specified exactly 19200, otherwise the board was not flashed. You can view the parameters of all the boards in a file at arduino-1.0.1 \ hardware \ arduino \ boards.txt
By the way, there is also a memory size and a chip frequency:
nano.name=Arduino Nano w/ ATmega168
nano.upload.maximum_size=14336
nano.upload.speed=19200
nano.bootloader.low_fuses=0xff
nano.bootloader.high_fuses=0xdd
nano.bootloader.extended_fuses=0x00
nano.build.mcu=atmega168
nano.build.f_cpu=16000000L
An alternative way to download (I do not like the built-in flasher for its slowness) is using AVRDUDE, the most powerful console programmer.
Download the latest version from here , for example avrdude-5.11.tar.gz . Unpack it into the program folder.
We go to Options - Programmer - External Programmer , and specify in the after Programm the path to the executable file:
"C: \ Program Files \ MCS Electronics \ BASCOM-AVR \ ARVDUDE \ avrdude.exe"
And in the following, the parameters are as follows:
- C "C: \ Program Files \ MCS Electronics \ BASCOM-AVR \ ARVDUDE \ avrdude.conf" -p atmega168 -P com2 -c arduino -b 19200 -U flash: w: {FILE}: i
Everything is clear from the names, we show where the config is, we indicate the type of controller, port, protocol, speed, working with flash, recording, and file. We tick Use HEX file.
For the greatest joy, you can also note the item Program after compile - to compile and flash with one button.
During assembly, the program displays the consumption of the available flash:

And then ARVDUDE starts: You

can also enable help on the pins of the selected controller from the side (by default, and if not, then View - Pin Layout is turned on ):

When you hover over the pin, it shows its name and description .
If this is not enough, then you can download the datasheet and enable View - PDF Viewer :

Another cool thing is the built-in debugger with a simulation of iron, break points and step-by-step execution.

It is turned on by pressing a button with a red microcircuit, of course, you must first compile the program.
And on the sweet side - the code compiled in bascom is much smaller and often runs faster than the code from the Arduino IDE.
For example, standard blink (flashing LED):
For Arduino:
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
digitalWrite(13, LOW);
}
It is compiled into hex with a size of 3078 (!!!) bytes, and yanks a pin with a frequency of 210 kHz:

And in Bascom, written like this:
$regfile = "m168def.dat"
$crystal = 16000000
Config Portb.5 = Output
Do
Toggle Portb.5
Loop
It occupies 553 bytes (five times less) hex, and flashes already at a frequency of 1.6 MHz:

References:
- Offsite
- Latest version of Bascom-AVR
- About 100 examples with detailed diagrams and code listings
- Wonderful Russian tutorial from WildCat (just follow the link just for the sake of reading the introduction)
- Another textbook in Russian . And there is a tutorial on microC and microPascal written by the respected moriam , who has no invite (yes, this is a hint)
- Russian-language site with projects
- Active Russian forum
- Another bunch of articles, books and projects
- Theme of discussion on the radio cat
- Discussion topic at cqham
- Do not go here , much less read anything. The site is “for search engines”, on which there are a lot of errors in the examples. And all in order to resell a couple of modules.