Programming avr in C. AVR: programming in AVR Studio environment

Almost everyone dreams of traveling, getting to know new places and countries, and not being dependent on anyone. It is ideal to have a motor home for such trips. This way you will not be tied to tickets, trains or buses, you will be able to come and leave whenever you want.

Motorhome - what are the advantages?

But, unfortunately, purchasing your own motorhome is very expensive, and many people cannot even afford to buy a car that has already been used. But craftsmen found a way out of this situation and managed to make the model with their own hands, without spending a lot of money or materials. How they managed to do this and what the sequence of actions was, we will discuss in the article. If you look at it, a mobile home is a trailer that has been equipped to accommodate one or more people in the most comfortable conditions.

The standard equipment in which the car is sold includes a gas stove, refrigerator, bathroom and toilet, and many other items without which it would be difficult for a normal person to travel around the world.

A mobile home has a large number of advantages, the main of which are:

  • It takes up minimal space when folded, and at the same time has everything necessary for normal life.
  • Does not require special care
  • Suitable for use in any conditions: you can use a motor home for a trip to the country, to the sea, in the countryside, or to travel across the continent - everything you need will always be at your fingertips.
  • There is no need to spend money on renting housing; you will live and spend the night here.
  • Even a passenger car will be suitable as a tow to the new parking lot.
  • You will be free to move - no one will be able to limit your time.
  • You can decorate your car in a way that is convenient for you.
  • If the trailer is insulated and soundproofed, then there will be practically no difference from a real house.
  • Traveling, especially over long distances, will be much easier.

It’s unlikely that you can argue with so many positive factors, so if you travel a lot and want to make your trips as comfortable as possible without spending a fortune, get to work.

Step one - draw a plan

As in any other responsible matter, you need to start with drawing up a detailed plan. It is at this stage that all the little details and aspects of the matter are thought through, an accurate drawing is drawn up, with the indicated dimensions, which you will adhere to in the future.

The entire interior space of the mobile home should be divided into three zones:

But the bathroom consists of a sink (but you can do without it), a small shower and a dry closet.

Due to the fact that the space is very limited, zones are often integrated into one another. That is why it is important to think about their placement at the planning stage. In addition, on sites where expensive motorhomes from the manufacturer are sold, there are many layout diagrams of everything you need. You can familiarize yourself with them and choose one for yourself.

Think carefully about which furnishings you really need and which you can discard. Next, draw on a piece of paper the space that will be used as an RV, indicating the exact length and width.

  • Conditionally divide it into zones, taking into account their characteristics. For example, a sleeping area will require more space than a kitchen.
  • Think about where the bathroom will be located and how you will fence it off.
  • Draw all the furniture elements and show how they will be attached and folded.
  • Consider the dimensions of each element.
  • Don't forget about free space. The van cannot be filled with furniture or belongings.

Only after drawing up a detailed plan and clarifying the dimensions can you begin to decorate the room.

Motorhome: what you need for comfort

Now let's talk a little about the benefits of civilization, which must be in a motor home so that you can fully use it:

  • Heating. This question is especially interesting for those who are planning long trips, some of which will take place during the cold season. Gas is most often used for heating, as well as for cooking. The gas cylinder must be properly secured, observing all safety rules. And you can fill it up at any gas station.
  • Ventilation. Even if your mobile home does not have enough space for a kitchen, you still need an influx of fresh air. Use windows for this, and also provide several ventilation holes. When using gas for heating, one of the holes should be almost at floor level.
  • It is almost impossible to do without electricity in the modern world. It is with its help that we charge gadgets, watch TV, and it will be difficult without regular lighting at night. Therefore, even before the trip, it is important to install electrics inside the van, equipping several light bulbs and sockets there.

We build a motorhome from a GAZelle

Often, to build a mobile home with their own hands, they use a GAZelle car, which has long been known in our country. Many people have GAZelles that no longer serve their intended purpose, but are still running. They can easily be converted into a motor home if you have enough free time and the necessary tools. The work itself consists of the following stages:

  1. External works
  2. Interior work
  3. conducting water and communications

