Programming Embedded system

Explanation of program:

Posted on

This example contains three preprocessor directives:

# include:

  • Is one of the most commonly used preprocessor directives.
  • When the preprocessor reaches this directive it looks for the file named in the brackets.
  • In the above example the preprocessor searches for the file hc705c8.h which contains device specific specification for the Motorola 68HC705C8.
  • If the file is found the preprocessor will replace the #includes directive with the entire contents of the file. If the file is not found the preprocessor will halt and give an error.
  • Here 3 include directive is used to include the contents of a header file.

#define ON 1 & # define OFF 0:

  • This directive is used to define symbolic constants.
  • Programs often use a constant number or value many times. Instead of typing in the actual number or value throughout the program, you can define a symbol which represents the value.
  • When the preprocessor reaches# define directive it will replace all the occurrences of the symbol name in your program with the associated constant.
  • In the statements # define ON 1 and # define OFF 0, the symbols ON and OFF are assigned the values 1 and 0 respectively.
  • Everywhere the preprocessor sees the symbol ON it will replace it with the constant 1; where it sees OFF it will replace it with the constant 0.

#pragma portrw portA @ 0X0A;

#pragma portw portAdir @ 0X8A;

  • #pragma directives instruct the compiler to behave in a certain way based on the description of the hardware resources of the target computer.
  • #pragma statements are most often used in header files which provide the hardware specification for a particular device. #pragma port directives for example, describe the port available on the target computer.
  • The description includes details on port location, whether they are read, write or read/write and the names the program uses to access ports.
  • In the above example the compiler is informed that two ports are available.
  • The name port A refers to physical Port A’s data register, which is available for reading and writing and is located at address 0X0A.
  • The name portADir refers to physical Port A’s data direction register, which is available for writing only and is located at address 0X8A.


Posted By-: Vissicomp Technology Pvt. Ltd.

Website -:


Structure of embedded program:

Posted on

The following Introductory program is representative of microcontroller programming  .The program tests to see if a button attached  to a controller port has been pushed.

If the button has been pushed, the program turns on an L ED attached to the port, waits and then it back off.

# include <hc705c8.h>

//#pragma portw portA @ 0X0A; is declared in header

//#pragma portw portADir @ 0X8A; is declared in header

# define INPUT 1

# define OUTPUT 0

# define ON 1

# define OFF 0

# define PUSHED 1

Void Wait (registera);  // wait  function protype

Void Main (void)


PortA Dir.0=OUTPUT;     // set pin 0 for output (light)

PortA Dir.1= INPUT;       // set pin 1 for input (button)

While (1)

{                                     // Infinite loop

If (portA.1==PUSHED)


Wait(1);              // is it valid push?

If (portA.1==PUSHED)


PortA.0=ON ;   // turn on light

Wait(10); //delay (light on)

PortA.0=OFF; // turn off light




}   // end main


Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: