Counter


A counter display using 8051 micro-controller. Counter counts and displays negative going edge on P3.3. Counter is reset by a low level on P3.2

Toolkit:SDCC 8051 Development System

Location:/bipom/devtools/SDCC/examples/counter/

Code Example


main()
{
    unsigned counter;
	
	/* Set all ports as inputs */
	P1 = 0xFF;
	P3 = 0xFF;
	
    /* Set the serial port to 19200 Baud */
    serinit(CBR_19200);
		
	printf( "\r8051 Counter - (C) 1999 BiPOM Electronics" );
	
	/* Initialize the counter */
	counter = 0;
	
	for( ;; )
	{
		/* If RESET is generated, reset the counter */
		if( !(P3 & 0x04) )	
		{
			counter = 0;
			
			printf( "\rCounter is reset!" );			
		}
					
		/* If the input goes low, increment the counter */
		if( !(P3 & 0x08) )	
		{
			++counter;
			printf( "\rCounter=%u", counter );
			
			/* A small delay to debounce the input */
			delay(10);
			
			/* Wait until the input goes high again */
			while( !(P3 & 0x08) );					
		}				
	}
}