An approximate sequence of actions is as follows:

  1. cut some holes for ventilation, which must be in the van. If you want to add a few more windows to make the house seem brighter, now is the time to do it.
  2. Apply primer to the bare metal parts, and then paint over them with paint that matches the color. This way you will protect the material from rust.
  3. Cut holes where the gas and propane release valves will be located.
  4. Insulate the gazelle using regular polystyrene foam. This way you will protect it not only from the cold, but also from the heat that is always present in cars.
  5. Level the ceiling, then the walls, and only then proceed to the floor. An excellent solution would be to put new boards on top, in which all the furniture will be perfectly secured, and linoleum on top. It is better not to skimp on these materials.
  6. To supply water, use several cans of water located under the washbasin and sink, and a simple pump.
  7. Install a wastewater tank.
  8. Secure the gas cylinder. There must be a ventilation hole near it.
  9. Think about exactly how the current will be supplied. You can use a battery with an external charging output for this.
  10. Equip the room with furniture, check all hinges
  11. The outside of the gazelle can be covered with iron sheets and sheathed. And then paint the van in any color, or decorate it to your taste.

As you can see, if you think through everything carefully, there will be no difficulties.

We build a mobile home from a trailer

You can even make a motorhome from an old trailer. If you don't have one, you can purchase it at a low cost. So, to make a motorhome from a trailer you will need:

  • The trailer itself. Only options with a strong chassis are suitable.
  • Wooden components: boards, parts of plywood, slats and bars.
  • Plywood sheets
  • Metal sheets for covering the resulting structure.
  • Accessories. It is desirable that it be all the same, or harmoniously combined with each other.
  • Tools.
  1. Disassemble the trailer. The chassis must be thoroughly cleaned and coated with anti-corrosion paint. Build a frame from the boards and cut out supports in the right places.
  2. Build a frame from pine slats measuring 2x2 cm. An oak strip with a 3x3 section is additionally installed in each corner. Tie the frame horizontally around the entire perimeter with a lath.

It is better for the lining to be of different thicknesses: for the side walls, a thickness of 6 mm is suitable, but for the floor you need something thicker, at least 19 mm.

  1. Cover the top of the floor with plywood so that it is as level as possible, use a level. Lay moisture-resistant material on top.
  2. Cut out the window. As planned, it will be located in the upper part of the back wall. This will ensure ventilation and sufficient lighting.
  3. Install the bed in the back of the van, so it will not only be conveniently located, but also support the structure.
  4. Set up a table. It is convenient if it can be pulled out from under the bed. In addition, this will significantly save space.
  5. Install other furniture that you need. But, usually nothing else can be placed in such a small mobile home.

As you can see, making a mobile home with your own hands is not at all difficult. You just need to carefully prepare for the work, draw up a detailed plan, and everything will definitely work out.

In contact with

A mobile home is the dream of many travel lovers, since there is no connection to one vacation spot, no need to book hotels and purchase tickets. This is both housing and a vehicle that allows you to travel anywhere with maximum comfort. The price of such a product on the market is high, so many are interested in how to build mobile homes with their own hands.

Types of mobile homes

It is much cheaper to make such a vehicle yourself from an old car or completely from scratch. In addition to the vehicle itself, you need to prepare various tools. Moreover, to make a mobile home you will need work experience, a lot of effort and free time.

Before investing in such structures, it is necessary to find out from the regulatory authorities the legality of the movement of such a vehicle in order to avoid any violations. Otherwise, you won't be able to travel with him.

A large home on wheels can be made from a van, but the price will be too high. Cheaper options can be made from:

  • bus;
  • gazelles;
  • an old but still durable trailer.

To build a mobile home, it is necessary, in addition to the vehicle, to make a plan for the future construction. Planning will help you make your motorhome as comfortable as possible. It can be simply drawn on paper or designed on a computer.

Communications in the motorhome

If there is no electricity, gas or water in a motor home, then it can hardly be called a comfortable trip. To supply electricity, batteries and chargers are used. How the electrical wiring will go in such a house must be planned and displayed in the drawing. You also need to think about where the external connector for charging the battery will be located. They come in different capacities. It must be selected in accordance with the expected travel range and the load on the electrical network.

Gas cylinders are often used for cooking and heating the van. If you use electricity for this, the financial costs will be much higher. When a mobile home is equipped with a kitchen, it is necessary to install an extractor hood with a ventilation system. This is especially important when using gas.

