IC211 Autumn 2010
Expt 4: Introduction to Micro-controllers
Aim:
1. To write a C program for the 8051-family micro-controller, using the Keil
software.
2. To study port operations of the micro-controller
3. Introduction to micro-controller timers.
Part 1: Port Operations [4 marks]
1. Assign a value to Port 2 in your program, execute the program and
observe the value on Port 2 LEDs.
2. Repeat the same for Port 0.
What is the difference between Port 0 and Port 2 outputs?
3. Give input at port 0 using jumpers J2 to J9. Write a program to assign this
value to Port 2
Note: A connected jumper assigns bit value ‘1’ to the micro-controller pin.
Part 2: Introducing timer delays [8 marks]
Generating a delay of 1ms
1. Initialize Port 2 with the value 00h.
2. After a delay of 1 ms assign Port 2 the value FFh.
3. After a delay of 1 ms assign Port 2 the value 00h.
4. Run step 2 and step 3 in an infinite loop.
This should generate a 500Hz wave on the pins of Port 2.
For generating the delay you need to use timers.
Challenge: [3 marks]
• Create a delay of 1 second with the timer idea as before.
Hint: Use multiple overflows.
Registers to be used to configure Timer
• TMOD (8 bit) – to configure timer modes.
• TH0 (8 bit) – timer 0 higher bit
• TL0 (8 bit) – timer 0 lower bits
• TR0 (1 bit) – start/stop timer
• TF0 (1 bit) – overflow bit
Refer to the 8051 manual to understand the use of these registers.
Information to be coded into the register should be based on the following
instructions:
TMOD Register:
• Use Timer 0 for the timer operation.
• Disable Timer 1
• Use Timer 0 in Mode 1 (16-bit timer).
TH0 & TL0:
• For getting a delay of 1 ms, assign proper values to TH0 and TL0.
• Understand the operations of TL0 and TH0 before initializing the
values.
TR0:
• Assigning 1 indicates the start of Timer 0 and vice versa.
TF0:
• Timers overflow indication flag/bit.
• TF0 = 1 when the Timer value reaches 0xFFFF
• TF0 should be reset before starting the timers.