Professional Documents
Culture Documents
Chapter 1
INTRODUCTION
1.1.1Existing Systems:
Existing systems do employ POV principle, but for displaying each pixel, individual
LED is used. This results in a huge number of LEDs even for small sized displays. By
using a propeller type display, LED count can be kept to a bare minimum. Even 8
LEDs can perform a task of over 525 LEDs.
1.1.2Applications:
Applications can find their way into cost effective solutions for large public displays,
information systems. It can directly replace Railway station information displays, bus
stands and many more places.
1.3BLOCK
BLOCK DIAGRAM
Interrupter Module
Microcontroller
LED module
DC motor
DC power supply
Chapter 2
Hardware Design
2.1Interrupter module
MOC7811 is the sensing part of the interrupter module, while rest of the circuitry
works as signal conditioning circuit 3 wires emerge out from the module,
respectivelyVcc, Signal and Ground. Output of the module is LOW, if interrupt
occurs, otherwise it remains HIGH.
It consists of IR LED and Photodiode mounted facing each other enclosed in plastic
body. When light emitted by the IR LED is blocked because of some completely
opaque object, logic level of the photo diode changes. This 3change in the logic level
can be sensed by the microcontroller or by discrete hardware. This sensor is used to
give position feedback.
Output
Figure 3: Functioning of MOC7811
2.1.1Signal Conditioning:
INT0 pin of our microcontroller is Active Low. That means, occurrence of each
interrupt is should be signaled with Low logic level. So, we must invert the output of
the sensor.
2.1.2Transistor
Transistor 2N3904:
This is ageneral
general purpose silicon NPN transistor. It is connected in the CE inverting
amplifier configuration. It inverts the output of the photodiode, and also improves the
transient response.
2.2MECHANICAL
MECHANICAL ASSEMBLY
Mechanical assembly plays a vital role in proper functioning of this project. The
display is scanned each time, by rotating the whole assembly in a circular path. The
basic idea we developed is on our own, by implementing and modifying different
ways to do this.Above diagram shows the most reliable way, that we finally selected.
Here, one major challenge was how to bring +5V supply to the spinning cir
circuit. We
tried the same by adopting two-three
two three different methods, but finally concluded on the
method, to use a 7805 regulator and I/P to regulator was given by a 9V DC battery.
Most critical objective was to achieve pristine balance and overall good mechanical
strength. We designed a case in which motor is fixed permanently and pcb is fixed on
it with the help of nut and bolts to avoid wobbling. To balance the weight we placed
battery on one side of PCB and whole circuit on other side.
2.3POWER SUPPLY
We are using a 9v motor dc motor to rotate the assembly to provide 9v to the DC
motor we have used a voltage adapter, which has an in built rectification circuit, that
converts 230 V AC mains to 9V DC.
The 9V DC is given to an arbitrary PCB then with connectors the supply is given to
motor.
Microcontroller we are using, P89V51RD2, operates at 5V DC supply. The DC
supply is provided by using 7805 regulator and a 9V battery.
Chapter 3
Software Design
10
3.1Schematic Diagram
11
There are several types of HEX files; we are going to produce machine code in the
INTEL HEX-80 format, since this is the output of the KEIL IDE that we are going to
use. Fig. 8 shows that to convert a C program to machine language, it takes several
steps depending on the tool you are using, however, the main idea is to produce a
HEX file at the end. This HEX file will be then used by the burner to write every
byte of data at the appropriate place in the EEPROM of the P89V51RD2.
3.2.2Organization of a C program
All C programs have this common organization scheme, sometimes its followed,
sometimes its not, however, it is imperative for this category of programming that
this organization scheme be followed in order to be able to develop your applications
12
successfully. Any application can be divided into the following parts, noting that is
should be written in this order:
1. Headers Includes and constants definitions: In this part, header files (.h) are
included into your source code. Those headers files can be system headers to
declare the name of SFRs, to define new constants, or to include mathematical
functions like trigonometric functions, root square calculations or numbers
approximations. Header files can also contain your own functions that would
be shared by various programs.
2. Variables declarations:More precisely, this part is dedicated to Global
Variables declarations. Variables declared in this place can be used anywhere
in the code. Usually in microcontroller programs, variables are declared as
global variables instead of local variables, unless your are running short of
RAM memory and want to save some space, so we use local variables, whose
values will be lost each time you switch from a function to another. To
summarize, global variables as easier to use and implement than local
variables, but they consume more memory space.
3. Functions body:Here you group all your functions. Those functions can be
simple ones that can be called from another place in your program, as they can
be called from an interrupt vector. In other words, the sub-programs to be
executed when an interrupt occurs is also written in this place.
4. Initialization:The particularity of this part is that it is executed only one time
when the microcontroller was just subjected to a RESET or when power is
just switched ON, then the processor continue executing the rest of the
program but never executes this part again. This particularity makes it the
perfect place in a program to initialize the values of some constants, or to
define the mode of operation of the timers, counters, interrupts, and other
features of the microcontroller.
5. Infinite loop
An infinite loop in a microcontroller program is what is going to keep it alive,
because a processor have to be allays running for the system to function,
exactly like a heart have to be always beating for a person to live. Usually this
part is the core of any program, and its from here that all the other functions
are called and executed.
13
#include <math.h>
delay(unsignedint y)
{
unsignedint i;
for(i=0;i<y;i++){;}
}
main()
{
while(1)
{
delay(30000);
P1_0 = 0;
delay(30000);
P1_0 = 1;
}
}
After including basic headers for the SFR definitions of the 8952 microcontroller
(REGX52.h) and for mathematical functions (math.h), a function named delay is
created, which is simple a function to create a delay controlled via the parameter y.
Then comes the main function, with an infinite loop (the condition for that loop to
remain will always be satisfied as it is 1). Inside that loop, the pin number 0 of port 1
is constantly turned ON and OFF with a delay of approximately one second.
14
To create a project, write and test the previous example source code, follow the
following steps:
You will prompted to choose a name for your new project, Create a separate
folder where all the files of your project will be stored, chose a name and click
save. The following window will appear, where you will be asked to select a
device for Target Target 1:
15
From the list at the left, seek for the brand name NXP, then under NXP,
select P89V51RD2. You will notice that a brief description of the device
appears on the right. Leave the two upper check boxes unchecked and click
OK. The P89V51RD2 will be called your Target device, which is the final
destination of your source code. You will be asked whether to copy standard
8051 startup code click No.
16
Click File, New, and something similar to the following window should
appear. The box named Text1 is where your code should be written later.
Now you have to click File, Save as and chose a file name for your source
code ending with the letter .c. You can name is code.c for example, and
click save. Then you have to add this file to your project work space at the left
as shown in the following screen shot:
17
In some versions of this software you have to turn ON manually the option to
generate HEX files. make sure it is turned ON, by right-clicking on target
1, Options for target target 1, then under the output tab, by checking the
box generate HEX file. This step is very important as the HEX file is the
compiled output of your project that is going to be transferred to the microcontroller.
18
You can then start to write the source code in the window titled code.c then
before testing your source code, you have to compile your source code, and
correct eventual syntax errors. In KEIL IDE, this step is called rebuild all
targets and has this icon:
You can use the output window to track eventual syntax errors, but also to
check the FLASH memory occupied by the program (code = 49) as well as the
registers occupied in the RAM (data = 9). If after rebuilding the targets, the
output window shows that there is 0 error, then you are ready to test the
performance of your code. In KEIL, like in most development environment,
this step is called Debugging, and has this icon:
19
debug icon, you will notice that some part of the user interface will change,
some new icons will appear, like the run icon circled in the following figure:
You can click on the Run icon and the execution of the program will start. In
our example, you can see the behavior of the pin 0 or port one, but clicking on
peripherals, I/O ports, Port 1. You can always stop the execution of the
program by clicking on the stop button (
20
increase the overall performance of the controller. Those features are principally the
timers, counters, interrupts, Analog to digital converters, PWM generators, and
communication buses like UART, SPI or I2C. The P89V51RD2 is not the most
equipped micro-controller in terms of peripherals, but never the less, the available
features are adequate to a wide range of applications, and it is one of the easiest to
learn on the market.
3.4.1Introduction to P89V51RD2 Peripherals
Figure 15 below shows a simplified diagram of the main peripherals present in the
P89V51RD2 and their interaction with the CPU and with the external I/O pins. You
can notice that there are three timers/Counters. We use the expression
Timer/Counter because this unit can be a counter when it counts external pulses on
its corresponding pin, and it can be a timer when it counts the pulses provided by the
main clock oscillator of the microcontroller. Timer/Counter two is a special counter
that does not behave like the two others, because it have a couple of extra
functionality.
The serial port, using a UART (Universal Asynchronous Receive Transmit) protocol
can be used in a wide range of communication applications. With the UART provided
in the P89V51RD2 you can easily communicate with a serial port equipped computer,
as well as communicate with another microcontroller. This last application, called
Multi-processor communication, is quite interesting, and can be easily implemented
21
3.4.2External Interrupts
Lets start with the simplest peripheral which is the external interrupt, which can be
used to cause interruptions on external events (a pin changing its state from 0 to 1 or
vice-versa). In case you dont know, interruption is a mean of stopping the flow of a
program, as a response to a certain event, to execute a small program called interrupt
routine.
As you noticed in figure 15, in the P89V51RD2, there are two external interrupt
sources, one connected to the pin P3.2 and the other to P3.3. They are configured
using a number of SFRs (Special Function Registers). Most of those SFRs are shared
by other peripherals as you shall see in the rest of the tutorial.
The first register you have to configure (by turning On or Off the right bits) is
the IE register, shown in figure 16. IE stands for Interrupt Enable, and it is used to
allow different peripherals to cause software interruption. To use any of the interrupts,
the bit EA (Enable ALL) must be set to 1, then, you have enable each one of the
interrupts to be used with its individual enable bit. For the external interrupts, the two
bits EX0 and EX1 are used for External Interrupt 0 and External Interrupt 1.
Using the C programming language under KEIL, it is extremely simple to set those
bits, simply by using their name as any global variables, using the following syntax:
EA = 1;
EX0 = 1;
22
EX1 = 1;
The rest of the bits of IE register are used for other interrupt sources like the 3 timers
overflow (ETx) and the serial interface (ES).
Similarly, you have to set the bits IT0 and IT1 in the TCON register, shown in figure
4.2.B. The bits IT0/IT1 are used to configure the type of signal on the corresponding
pins (P3.2/P3.3) that generated an interrupt according to the following table:
IT0/IT1 = 1
IT0/IT1 = 0
If IT0 or IT1 is set to 0, an interruption will keep reoccurring as long as P3.2 or P3.3
is set to 0. This mode isnt easy to manage, and most programmers tends to use
external interrupts triggered by a falling edge (transition from 1 to 0).
Again, this register is bit addressable meaning you can set or clear each bit
individually using their names, like in the following example:
IT0 = 1;
IT1 = 1;
3.4.2.1The IE register
First, you have to Enable the corresponding interrupts, but writing 1s to the
corresponding bits in the IE register. The following table shows the names and
definitions of the concerned bits of the IR register (you can always take a look at the
complete IE register in figure 14):
EA
ET2
ET1
ET0
You can access those special bits by their names, as simply as it seems, example:
23
ET0 = 1;
3.4.3Timer/Counter
The timer is a very interesting peripheral that is imperatively present in every
microcontroller. It can be used in two distinct modes:
1. Timer: Counting internal clock pulses, which are fixed with time, hence, we
can say that it is very precise timer, whose resolution depends on the
frequency of the main CPU clock (note that CPU clock equals the crystal
frequency over 12).
2. Counter: Counting external pulses (on the corresponding I/O pin), which can
be provided by a rotational encoder, an IR-barrier sensor, or any device that
provide pulses, whose number would be of some interest.
Sure, the CPU of a microcontroller could provide the required timing or counting, but
the timer/counter peripheral relieves the CPU from that redundant and repetitive task,
allowing it to allocate maximum processing power for more complex calculations.
So, like any other peripheral, a Timer/Counter can ask for an interruption of the
program, which if enabled occurs when the counting registers of the
Timer/Counter are full and overflow. More precisely, the interruption will occur at the
same time the counting register will be reinitialized to its initial value.
So to control the behavior of the timers/counters, a set of SFR are used, most of them
have already been seen at the top of this tutorial.
3.4.3.1 The TCON register
The TCON register is also shared between more than one peripherals. It can be used
to configure timers or, as you saw before, external interrupts. The following table
shows the names and definitions of the concerned bits of the TCON register (available
in figure 17):
TF1 Overflow interrupt flag, used by the processor.
TR1 Timer/counter 1 RUN bit, set it to 1 to enable the timer to count, 0 to stop counting.
TF0 Overflow interrupt flag, used by the processor.
TR0 Timer/counter 0 RUN bit, set it to 1 to enable the timer to count, 0 to stop counting.
As the IE register, TCON is also bit-addressable, so you can set its bit using its
names, like we did before. Example:
TR0 = 1;
24
For the given Timer/Counter, the corresponding bits of TMOD can be defined as in
the following table:
If you want to use the timers to capture external eventss length, set it to 1, and the timer 1/0 will stop counting when
External Interrupt 1/0 pin is low (set to 0 V). Note that this feature involves both a timer and an external interrupt, It youre
responsibility to write the code to manage the operation of those two peripherals.
C/T
Set to 1 to use the timer/counter 1/0 as a Counter, counting external events on P3_4/P3_5, cleared to 0 to use it as timer,
counting the main oscillator frequency divided by 12.
M1
Timer MODE: Those two last bits combine as 2 bit word that defines the mode of operation, defined as the table below.
M0
25
Timer/counter will count up from the value initially stored in TH0/1 to 255, and then overflow back
to 0.
If used as timer, pulses from the processor are divided by 32 (after being divided by 12). The result is
the main oscillator frequency divided by 384.
Timer/counter will count up from the 16 bit value initially stored in TH0/1 and TL0/1 to 65535, and
then overflow back to 0.
If used as timer, pulses from the processor are only divided by 12.
If used as counter, external pulses are not divided, but the maximum frequency that can be accurately
counted equals the oscillator frequency divided by 24.
TL0/1 is used for counting, forming an 8 bit timer/counter. TH0/1 is used to hold the value to be
restored in TL upon overflow.
Timer/counter will count up from the 8 bit value initially stored in TL0/1 and to 255, and then
overflow, setting the value of TH0/1 in TL0/1. This is called the auto-reload function.
If used as timer, pulses from the processor are only divided by 12.
If used as counter, external pulses are not divided, but the maximum frequency that can be accurately
counted equals the oscillator frequency divided by 24.
Timer modes 1 and 2 are the most used in 8051 microcontroller projects, since they
offer a wide range of possible customization.
3.5 ALGORITHM
Main routine:
1. Load proper value in IE register, so that the interrupts INT0 and T0 are
enabled. (IE = 83H)
2. Offer higher priority to the INT0 (External) interrupt. (IP = 01H)
3. Configure timer 1 as 16-bit timer, and timer 0 as 8-bit auto reload mode timer.
( TMOD = 12H)
4. INT0 should be configured as edge interrupt. (IT0 = 1)
5. Configure port 3 as input port. (P3 = 0FFH)
26
6. Move input string to the video RAM area. (call ramc function)
7. Start the timers.
8. Initiate an infinite loop.
Interrupt Routines:
(a) External Interrupt:
1. Stop the timers.
2. Move th1 and tl1 into convenient registers.
3. Divide this 16 bit value by our total number of segments.
4. Subtract the answer from 256, and load the result in th0.
5. Now, reset the video RAM pointer and character segment pointers to their
initial respective positions.
6. Start the timers.
7. Return from interrupt.
(b) Timer 0 Interrupt:
1. Call the display routine.
2. Clear timer overflow flag.
3. Return from interrupt.
4. Clear timer overflow flag.
5. Return from interrupt.
27
FUTURE SCOPE
We can improvise this project in the following ways:1.
2.
3.
4.
28
TROUBLESHOOTING MANUAL
1.
2.
3.
4.
29
Bibliography
(a) J.B. Gupta, Electronic circuits and devices, 1sted,S.KKataria and Sons,2005
(b) Muhammed AliMazidi, Janice GillispieMazidi and Rolin D Mckinlay,The
8051 Microcontroller and Embedded System Using Assembly and C,2nded,
Pearson, 2007
(c) Ramakant A. Gayakwad, Op Amp and Lineair Integrated Circuit,2nded,
Prentice Hall PTR, 2000
(d) K R Botkar, Integrated Circuits,2nded, Khanna Publisher,2003
(e) (2011)LogicBrigade website.[Online].Available:http://www.logicbrigade.com/
30