It is not recommended to install the gas system and electrical network yourself unless you have the appropriate experience. Such work should be done by professionals. If not installed correctly, it could result in injury or death to the traveler.

Such a kitchen cannot be as comfortable as possible without a designated place for storing water. Usually a special container with a pump is used to supply water to the tap. A container is also used as a sewage system indoors under the sink or outside. Sometimes such a motorhome is equipped with a shower. It will be difficult to make a bathroom in it, and for this they use a dry closet.

Furniture must be installed small and compact, since there will be little space in such a house. To save space, you can use folding beds, sliding tables and the like. Such structures must be well secured to the walls to ensure safety during movement. Furniture for a motorhome can be bought ready-made in a store, but if you have a strong desire to save money and learn something new, you can easily make it yourself, taking into account the size of the room.

Sometimes car seats are used as a sofa and chairs. It is quite possible to make a mobile home from a trailer with your own hands. Before this, you need to prepare the room. Depending on what base is taken - a minibus or a homemade trailer - the stages of work will differ.

Using a Gazelle and an old bus

It is necessary to begin remodeling a minibus by completely cleaning the body from seats, upholstery and dirt. After this, you need to cut out all the holes for windows, ventilation, and so on.

The further sequence of actions will be as follows:

  • Leveling and cleaning all damaged surfaces. To do this, use a metal brush, hammer or special equipment to level out dents. If necessary, you need to weld the corrosion areas where holes have formed. Then they are cleaned and primed to prevent further rust formation.
  • The interior is carefully insulated, including the floor and ceiling.
  • After the thermal insulation coating, it is necessary to sheathe everything with waterproof plywood.

After such work, you need to install gas, electricity, water supply, install a bathroom and furniture. To securely fix the furniture, it is necessary to install thick plywood on the walls in advance. Furniture needs to be attached to it. As an option, you can install reinforcing strips on the floor and fix the set to them.

If such a house is made not from an old trailer, but from a gazelle or a bus, then the chassis needs to be brought into working condition. Then such a structure will actually be mobile.

Trailer as the basis of the design

You can also make a motorhome from a trailer yourself, but there will be a lot more work involved. First you need to clean the chassis from corrosion and other defects. Then all the holes, just like in a minibus, need to be welded, cleaned and primed. This is followed by painting.

When the base is ready, you need to start building the floor, walls and roof. You need to act in the following sequence:

After this work, you can begin installing gas equipment, electrical wiring, organizing the kitchen and toilet, as well as installing furniture. Then you should install the headlights, license plate and fenders. The trailer is ready for travel.

Before you start work, you need to think carefully about the possibility of doing them efficiently. They require special skills and a lot of funds. But in any case, you can make a trailer-house on wheels with your own hands if you have a great desire to learn how to do it.

Comfortable movement

Although such a structure is not intended for permanent residence, the need for comfort on the road and travel has not been canceled. Today there is a lot of technology that can make living in a mobile home easier.

Indoor light

To ensure the availability of constant light and electricity, you can use a battery or accumulator, a charger, electrical wires, or an electricity supply control panel.

Heating in the house

For these purposes, you can use several types of heaters. It is preferable to use a gas cylinder, as this will also provide the possibility of cooking.

If the gas supply installation technology is quite complex, then you need to seek help from a specialist. Constructing such a vehicle with your own hands is commendable, but the safety of its inhabitants must be taken into account above all.

Water supply, kitchen and bathroom

Any housing will not be comfortable if it does not have basic amenities, such as a bathroom, a well-equipped kitchen and the availability of water. At the planning stage, you need to carefully consider their location for maximum comfort. Do not forget about the automatic water supply system and tanks for it.

Furniture installation

When installing furniture, certain difficulties may arise, since it should be located as compactly as possible around the entire perimeter. They mainly use folding furniture that can be unfolded if necessary. This allows you to significantly save space. It can only be purchased to order, and it will not be cheap.

It is better to have at least 2-3 windows. Thanks to their large number, there will be no need to turn on the lights during the day.

Legality of construction

If we talk about the legality of movement, then such a vehicle will not have any special status as a vehicle. A mobile home in the legal field is no different from a regular trailer. All that is needed is the presence of headlights and dimensions on the rear side, as well as a license plate.

An additional permit is required if such a trailer exceeds the following dimensions:

  • 4 meters high;
  • 2.55 m wide;
  • 10 meters long.

