28
Chapter 4. Programming
BLINKY Example Program
The following simple program, BLINKY, is an exercise you may use to test the
MCB167-NET and verify that you can use the tools provided to generate a
working program.
BLINKY blinks the LEDs on the MCB167-NET evaluation board. The
complete source listing for the program is shown below:
/* FLASH.C - LED Flasher for the Keil MCB167-NET Board */
#include <reg167.h>
#include <stdio.h>
#include <intrins.h>
void wait (void)
{
/* wait function */
_nop_();
/* only to delay for LED flashes
*/
_nop_();
_nop_();
_nop_();
_nop_();
}
void main (void)
{
unsigned int i;
/* Delay var */
unsigned int j;
/* LED var */
DP2
= 0x00FF;
ODP2 = 0x0000;
while (1) {
/* Loop forever */
for (j=0x0001; j != 0x0100; j<<=1){
/* Blink LED */
P2 = ~j & 0x00FF;
/* Output to LED Port */
for (i = 0; i < 50000; i++)
{
/* Delay for 50000 Counts */
wait ();
/* call wait function */
}
}
for (j=0x0080; j != 0; j>>=1){
/* Blink LED */
P2 = ~j & 0x00FF;
/* Output to LED Port */
for (i = 0; i < 50000; i++)
{
/* Delay for 50000 Counts */
wait ();
/* call wait function */
}
}
}
}
You may build the BLINKY example program either using the µVision2 project
file
C:\Keil\C166\Examples\Boards\Keil MCB167 Net\Blinky\Blinky.UV2
.
Once you load this project file you can create and test the application as
described under “Writing Programs for the MCB167-NET” on page 25. When
you run this program it will flash the LED’s on the MCB167-NET board.
Summary of Contents for MCB167-NET
Page 18: ...18 Chapter 3 Hardware Schematics...
Page 19: ...MCB167 NET Board User s Guide 19...
Page 20: ...20 Chapter 3 Hardware...
Page 21: ...MCB167 NET Board User s Guide 21...