Skip to content

Files

Latest commit

1116ca5 · Nov 27, 2021

History

History
This branch is 1377 commits behind ckormanyos/real-time-cpp:master.

chapter02_03

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 24, 2021
Nov 27, 2021
Dec 29, 2017
Jan 2, 2018
Nov 27, 2021
Jun 30, 2021
Dec 22, 2018
Jun 26, 2020
Jan 25, 2021
Jan 25, 2021
Jun 26, 2020
Nov 27, 2021
Jan 11, 2020
Jan 25, 2021
Dec 29, 2017

Example chapter02_03

The LED program with timing

This example implements the LED program (with timing) for the target with the 8-bit microcontroller. This example builds on the previous example02_02 by including a small subset of a microcontroller abstraction layer, enough to provide functions for approximate timing and delays.

Building the example can be done with GNUmake in the command batch or shell script. The results of the build will be stored in the bin directory. After successful build, files such as the HEX-file led.hex and othe name and map files can be found in bin.

With GNUmake

The classic GNUmake facility is used to support the build. The user needs to supply (or modify) the Win* path to gcc-avr On a *nix system, the tool chain should be pre-installed, such as might be done via package management. In Win*, the GNUmake command is executed from Build.bat. The exact Win* command including command line parameters is shown below.

Target\Build\Build.bat avr rebuild

With VC or Atmel Studio

Project workspaces providing code visualization and single-click build are provided for both VC as well as Atmel Studio.

Application Description

In the LED program with timing, the blinking is controlled directly from the main subroutine of the program. The blinking frequency is approximately 1/2Hz, controlled by a timer dely. The blinking loop can be found in the file sys_start.cpp. It is reproduced below within its contect in main. Please note the MCAL initialization, which is essential for initializing clocks and interrupts. It is this layer that needs to be modified when porting to other microcontroller systems.

int main()
{
  // Initialize the mcal.
  mcal::init();

  // Toggle led0 forever.
  for(;;)
  {
    led_b5.toggle();

    // Wait 1 second in a blocking delay.
    timer_type::blocking_delay(timer_type::seconds(1U));
  }
}