If the dimensions are larger, then such a vehicle can move according to special rules: the presence of flashing lights and police escort. You can make good money from such structures by organizing a business. There are quite a lot of options for such entrepreneurial activity.

As an option, you can make such houses to order for the purpose of summer holidays and temporary residence in the country. This does not require large initial investments, since small, economical motorhomes can be manufactured without insulation.

Such houses can be rented out. Entrepreneurial activity of this kind is new. The market value has not yet formed, and, accordingly, you can set your own price. The number of such structures needs to be increased as the customer base expands.

You can also make your own car park and use it as hotels. An important factor here is their division into economy, middle and vip classes.

Many lovers of free holidays dream of traveling in a motor home, so as not to be dependent on purchasing tickets, booking hotels and being tied to one point during the entire holiday. A mobile home is both a home and a means of transportation. It allows you to travel with maximum comfort and stop wherever you want along the way. In addition, it can be used as housing in the country or while building a house.

Types of mobile homes

Today a mobile home can be purchased ready-made, although it is quite expensive. But it’s much more interesting and cheaper to make it yourself from an old vehicle, refurbishing its interior or making such a motorhome practically from scratch, not counting the base. For this, in addition to the “wheels” themselves, you will need not only funds for re-equipment and a variety of tools, but also certain skills for such work, as well as a lot of effort and free time.

Attention! Before investing in the conversion of a vehicle, you need to find out all the nuances of its registration with the relevant authorities in order to avoid any problems during registration. Otherwise, it is unlikely that you will be able to use such a vehicle for travel, and it will end up as a dead weight somewhere in the country.

A decent sized mobile home can be made from a large van, but a mobile home like this is a prohibitively expensive vehicle. Among the budget options that are quite suitable for those who like to make anything with their own hands, there are three most convenient ones. So, a mobile home can be made from:

  • Gazelles;
  • old bus;
  • trailer with a strong chassis.

House made from a Gazelle car

To implement any of these three options, in addition to having the vehicle itself, which will be taken as a basis, you will need a plan for the future motorhome, at least in schematic form. Such a plan will allow you to take into account all the design features and plan a living area with maximum comfort for living there. You can simply draw it on paper or do it on a computer, if that’s more convenient.

Internal communications of a mobile home

Without electricity, water supply and gas, it is difficult to call life in a mobile home comfortable. To provide electricity to a room, a battery and a charger are usually used. The electrical wiring inside must be thought out in advance. Don’t forget about the external connector to charge the battery, which come in different capacities. The most suitable battery capacity also needs to be calculated in advance, taking into account the load and travel distance.

Interior arrangement of a mobile home

Gas cylinders are often used to heat rooms. Gas will also be convenient for cooking, which is much more economical in terms of consumption than an electric stove. Having a kitchen in such a house means installing a hood above the stove and organizing a general ventilation system, which is especially important when using propane.

Advice. You should not undertake independent gasification and electrical supply of the premises in the absence of the necessary knowledge and experience; it is better to entrust such work to professionals. The safety of people in the motorhome directly depends on how competently they are carried out.

The kitchen cannot function without water, which is usually stored in containers into which a submersible pump is lowered to supply it to the tap. To drain used water, a tank is also used, which is mounted either indoors or outdoors. If desired, the mobile home can be equipped with a small shower. But it is not possible to create a conventional bathroom in a mobile home; a dry closet is used for this purpose.

Kitchen area in a motorhome

As for furniture, it is better if all of it in a motor home is practical and compact, because there is not too much space to place it. Options for reclining beds, sliding tables and similar organization of space can be used. And all this must be securely fastened to the walls to ensure safety when moving. Furniture for furnishing can be purchased ready-made, but for a person with hands it is not difficult to make it yourself, taking into account the size of the room, and make a sofa and chairs, for example, from car seats.

It is quite possible to arrange the interior space in a mobile home, and you can do it all yourself. But before that you need to prepare the room. Depending on which option is taken - a minibus or a trailer, there will be differences in the stages of work required for the conversion.

Mobile home from a Gazelle or an old bus

Re-equipment of a minibus begins with cleaning the body from upholstery and seats, after which various holes are made - for windows, ventilation, for gas supply.

Mobile house from a bus

