Professional Documents
Culture Documents
ABSTRACT
CHAPTER 1
OVERVIEW
DENSITY BASED TRAFFIC CONTROL SYSTEM
INTRODUCTION
Implementation
BLOCK DIAGRAM
AT89S52
IR
MICRO LED
TRANSMI IR CONTROLLER
TTER RECIEVE
R
LCD
REGULAT
ED
POWER
SUPPLY
DENSITY BASED TRAFFIC CONTROL SYSTEM
The IR sensors and leds are connected to any of the port pins of
microcontroller,regulated power supply is connected to the Vcc
pin of microcontroller which uses an voltage regulator to get 5 v
of power supply. The transmit pin of IR receiver is connected to
the receive pin of microcontroller
IR TRANSMITTER
IR RECEIVER
Description
Features
Photo detector and preamplifier in one package
Internal filter for PCM frequency
Improved shielding against electrical field disturbance
TTL and CMOS compatibility
Output active low
Low power consumption
High immunity against ambient light
Continuous data transmission possible (1200 bit/s)
DENSITY BASED TRAFFIC CONTROL SYSTEM
CHAPTER 2
INTRODUCTION TO MICROCONTROLLER AND EMBEDDED SYSTEM
DENSITY BASED TRAFFIC CONTROL SYSTEM
EMBEDDED SYSTEM
MICROCONTROLLER
Microcontroller
DENSITY BASED TRAFFIC CONTROL SYSTEM
both program and data. So, it has two distinctive memory spaces
of 64K X 8 size for both program and data. It is based on an 8 bit
central processing unit with an 8 bit Accumulator and another 8
bit B register as main processing blocks. Other portions of the
architecture include few 8 bit and 16 bit registers and 8 bit
memory locations.
Each 8031 device has some amount of data RAM built in the
device for internal processing. This area is used for stack
operations and temporary storage of data.
8051 DERIVATIVES
First major manufacturer was the Philips who brought out more
than 40-50 derivatives with a variety of I/O options, memory
combinations, and peripheral functions. Devices became available
in regular DIP and SMD packages. With the basic 8031 core,
Philips ported high capacity Program Memory (upto 32K/64K), its
patented I2C interface bus, 8/10 bit Analog to Digital Converters,
CAN Bus, Capture and Compare registers, Watch dog timer, PWM
facilities and etc. More I/O ports (as many as eight ports),
additional timer/counter, second serial port was also made
available in Philips devices.
All the Port 3 pins are multifunctional. They are not only port pins,
but also serve the functions of various special features as listed
below:
MEMORY ORGANISATION
Program memory (ROM, EPROM) can only be read, not written to.
There can be up to 64k bytes of program memory. In the 80C51,
the lowest 4k bytes of program are on-chip. In the ROMless
versions, all program memory is external. The read strobe for
external program memory is the PSEN (program store enable).
Data Memory (RAM) occupies a separate address space from
Program Memory. In the 80C51, the lowest 128 bytes of data
memory are on-chip. Up to 64k bytes of external RAM can be
addressed in the external Data Memory space. In the ROMless
version, the lowest 128 bytes are on-chip. The CPU generates
DENSITY BASED TRAFFIC CONTROL SYSTEM
BASIC REGISTERS
The "R" Registers The "R" registers are sets of eight registers
that are named R0, R1, through R7. These registers are used as
auxiliary registers in many operations. To continue with the above
example, perhaps you are adding 10 and 20. The original number
10 may be stored in the Accumulator whereas the value 20 may
be stored in, say, register R4. To process the addition you would
execute the command:
ADD A,R4
The "R" registers are also used to store values temporarily. For
example, letís say you want to add the values in R1 and R2
together and then subtract the values of R3 and R4. One way to
do this would be:
Aside from the MUL and DIV instructions, the "B" register are
often used as yet another temporary storage register much like a
ninth "R" register.
It is also interesting to note that while you may change the value
of PC (by executing a jump instruction, etc.) there is no way to
read the value of PC. That is to say, there is no way to ask the
8052 "What address are you about to execute?" As it turns out,
DENSITY BASED TRAFFIC CONTROL SYSTEM
this is not completely true: There is one trick that may be used to
determine the current value of PC. This trick will be covered in a
later chapter.
The Data Pointer The Data Pointer (DPTR) is the 8052ís only
user-accessible 16-bit (2-byte) register. The Accumulator, "R"
registers, and "B" register are all 1-byte values. The PC just
described is a 16-bit value but isn't directly user-accessible as a
working register.
The Stack Pointer The Stack Pointer, like all registers except
DPTR and PC, may hold an 8-bit (1-byte) value. The Stack Pointer
is used to indicate where the next value to be removed from the
stack should be taken from.
DENSITY BASED TRAFFIC CONTROL SYSTEM
When you push a value onto the stack, the 8052 first increments
the value of SP and then stores the value at the resulting memory
location. When you pop a value off the stack, the 8052 returns the
value from the memory location indicated by SP, and then
decrements the value of SP.
ADDRESSING MODES
MOV A, #100
loads the Accumulator with the decimal number 100. The same
number could be specified in hex digits as 64H.
Indexed Addressing
CHAPTER 3
AT89S52 MICROCONTROLLER
DENSITY BASED TRAFFIC CONTROL SYSTEM
Description
Features
• Watchdog Timer
• Power-off Flag
Pin
Description
GND Ground.
DENSITY BASED TRAFFIC CONTROL SYSTEM
RST Reset input. A high on this pin for two machine cycles while
the oscillator is running resets the device. This pin drives high for
98 oscillator periods after the Watchdog times out. The DISRTO
bit in SFR AUXR (address 8EH) can be used to disable this feature.
In the default state of bit DISRTO, the RESET HIGH out feature is
enabled.
shown in Table 1. Note that not all of the addresses are occupied,
and unoccupied addresses may not be implemented on the chip.
Read accesses to these addresses will in general return random
data, and write accesses will have an indeterminate effect.User
software should not write 1s to these unlisted locations, since
they may be used in Future products to invoke new features. In
that case, the reset or inactive values of the new bits will always
be 0.
Using the WDT To enable the WDT, a user must write 01EH and
0E1H in sequence to the WDTRST register (SFR location 0A6H).
When the WDT is enabled, the user needs to service it by writing
01EH and 0E1H to WDTRST to avoid a WDT overflow. The 14-bit
counter overflows when it reaches 16383 (3FFFH), and this will
reset the device. When the WDT is enabled, it will increment
every machine cycle while the oscillator is running. This means
the user must reset the WDT at least every 16383 machine
cycles. To reset the WDT the user must write 01EH and 0E1H to
WDTRST. WDTRST is a write-only register. The WDT counter
cannot be read or written. When WDT overflows, it will generate
an output RESET pulse at the RST pin. The RESET pulse duration
is 98xTOSC, where TOSC = 1/FOSC. To make the best use of the
WDT, it should be serviced in those sections of code that will
periodically be executed within the time required to prevent a
WDT reset.
With WDIDLE bit enabled, the WDT will stop to count in IDLE mode
and resumes the count upon exit from IDLE. UART The UART in
the AT89S52 operates the same way as the UART in the AT89C51
DENSITY BASED TRAFFIC CONTROL SYSTEM
Timer 2 consists of two 8-bit registers, TH2 and TL2. In the Timer
function, the TL2 register is incremented every machine cycle.
Since a machine cycle consists of 12 oscillator periods, the count
rate is 1/12 of the oscillator frequency. In the Counter function,
DENSITY BASED TRAFFIC CONTROL SYSTEM
by the DCEN (Down Counter Enable) bit located in the SFR T2MOD
(see Table 6). Upon reset, the DCEN bit is set to 0 so that timer 2
will default to count up. When DCEN is set, Timer 2 can count up
or down, depending on the value of the T2EX pin.
----------------------------------------------------------- =
DENSITY BASED TRAFFIC CONTROL SYSTEM
The timer should be turned off (clear TR2) before accessing the
Timer 2 or RCAP2 registers.
given below.
unsigned integer.
overlap a reload and cause write and/or reload errors. The timer
should be turned off (clear TR2) before accessing the Timer 2 or
RCAP2 registers.
DENSITY BASED TRAFFIC CONTROL SYSTEM
Programmable
Clock Out
flags, TF0 and TF1, are set at S5P2 of the cycle in which the
timers overflow. The values are then polled by the circuitry in the
next cycle. However, the Timer 2 flag, TF2, is set at S2P2 and is
polled in the same cycle in which the timer overflows.
DENSITY BASED TRAFFIC CONTROL SYSTEM
Oscillator
Characteristics
Idle Mode In idle mode, the CPU puts itself to sleep while all the
on-chip peripherals remain active. The mode is invoked by
software. The content of the on-chip RAM and all the special
following the one that invokes idle mode should not write to a
port pin or to external memory.
Reset redefines the SFRs but does not change the on-chip RAM.
The reset should not be activated before VCC is restored to its
normal operating level and must be held active long enough to
allow the oscillator to restart and stabilize.
DENSITY BASED TRAFFIC CONTROL SYSTEM
DENSITY BASED TRAFFIC CONTROL SYSTEM
Program Memory
Lock Bits
DENSITY BASED TRAFFIC CONTROL SYSTEM
The AT89S52 has three lock bits that can be left unprogrammed
(U) or can be programmed
Program Verify: If lock bits LB1 and LB2 have not been
programmed, the programmed code data can be read back via
the address and data lines for verification. The status of the
individual lock bits can be verified directly by reading them back.
(200H) = 06H
The Code memory array can be programmed using the serial ISP
interface while RST is pulled to VCC. The serial interface consists
of pins SCK, MOSI (input) and MISO (output).
Serial Programming
Algorithm
DENSITY BASED TRAFFIC CONTROL SYSTEM
1. Power-up sequence:
Set RST pin to “H”.If a crystal is not connected across pins XTAL1
and XTAL2, apply a 3 MHz to33 MHz clock to XTAL1 pin and wait
for at least 10 milliseconds.
Figure 13.
CHAPTER 4
INTERFACING DEVICES
RS232 is the most known serial port used in transmitting the data
in communication and interface. Even though serial port is harder
to program than the parallel port, this is the most effective
method in which the data transmission requires less wires that
yields to the less cost. The RS232 is the communication line which
enables the data transmission by only using three wire links. The
three links provides ‘transmit’, ‘receive’ and common ground...
Rs232
Thus the RS-232 signal levels are far too high TTL electronics,
and the negative RS-232 voltage for high can’t be handled at all
by computer logic. To receive serial data from an RS-232 interface
the voltage has to be reduced. Also the low and high voltage
level has to be inverted. This level converter uses a Max232 and
five capacitors. The max232 is quite cheap (less than 5 dollars)
or if youre lucky you can get a free sample from Maxim.The
MAX232 from Maxim was the first IC which in one package
contains the necessary drivers and receivers to adapt the RS-232
signal voltage levels to TTL logic. It became popular, because it
just needs one voltage (+5V or +3.3V) and generates the
8 -|R2I R2O|- 9
+--------+
J 2
C 1
U 3 1 u f
9 5
16
8 4 1 3 1 2 P 3R . X0 D
7 3 T 1 O U T 8 R 1 IR N 1 O9 U T
VCC
6 2 R 2 IR N 2 O U T
1 1 0 1 4 T 1 O U T
T X P D 3 1. 1 1 T 2 I TN 1 O 7 U T
C 4 T 1 I TN 2 O U T
5 V 1
3 C 1 +
C0 . 5 1 u 4 f C 1 -
5 C 2 +
C 6 C 2 -
0 . 1 u2 f
0 . 1 u f 6 V +
GND
V -
C 7
M A X 3 2 3 2
15
0 . 1 u f
.
DENSITY BASED TRAFFIC CONTROL SYSTEM
LED’S :
DENSITY BASED TRAFFIC CONTROL SYSTEM
The LM7805 is simple to use. You simply connect the positive lead
of your unregulated DC power supply (anything from 9VDC to
24VDC) to the Input pin, connect the negative lead to the
Common pin and then when you turn on the power, you get a 5
volt supply from the Output pin.
CIRCUIT FEATURES
BLOCK DIAGRAM
DENSITY BASED TRAFFIC CONTROL SYSTEM
RESET
DENSITY BASED TRAFFIC CONTROL SYSTEM
Regist Reset
er value (hex)
PC 0000
DPTR 0000
ACC 00
PSW 00
SP 07
B 00
P0-P3 FF
POWER SUPPLY
Power supply is an important part of operation of the
Microcontroller. Microcontroller operates at +5v DC and also
for other ICs and displays.
DENSITY BASED TRAFFIC CONTROL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P 1 . 4 5 P 1 . 3 P 3 . 3 / 1 I N4 TP 1 3 . 4 T H R
2 P 2 . 4
P 1 . 4 P3 . 4 1 / T5 O P
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
P 1 . 5 3 . 5
CV
C 4 6 2 7 p f 6
2
1 0 K 5
1
U 2 2
1
c o n 1 6 U 2 3 1 u f C 4 7 P 1 . 6 7 P 1 . 5 P3 . 5 1 / 6T 1 P 3S . C6 L
9 5 P 1 . 6 P 3 . 6 /1 W 7 RP D 3 4 3 2 Q 1 2
16
P 1 . 7 8 3S . D7 A U 4 9 3 B C 5 4 7 4
8 4 P 3 R . 0X P 1 . 7 P 3 . 7 / R D L E D
1
5
1 3 1 2 D N E 5 5 5 2
7 3 T 2 O U T R 1 I RN 1 O 9 U T
1
8 Y 5 1 9 2 9 R 5 6
VC C
4 7 0 M C T 2 E
1
6 2 R 2 I RN 2 O U T C 4 8 8 X T A L 1 P S E N
3
1 1 7 3 8
5 V 1 1 0 1 4 T 2 O U T 9 X T A L 2 3 0 A L EU 2 4
T X P D 3 . 11 1 T 2 I N T 1 O 7U T R S T R S T A L E / P R O2 GK
1
5 V 1 0 k D 3 5 3 3 0
C 4 9 T 1 I NT 2 O U T 2 7 p f 3 1 1
GND
1 5 VR 5 7 E A / V P P 2 L E D
3 C 1 + 3
0C . 51 1 u f4 C 1 - A T 8 9 C 5 1
0 . 0 0 1 u
0 . 0 0 1 u
20
C 5 0 5 C 2 +
1 0 u f C 5 2 C 2 - 1 0 k U 2 5 S P D T
0 . 1 u f2 3 5 V
R 5 8 0 . 1 u f 6 V + 2
GND
1 0 k V - 1
C 5 3
M A X 3 2 3 2
15
0 . 1 u f S P D T
2
R S T J P 4
2
1
3
S W 4 5 V 1 2 v J U M P E R 3
J 8
1
3
1 2 D 1 4 U 2 L6 7 8 0 5 / T O 3
3 1 2 1 3 5 V
2 V I N V O U T
1 1 N 4 0 0 1 GN D
C 5 4 C 5 5 C 5 6 4 . 7 K
2
C O N N J A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 . 3
C V
CV
2
1 0 K 5 1 0 K 5
1
1
1
D 3 4 3 2 Q 1 2 D 3 4 3 2 Q 1 2
U 4 9 3 B C 5 4 7 4 U 4 9 3 B C 5 4 7 4
L E D L E D
1
5
1
5
N E 5 5 5 N E 5 5 5
SCHEMATIC DESCRIPTION
2 2
1
4 7 0 M C T 2 E 4 7 0 M C T 2 E
1
1
3
1 7 3 8 1 7 3 8
1
1 0 k D 3 5 3 3 0 1 0 k D 3 5 3 3 0
L E D L E D
0 . 0 0 1 u 0 . 0 0 1 u
0 . 0 0 1 u 0 . 0 0 1 u
T it le
< T it le >
D E N S I T Y B A S E D T R A F F I C C O N T R O L
S iz e D o c u m e n t N u m b e r R e v
A 2 < D o c > < R e v C o d e >
CHAPTER 7
SDCC COMPILATION TOOL
DENSITY BASED TRAFFIC CONTROL SYSTEM
FEATURES
SDCC also comes with the source level debugger SDCDB, using
the current version of Daniel's s51 simulator.
Linux - x86, Microsoft Windows - x86 and Mac OS x - ppc are the
primary, so called "officially supported" platforms.
SUPPORT OF SDCC
DENSITY BASED TRAFFIC CONTROL SYSTEM
SDCC and the included support packages come with fair amounts
of documentation and examples. When they aren't enough, you
can find help in the places listed below. Here is a short check list
of tips to greatly improve your chances of obtaining a helpful
response.
USING SDCC
Getting Started:
http://ece.colorado.edu/~mcclurel/make.exe.
o You can add make to your path as well.
" If you are developing on Windows XP:
• Right click on “My Computer”
• Select the “Advanced” tab
• Click on “Environment Variables”
• Select “PATH” and “Edit” if it already exists. Otherwise
click “New” and create a PATH variable.
• Add the location of make.exe to the “Variable Value”
" If you are developing on another version of Windows you will
need to investigate further because the Environment variables
maynot be in the same location. For example, in Windows NT look
in
Start/Settings/Control Panel/System and select the Environment
tab to modify the PATH variable.
SDCC Memory Models
SDCC Basics
#include <stdio.h>
DENSITY BASED TRAFFIC CONTROL SYSTEM
However:
" printf depends on putchar() which is not implemented.
• You must implement putchar()
• This allows you to decide where printf is displayed (on a
terminal via serial port, on an LCD, etc…)
• The putchar() function must have the following format:
void putchar(char c);
CHAPTER 7
FLASH MAGIC
DENSITY BASED TRAFFIC CONTROL SYSTEM
FLASH MAGIC
Flash Magic can erase devices, program them, read data and read
and set various configuration information. Rather than providing
the basic features of ISP, Flash Magic adds additional features and
intelligence, allowing complex operations to be performed. For
DENSITY BASED TRAFFIC CONTROL SYSTEM
Flash Magic has been available for free for over six years and
supports all current 8-bit (8051), 16-bit (XA) and 32-bit (ARM)
flash microcontrollers from NXP.
Possible Uses
• Custom ISP tool for in-house use, for example production line
programming where it is essential the user interface is
simplified as much as possible
• End user ISP tool for updating the firmware of products. You
can build the hex file into the application or allow it to be
fetched over the internet. Adverts for new products could be
DENSITY BASED TRAFFIC CONTROL SYSTEM
displayed to the user. Use one tool for all your products
involving potentially multiple NXP microcontrollers.
• Gang programming tool. Invoke multiple instances of the
Flash Magic DLL in seperate threads, each using a different
COM port to allow parallel ISP programming
• Future-proofing products. Rather than write your own ISP
tool and have to keep updating it for new NXP devices,
updates to the DLL will automatically add new devices
Screenshots
Main window
Device signature
Start bootloader
Blank check
Executing a script
Features
Schematic
DENSITY BASED TRAFFIC CONTROL SYSTEM