A program to implement a binary counter on Port B
/*
* Program to implement binary counter
* on Port B using C
*
* February 5, 1998 Bill Rison
*/
#include <hc11.h>
void delay(int num);
void delay_10ms(void);
main()
{
while(1)
{
PORTB = PORTB + 1;
delay(10);
}
}
void delay(int num)
{
while (num > 0)
{
delay_10ms();
num = num - 1;
}
}
/* Assembly loop takes 22 E-clock cycles *
* DELAY of 909 gives 909*22*0.5 us = 10 ms *
*/
#define DELAY 909
void delay_10ms(void)
{
int i;
i = DELAY;
while (i>0)
{
i = i - 1;
}
}