Then the work on arranging the residential area is carried out in the following sequence:

  • level out any dents on the inner surface, then prime all exposed metal parts of the body to prevent corrosion;
  • the internal surface of the future house, including walls, floor and ceiling, is covered with thermal insulation;
  • Moisture-resistant plywood or carpeting is laid on top of the heat-insulating material, starting from the ceiling.

Upon completion of these works, electrification and gasification of the premises, equipment of the kitchen and bathroom, and installation of furniture are carried out. For reliable installation of furniture, plywood of a larger thickness is attached to the walls than on the floor or ceiling, or separate reinforced strips are installed to fix it. And, of course, if necessary, you need to put in order the chassis and engine of a Gazelle or an old bus, then such a house will become truly mobile.

Mobile home based on trailer

Here, unlike a house made from a minibus, the work is somewhat different. First you need to protect the chassis from corrosion by cleaning and painting them. Then you will have to build the floor, walls, ceiling and roof, proceeding in the following sequence:

  • place plywood of sufficient thickness on the frame, surround the outer edge with timber and secure with bolts;

Flooring for a house based on a trailer

  • lay the beams on the floor, securing heat-insulating material between them and cover it all with plywood on top;
  • timber and clapboard are used for the construction of walls, not forgetting to make openings for windows and doors during the work, as well as technological openings for the entry and exit of various communications;
  • to build a roof, install rafters, cover them with plywood, covering them with moisture-resistant material;

Construction of walls

  • after laying the electrical wiring, make thermal insulation of the walls, then covering the fiberboard on top;
  • to protect wooden walls, prime them inside and out, then paint them in two layers;
  • install a door and windows; additional interior finishing may be required.

Upon completion of these works, you can think about gasification, water supply, organizing the kitchen and bathroom, and installing furniture. Then all that remains is to install the fenders and lights that come with the trailer, and the mobile home is ready to travel.

Don't forget to get your permits before you hit the road in your RV.

Of course, traveling in a motor home is very convenient. However, before you start construction, decide for yourself whether you can handle all the work yourself, because it will require quite a lot of effort, money and skills.

DIY mobile home: video

How to build a mobile home: photo


























Microcontrollers (hereinafter referred to as MK) have firmly entered our lives; on the Internet you can find a lot of interesting circuits that are executed on MK. What you can’t assemble on an MK: various indicators, voltmeters, home appliances (protection devices, switching devices, thermometers...), metal detectors, various toys, robots, etc. The list could take a very long time. I saw the first circuit on a microcontroller 5-6 years ago in a radio magazine, and almost immediately turned the page, thinking to myself “I still won’t be able to assemble it.” Indeed, at that time MKs were a very complex and misunderstood device for me; I had no idea how they worked, how to flash them, and what to do with them in case of incorrect firmware. But about a year ago, I first assembled my first circuit on an MK; it was a digital voltmeter circuit based on 7 segment indicators and an ATmega8 microcontroller. It so happened that I bought a microcontroller by accident, when I was standing in the radio components department, the guy in front of me was buying an MK, and I also decided to buy it and try to assemble something. In my articles I will tell you about AVR microcontrollers, I’ll teach you how to work with them, we’ll look at programs for firmware, we’ll make a simple and reliable programmer, we’ll look at the firmware process and, most importantly, the problems that may arise not only for beginners.

Basic parameters of some microcontrollers of the AVR family:

Microcontroller

Flash memory

RAM memory

EEPROM memory

I/O Ports

U power

Additional parameters of the AVR mega MK:

Operating temperature: -55…+125*С
Storage temperature: -65…+150*С
Voltage at the RESET pin relative to GND: max 13V
Maximum supply voltage: 6.0V
Maximum I/O line current: 40mA
Maximum power supply current VCC and GND: 200mA

ATmega 8X Model Pinouts

Pinouts for ATmega48x, 88x, 168x models

Pin layout for ATmega8515x models

Pin layout for ATmega8535x models

Pin layout for ATmega16, 32x models

Pin layout for ATtiny2313 models

An archive with datasheets for some microcontrollers is attached at the end of the article.

MK AVR installation FUSE bits

Remember, a programmed fuse is 0, an unprogrammed one is 1. You should be careful when setting fuses; an incorrectly programmed fuse can block the microcontroller. If you are not sure which fuse you need to program, it is better to flash the MK without fuses for the first time.

