Saturday, February 12, 2011

6.1 Counter 0 Mode 1 test

Hello Readers:

I have started this blog to show you Embedded C programming for 8051 family microcontroller using KEIL compiler. The KISS philosophy is used to write this tutorial. What is KISS? Keep It Simple, Stupid!

6. Counters
This section teaches you how to configure timers as counters.
 
6.1 Counter 0 Mode 1 test


This program is used to count the visitors and total count range is 16 bits as Counter 0 is in Mode 1. You can feed 1 Hz external clock into pin T0 (P3.4).

Start KEIL V4.01 and close projects, if any are open. Now start new project with Device -> Generic->8051 [all variants] for general 8051 family target chip. Add a new text file, name it Pgm_61.C and add it to above created project as a source file. It is time to add code to Pgm_61.C, so type below shown code in it.
  
Code explanation:
Line 09: make T0 an input.
Line 10: set TimerMODe register for Counter 0 in mode 1.
Line 11 &12: Initialize both registers to zero.
Line 16: Start the timer0.
Line 17 &18: Place value on LED port pins.
Line 19: do the above steps till Timer Flag is not overflowed.
Line 20 & 21: Reset Timer and Timer Flag for next iteration.

Below is the flow chart diagram of program PGM_61.C.
 
After typing the code, press F7 or click Project->Build Target for building the source code. If there are no typical errors file will build successively and shows zero errors and zero warnings. You cannot simulate this as external clock pulse is not supplied in this program.

If you generate HEX file of this program, burn it into your target chip’s memory using suitable uploader and connecting 1 Hz external clock to Port 2 you can watch LEDs incrementing in binary form. To stop running the program press red ‘x’ mark icon or click Debug->Stop.

To get back the compile mode press Ctrl+F5 or click Debug->Start/Stop Debug Session menu.   
<End of 6.1   Counter 0 Mode 1 test >
 
...till next post bye-bye & take care.

No comments:

Post a Comment