The most popular microcontrollers among radio amateurs are ATmega8, followed by ATmega48, 16, 32, ATtiny2313 and others. Microcontrollers are sold in TQFP and DIP packages; for beginners, I recommend buying in DIP. If you buy TQFP, it will be more problematic to flash them; you will have to buy or solder the board because their legs are located very close to each other. I advise you to install microcontrollers in DIP packages on special sockets, it is convenient and practical, you don’t have to unsolder the MK if you want to reflash it, or use it for another design.

Almost all modern MKs have the ability to in-circuit ISP programming, i.e. If your microcontroller is soldered to the board, then in order to change the firmware we will not have to desolder it from the board.

6 pins are used for programming:
RESET- Login MK
VCC- Plus power supply, 3-5V, depends on MK
GND- Common wire, minus power.
MOSI- MK input (information signal in MK)
MISO- MK output (information signal from MK)
SCK- MK input (clock signal in MK)

Sometimes they also use pins XTAL 1 and XTAL2; quartz is attached to these pins if the MK is powered by an external oscillator; in ATmega 64 and 128, the MOSI and MISO pins are not used for ISP programming; instead, the MOSI pins are connected to pin PE0, and MISO to pin PE1. When connecting the microcontroller to the programmer, the connecting wires should be as short as possible, and the cable running from the programmer to the LPT port should also not be too long.

The marking of the microcontroller may contain strange letters with numbers, for example Atmega 8L 16PU, 8 16AU, 8A PU, etc. The letter L means that the MK operates at a lower voltage than the MK without the letter L, usually 2.7V. The numbers after the hyphen or space 16PU or 8AU indicate the internal frequency of the generator that is in the MK. If the fuses are set to operate from an external quartz, the quartz should be set to a frequency not exceeding the maximum according to the datasheet, this is 20 MHz for ATmega48/88/168, and 16 MHz for other atmegas.


In this avr training course, I tried to describe all the basics for beginners in programming microcontrollers avr. All examples are built on a microcontroller atmega8. This means that to repeat all the lessons you will need only one MK. Proteus is used as an electronic circuit emulator - in my opinion, the best option for beginners. The programs in all examples are written in the C compiler for avr CodeVision AVR. Why not in some assembler? Because a beginner is already loaded with information, and a program that multiplies two numbers takes about a hundred lines in assembler, and in complex, bold projects they use C. The CodeVision AVR compiler is tailored for atmel microcontrollers, has a convenient code generator, a good interface and directly from You can flash the microcontroller with it.

This training course will explain and show with simple examples how to:

  • Start programming microcontrollers, where to start, what you need for this.
  • What programs to use for writing firmware for avr, for simulating and debugging code on a PC,
  • What peripheral devices are inside the MK, how to control them using your program
  • How to write finished firmware to a microcontroller and how to debug it
  • How to make a PCB for your device
In order to take the first steps towards programming the MK, you will need only two programs:
  • Proteus is an emulator program (in it you can develop a circuit without resorting to real soldering and then test our program on this circuit). We will first launch all projects in Proteus, and then we can solder the real device.
  • CodeVisionAVR is a C programming language compiler for AVR. In it we will develop programs for the microcontroller, and directly from it it will be possible to flash a real MK.
After installing Proteus, launch it
He invites us to look at the projects that come with him, we politely refuse. Now let's create the simplest circuit in it. To do this, click on the icon and visually nothing happens. Now you need to click on the small letter P (select from library) in the component list panel, the component selection window will open
in the mask field, enter the name of the component that we want to find in the library. For example, we need to add a mega8 microcontroller
in the list of results, point to mega8 and press the button OK. The mega8 microcontroller appears in our list of components
Thus, we add another resistor to the list of components by entering the word mask in the field res and LED led

To place parts on the diagram, click on the part, then click on the diagram field, select the location of the component and click again. To add a ground or general negative to the diagram on the left, click “Terminal” and select Ground. Thus, by adding all the components and connecting them, we get this simple circuit
That's it, now our first scheme is ready! But you might ask, what can she do? Nothing. Nothing, because in order for the microcontroller to work, you need to write a program for it. A program is a list of commands that the microcontroller will execute. We need the microcontroller to be mounted on a leg PC0 logical 0 (0 volts) and logical 1 (5 volts).

Writing a program for a microcontroller

We will write the program in C language using the CodeVisionAVR compiler. After running the CV, it asks us what we want to create: Source or Project We select the latter and click OK. Next, we will be asked to launch the CVAVR CodeWizard wizard (this is an invaluable tool for a beginner, because it can generate the main skeleton of the program) choose Yes
The wizard starts with the Chip tab active, here we can select the model of our MK - this is mega8, and the frequency at which the MK will operate (by default, mega8 is set to a frequency of 1 megahertz), so we set everything as shown in the screenshot above.
Go to the Ports tab
  • The atmega8 microcontroller has 3 ports: Port C, Port D, Port B. Each port has 8 pins. Port legs can be in two states:
Exit
  • Using the DDRx.y register we can set the pin to be input or output. If in DDRx.y = 0 - the output works like
  • ENTRANCE DDRx.y = 1 pin running on
EXIT

When the pin is configured as an output, we can set it to logic 1 (+5 volts) and logic 0 (0 volts). This is done by writing to the PORTx.y register. Next we will talk in detail about I/O ports. Now we set everything as shown in the screenshot and click File->Generate, Save and Exit. Next, CodeWizard will prompt us to save the project, we save it and look at the code: #include


//library for creating time delays void main(void) ( PORTB=0x00; DDRB=0x00; PORTC=0x00; DDRC=0x01; // make PC0 pin an output PORTD=0x00; DDRD=0x00; // Timer/Counter 0 initialization TCCR0=0x00; // Timer/Counter TCCR1A=0x00; TCNT1L=0x00; OCR1BH=0x00 ; OCR1BL=0x00; // Timer/Counter 2 initialization TCCR2=0x00; // External Interrupt(s) initialization MCUCR=0x00; ) Interrupt(s) initialization TIMSK=0x00; // Analog Comparator initialization ACSR=0x80; while (1) ( )

When the pin is configured as an output, we can set it to logic 1 (+5 volts) and logic 0 (0 volts). This is done by writing to the PORTx.y register. Next we will talk in detail about I/O ports. Now we set everything as shown in the screenshot and click File->Generate, Save and Exit. Next, CodeWizard will prompt us to save the project, we save it and look at the code: Everything here may seem scary and unfamiliar to you, but in reality everything is not like that. The code can be simplified by eliminating the initialization of MK peripheral devices that we do not use. After simplification it looks like this: //library for working with the mega8 microcontroller #include


//library for creating time delays void main(void) ( DDRC=0x01; /* make the PC0 pin the output The entry 0x01 may seem unfamiliar to you, and this is just the number 1 in hexadecimal form, this line will be equivalent to 0b00000001 in binary, then I I will write this way.*/ while (1) ( )

When the pin is configured as an output, we can set it to logic 1 (+5 volts) and logic 0 (0 volts). This is done by writing to the PORTx.y register. Next we will talk in detail about I/O ports. Now we set everything as shown in the screenshot and click File->Generate, Save and Exit. Next, CodeWizard will prompt us to save the project, we save it and look at the code: Everything here may seem scary and unfamiliar to you, but in reality everything is not like that. The code can be simplified by eliminating the initialization of MK peripheral devices that we do not use. After simplification it looks like this: //library for creating time delays void main(void) ( DDRC=0x01; /* make the PC0 pin the output The entry 0x01 may seem unfamiliar to you, and this is just the number 1 in hexadecimal form, this line will be equivalent to 0b00000001 in binary, then I I’ll write it exactly like this.*/ while (1) // main loop of the program (// opens the operator bracket of the main loop of the program PORTC.0=1; // set pin 0 of port C 1 to delay_ms(500); // make a delay of 500 milliseconds PORTC.0=0; //set port C to pin 0 delay_ms(500); //make a delay of 500 milliseconds);//closes the operator bracket of the main program loop)


That's it, the code is now ready. Click on the Build all Project files icon to compile (translate into MK processor instructions) our program. In the Exe folder, which is located in our project, a file with a hex extension should appear, this is our firmware file for the MK. In order to feed our firmware to the virtual microcontroller in Proteus, you need to double-click on the image of the microcontroller in Proteus. A window like this will appear
Click on the folder icon in the Program File field, select the hex file of our firmware and click OK.