CCCCCC C
CCCCCC C
1. 2.
ABSTRACT PROJECT DOCUMENTATION INTRODUCTION 2.1 EMBEDDED SYSTEMS INTRODUCTION 2.2. KEIL INTRODUCTION 2.3. MICROCONTROLLER INTRODUCTION 2.4. INTRODUCTION TO SERIAL COMMUNICATION 2.5. INTRODUCTION TO RS232 PROTOCOL
3. PROJECT DESCRIPTION 3.1. SCHEMATIC DESCRIPTION 3.2. CIRCUIT DESCRIPTION 3.3. DATA SHEET OF THE COMPONENTS
1.ABSTRACT
PC based electrical appliances control is an interesting PC based project, mainly useful for industrial applications, home automation, and supervisory control applications. This project gives exact concept of interfacing a high voltage electrical device or DC / AC motor to high sensitive personal computer system. This project is the first step to design of PC based industrial automation projects.
We are using the RS-232 as the communication medium between pc and controller. We are controlling the devices like light and fan and etc by sending signals from the pc to controller through serial port communication. Here we are using 89S52 microcontroller for doing our job. A logical is written for 89S52 microcontroller, which will decode the serial Protocol and does functioning. The keyboard is used as an input device and the keys are assigned to the devices while writing the logic. Thus, the status of the device is displayed on the pc screen itself. This project uses regulated 5V, 500mA power supply. 7805 three terminal voltage regulator is used for voltage regulation. The relays used in this project will be operating by 12V and drives the outputs up to 240V.Bridge type full wave rectifier is used to rectify the ac output of secondary of 230/12V step down transformer. This project is based on a well known 89S51 microcontroller. It is an 8-bit microcontroller with 4-I/O ports and 8k flash memory, which is more than Sufficient to our project.
2. PROJECT DOCUMENTATION
INTRODUCTION
2.1 INTRODUCTION TO EMBEDDED SYSTEM Embedded systems are electronic devices that incorporate microprocessors with in their implementations. The main purposes of the microprocessors are to simplify the system design and provide flexibility. Having a microprocessor in the device helps in removing the bugs, making modifications, or adding new features are only matter of rewriting the software that controls the device. Or in other words embedded computer systems are electronic systems that include a microcomputer to perform a specific dedicated application. The computer is hidden inside these products. Embedded systems are ubiquitous. Every week millions of tiny computer chips come pouring out of factories finding their way into our everyday products. Embedded systems are self-contained programs that are embedded within a piece of hardware. Whereas a regular computer has many different applications and software that can be applied to various tasks, embedded systems are usually set to a specific task that cannot be altered without physically manipulating the circuitry. Another way to think of an embedded system is as a computer system that is created with optimal efficiency, thereby allowing it to complete specific functions as quickly as possible. Embedded systems designers usually have a significant grasp of hardware technologies. They use specific programming languages and software to develop embedded systems and manipulate the equipment. When searching online, companies offer embedded systems development kits and other embedded systems tools for use by engineers and businesses. Embedded systems technologies are usually fairly expensive due to the necessary development time and built in efficiencies, but they are also highly valued in specific industries. Smaller businesses may wish to hire a consultant to determine what sort of embedded systems will add value to their organization.
CHARACTERISTICS: Two major areas of differences are cost and power consumption. Since many embedded systems are produced in tens of thousands to millions of units range, reducing cost is a major concern. Embedded systems often use a (relatively) slow processor and small memory size to minimize costs. The slowness is not just clock speed. The whole architecture of the computer is often intentionally simplified to lower costs. For example, embedded systems often use peripherals controlled by synchronous serial interfaces, which are ten to hundreds of times slower than comparable peripherals used in PCs. Programs on an embedded system often run with real-time constraints with limited hardware resources: often there is no disk drive, operating system, keyboard or screen. A flash drive may replace rotating media, and a small keypad and LCD screen may be used instead of a PC's keyboard and screen. Firmware is the name for software that is embedded in hardware devices, e.g. in one or more ROM/Flash memory IC chips. Embedded systems are routinely expected to maintain
100% reliability while running continuously for long periods, sometimes measured in years. Firmware is usually developed and tested too much harsher requirements than is general purpose software, which can usually be easily restarted if a problem occurs.
PLATFORM: There are many different CPU architectures used in embedded designs. This in contrast to the desktop computer market which is limited to just a few competing architectures mainly the Intel/AMD x86 and the Apple/Motorola/IBM Power PCs which are used in the Apple Macintosh. One common configuration for embedded systems is the system on a chip, an application-specific integrated circuit, for which the CPU was purchased as intellectual property to add to the IC's design.
TOOLS: Like a typical computer programmer, embedded system designers use compilers, assemblers and debuggers to develop an embedded system. Those software tools can come from several sources: Software companies that specialize in the embedded market Ported from the GNU software development tools. Sometimes, development tools for a personal computer can be used if the embedded processor is a close relative to a common PC processor. Embedded system designers also use a few software tools rarely used by typical computer programmers. Some designers keep a utility program to turn data files into code, so that they can include any kind of data in a program. Most designers also have utility programs to add a checksum or CRC to a program, so it can check its program data before executing it.
OPERATING SYSTEM: They often have no operating system, or a specialized embedded operating system (often a real-time operating system), or the programmer is assigned to port one of these to the new system.
DEBUGGING: Debugging is usually performed with an in-circuit emulator, or some type of debugger that can interrupt the micro controllers internal microcode. The microcode interrupt lets the debugger operate in hardware in which only the CPU works. The CPU-based debugger can be used to test and debug the electronics of the computer from the viewpoint of the CPU. Developers should insist on debugging which shows the high-level language, with breakpoints and single stepping, because these features are widely available. Also, developers should write and use simple logging facilities to debug sequences of real-time events. PC or mainframe programmers first encountering this sort of programming often become confused about design priorities and acceptable methods. Mentoring, code-reviews and ego less programming are recommended.
DESIGN OF EMBEDDED SYSTEMS: The electronics usually uses either a microprocessor or a microcontroller. Some large or old systems use general-purpose mainframes computers or minicomputers. START-UP: All embedded systems have start-up code. Usually it disables interrupts, sets up the electronics, tests the computer (RAM, CPU and software), and then starts the application code. Many embedded systems recover from short-term power failures by restarting (without recent self-tests). Restart times under a tenth of a second are common. Many designers have found one of more hardware plus software-controlled LEDs useful to indicate errors during development (and in some instances, after product release, to produce troubleshooting diagnostics). A common scheme is to have the electronics turn off the LED(s) at reset, whereupon the software turns it on at the first opportunity, to prove that the hardware and start-up software have performed their job so far. After that, the software blinks the LED(s) or sets up light patterns during normal operation, to indicate program execution progress and/or errors. This serves to reassure most technicians/engineers and some users. THE CONTROL LOOP: In this design, the software has a loop. The loop calls subroutines. Each subroutine manages a part of the hardware or software. Interrupts generally set flags, or update counters that are read by the rest of the software. A simple API disables and enables interrupts. Done right, it handles nested calls in nested subroutines, and restores the preceding interrupt state in the outermost enable. This is one of the simplest methods of creating an exocrine. Typically, there's some sort of subroutine in the loop to manage a list of software timers, using a periodic real time interrupt. When a timer expires, an associated subroutine is run, or flag is set. Any expected hardware event should be backed-up with a software timer. Hardware events fail about once in a trillion times. State machines may be implemented with a function-pointer per state-machine (in C++, C or assembly, anyway). A change of state stores a different function into the pointer. The function pointer is executed every time the loop runs. Many designers recommend reading each IO device once per loop, and storing the result so the logic acts on consistent values. Many designers prefer to design their state machines to check only one or two things per state. Usually this is a hardware event, and a software timer. Designers recommend that hierarchical state machines should run the lowerlevel state machines before the higher, so the higher run with accurate information. Complex functions like internal combustion controls are oft en handled with multidimensional tables. Instead of complex calculations, the code looks up the values. The software can interpolate between entries, to keep the tables small and cheap. One major disadvantage of this system is that it does not guarantee a time to respond to any particular hardware event. Careful coding can easily assure that nothing disables interrupts for long. Thus interrupt code can run at very precise timings. Another major weakness of this system is that it can become complex to add new features. Algorithms that take a long time to
run must be carefully broken down so only a little piece gets done each time through the main loop. This system's strength is its simplicity, and on small pieces of software the loop is usually so fast that nobody cares that it is not predictable. Another advantage is that this system guarantees that the software will run. There is no mysterious operating system to blame for bad behavior.
USER INTERFACES: Interface designers at PARC, Apple Computer, Boeing and HP minimize the number of types of user actions. For example, use two buttons (the absolute minimum) to control a menu system (just to be clear, one button should be "next menu entry" the other button should be "select this menu entry"). A touch-screen or screen-edge buttons also minimize the types of user actions. Another basic trick is to minimize and simplify the type of output. Designs should consider using a status light for each interface plug, or failure condition, to tell what failed. A cheap variation is to have two light bars with a printed matrix of errors that they select- the user can glue on the labels for the language that she speaks. For example, Boeing's standard test interface is a button and some lights. When you press the button, all the lights turn on. When you release the button, the lights with failures stay on. The labels are in Basic English. Designers use colors. Red defines the users can get hurt- think of blood. Yellow defines something might be wrong. Green defines everything's OK. Another essential trick is to make any modes absolutely clear on the user's display. If an interface has modes, they must be reversible in an obvious way. Most designers prefer the display to respond to the user. The display should change immediately after a user action. If the machine is going to do anything, it should start within 7 seconds, or give progress reports. One of the most successful general-purpose screen-based interfaces is the two menu buttons and a line of text in the user's native language. It's used in pagers, medium-priced printers, network switches, and other medium-priced situations that require complex behavior from users. When there's text, there are languages. The default language should be the one most widely understood.
KIEL U VISION2:
This is an IDE (Integrated Development Environment) that helps you write, compile, and debug embedded programs. It encapsulates the following components: A project manager A make facility Tool configuration Editor A powerful debugger To get start here are some several example programs
CREATING YOUR OWN APPLICATION IN UVISION2: To create a new project in uVision2, you must:
o Select Project - New Project. o Select a directory and enter the name of the project file. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the Device Database Create source files to add to the project. Select Project - Targets, Groups, and Files. Add/Files, select Source Group1, and add the source files to the project. Select Project - Options and set the tool options. Note when you select the target device from the Device Database all-special options are set automatically. You only need to configure the memory map of your target hardware. Default memory model settings are optimal for most.
APPLICATIONS:
Select Project - Rebuild all target files or Build target.
. . . .
EVALUATION SOFTWARE:
. . . Code-Banking Linker/Locator Library Manager. RTX-51 Tiny Real-Time Operating System
PERIPHERAL SIMULATION:
The u vision2 debugger provides complete simulation for the CPU and on ch ip peripherals of most embedded devices. To discover which peripherals of a device are supported, in u vision2. Select the Simulated Peripherals item from the Help menu. You may also use the web-based device database. We are constantly adding new devices and simulation support for on-chip peripherals so be sure to check Device Database often.
SOFTWARE DESCRIPTION : 1. 2.
Click on the Keil uVision Icon on DeskTop The following fig will appear
3. 4.
Click on the Project menu from the title bar Then Click on New Project
5.
Save the Project by typing suitable project name with no extension in u r own folder sited in either C:\ or D:\
6. 7. 8.
Then Click on Save button above. Select the component for u r project. i.e. Atmel Click on the + Symbol beside of Atmel
9.
10. 11.
Then Click either YES or NOmostly NO Now your project is ready to USE Now double click on the Target1, you would get another option Source group 1 as shown in next page.
15.
Click on the file option from menu bar and select new
16.
The next screen will be as shown in next page, and just maximize it by double clicking on its blue boarder.
17.
18.
For a program written in Assembly, then save it with extension . asm and for C based program save it with extension .C
19.
Now right click on Source group 1 and click on Add files to Group Source
20.
Now you will get another window, on which by default C files will appear.
Now select as per your file extension given while saving the file Click only one time on option ADD Now Press function key F7 to compile. Any error will appear if so happen.
24. 25.
If the file contains no error, then press Control+F5 simultaneously. The new window is as follows
26. 27.
Then Click OK Now Click on the Peripherals from menu bar, and check your required port as shown in fig below
28. 29.
Now keep Pressing function key F11 slowly and observe. You are running your program successfully
MICROPROCESSOR VS MICROCONTROLLER:
Microprocessor: y CPU is stand-alone, RAM, ROM, I/O, timer are separate y Designer can decide on the amount of ROM, RAM and I/O ports. y expensive y versatility general-purpose
Microcontroller:
CPU, RAM, ROM, I/O and timer are all on a single chip fix amount of on-chip ROM, RAM, I/O ports for applications in which cost, power and space are critical single-purpose
MICROCONTROLLER AT89S52
FEATURES: 8K Bytes of In-System Reprogrammable Flash Memory Endurance: 1,000 Write/Erase Cycles Fully Static Operation: 0 Hz to 24 MHz 256 x 8-bit Internal RAM 32 Programmable I/O Lines Three 16-bit Timer/Counters Eight Interrupt Sources Programmable Serial Channel Low-power Idle and Power-down Modes
DESCRIPTION:
The AT89S52 is a low-power, high-performance CMOS 8-bit microcomputer with 8Kbytes of Flash programmable and erasable read only memory (PEROM). The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89S52 is a powerful microcomputer, which provides a highly flexible and costeffective solution to many embedded control applications.
Port 0:
Port 0 is an 8-bit open drain bi-directional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high-impedance inputs. Port 0 can also be configured to be the multiplexed low order address/data bus during accesses to external program and data memory. In this mode, P0 has internal pull-ups. Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification. External pull ups are required during program verification.
Port 1:
Port 1 is an 8-bit bi-directional I/O port with internal pull -ups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pull -ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (I IL ) because of the internal pull-ups. In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX), respectively.
PORT PIN ALTERNATE FUNCTIONS: P1.0 T2 (external count input to Timer/Counter 2), clock-out P1.1 T2EX (Timer/Counter 2 capture/reload trigger and direction control Port 2:
Port 2 is an 8-bit bi-directional I/O port with internal pull -ups. The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (I IL) because of the internal pull-ups. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that uses 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s. During accesses to external data memory that uses 8 -bit addresses (MOVX @ RI); Port 2 emits the contents of the P2 Special Function Register. Port 2 also receives the high-order address bits and some control signals during Flash programming and verification.
Port 3:
Port 3 is an 8-bit bi-directional I/O port with internal pull -ups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the internal pull -ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (I IL) because of the pull-ups. Port 3 also serves the functions of various special features of the AT89C51. Port 3 also receives some control signals for Flash programming and verification.
RST:
Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device.
ALE/PROG:
Address Latch Enable is an output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during flash programming. In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator frequency and may be used for external timing or clocking purposes. However, that one ALE pulse is skipped during each access to external data memory. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE -disable bit has no effect if the microcontroller is in external execution mode.
PSEN:
Program Store Enable is the read strobe to extern al program memory. When the AT89C52 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory.
EA/VPP:
External Access Enable (EA) must be strapped to GND in order to enable the device to fetch code from external pro -gram memory locations starting at 0000H up to FFFFH. However, if lock bit 1 is programmed, EA will be internally latched on reset. EA should be strapped to VCC for internal program executions. This pin also receives the 12V programming enable voltage (VPP) during Flash programming when 12V programming is selected. Input to the inverting oscillator amplifier and input to the internal clock operating circuit.
XTAL1:
XTAL2:
EXTERNAL INTERRUPTS INTERRUPT CONTROL ON-CHIP ROM FOR PROGRAM CODE ONCHIP RAM
TIMER/CO UNTER
TIMER 1 TIMER 0
COUNTER INPUTS
CPU
OSC
BUS CONTROL
4 I/O PORTS
SERIAL PORT
P0 P1 P2 P3
TX
Rx
OSCILLATOR CHARACTERISTICS:
XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier, which can be configured for use as an on-chip oscillator. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should be left unconnected while XTAL1 is driven. There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed.
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 functions registers remain unchanged during this mode. The idle mode can be terminated by any enabled interrupt or by a hardware reset. It should be noted that when idle is terminated by a hardware reset, the device normally resumes program execution, from where it left off, up to two machine cycles before the internal reset algorithm takes control. On-chip hardware inhibits access to internal RAM in this event, but access to the port pins is not inhibited. To eliminate the possibility of an unexpected write to a port pin when Idle is terminated by reset, the instruction following the one that invokes Idle should not be one that writes to a port pin or to external memory.
OSCILLATOR CONNECTIONS:
OSCILLATOR CONNECTIONS:
Note: C1, C2 = 30 pF 10 pF for Crystal = 40 pF
3. PROJECT DESCRIPTION
DESIGNING:
Since the main intension of this project is to atomize the car parking system . In order to fulfill this application there are few steps that has been performed i.e. 1) Designing the power supply for the entire circuitry. 2) Selection of microcontroller that suits our application. 3) Selection of data cable which acts as transreciever between pc and micro controller. 4) Selection of RELAYS. Complete studies of all the above points are useful to develop this project.
SELECTION OF MICROCONTROLLER:
As we know that there so many types of micro controller families that are available in the market. Those are 1) 8051 Family 2) AVR microcontroller Family 3) PIC microcontroller Family 4) ARM Family Basic 8051 family is enough for our application; hence we are not concentrating on higher end controller families. In order to fulfill our application basic that is AT89S51 controller is enough. But still we selected AT89S52 controller because of inbuilt ISP (in system programmer) option. There are minimum six requirements for proper operation of microcontroller. Those are: 1) power supply section 2) pull-ups for ports (it is must for PORT 0) 3) Reset circuit 4) Crystal circuit 5) ISP circuit (for program dumping) 6) EA/VPP pin is connected to Vcc. PORT0 is open collector thats why we are using pull-up resistor which makes PORT0 as an I/O port. Reset circuit is used to reset the microcontroller. Crystal circuit is used for the microcontroller for timing pluses. In this project we are not using external memory thats why EA/VPP pin in the microcontroller is connected to Vcc that indicates internal memory is used for this application.
SELECTION OF RELAYS:
A relay is an electrically operated switch. Many relays use an electromagnet to operate a switching mechanism mechanically, but other operating principles are also used. Relays are used where it is necessary to control a circuit by a low-power signal (with complete electrical isolation between control and controlled circuits), or where several circuits must be controlled by one signal. The first relays were used in long distance telegraph circuits, repeating the signal coming in from one circuit and re-transmitting it to another. Relays were used extensively in telephone exchanges and early computers to perform logical operations.
: MAX The max 232 IC i al known as level cont oller. It converts the logic level at microcontroller to the logic level at the computer. It supports rs232 protocol. The M X232 is a dual driver/receiver that includes a capacitive voltage generator to suppl TIA/EIA-232-F voltage levels from a single 5-V suppl . Each receiver converts TIA/EIA-232F inputs to 5-V TTL/CM levels. These receivers have a t pical threshold of 1.3 V, a t pical hysteresis of 0.5 V, and can accept 30-V inputs. Each driver converts TTL/CM input levels into TIA/EIA-232-F levels
CIRCUIT OPERATION: In this design, we use at89S52 microcontroller which is a mini cpu and acts as the processing unit in the project. The code is written in embedded c language which is compiled using keil microvision software with the project name and thus it is compiled. The power supply present circuit will be supplying power to the circuit and step down transformer is used for providing the 5v and 12v supply to the microcontroller and the relays. Max 232 will be acting as the level controller between the pc and the microcontroller. i.e, it converts the voltage levels from high level to low or vice versa. The medium of input is keyboard. Some predefined keys are allotted to the devices. Then the input given through the key board will be transferred through the serial cable which is connected to the computers male pin. The relays will act as the switches for the devices. The device will be ON/OFF if it is OFF/ON. The status of the device is displayed on the pcs
In order to connect micro controller to a modem or a pc to modem a serial port is used. Serial is a very common protocol for device communication that is standard on almost every PC. Most computers include two RS-232 based serial ports. Serial is also a common communication protocol that is used by many devices for instrumentation. Furthermore, serial communication can be used for data acquisition in conjunction with a remote sampling device. The concept of serial communication is simple. The serial port sends and receives bytes of information one bit at a time. Although this is slower than parallel communication, which allows the transmission of an entire byte at once, it is simpler and can be used over longer distances. For example, the IEEE 488 specifications for parallel communication state that the cabling between equipment can be no more than 20 meters total, with no more than 2 meters between any two devices. Serial, however, can extend as much as 1200 meters. Typically, serial is used to transmit ASCII data. Communication is completed using 3 transmission lines: (1) Ground, (2) Transmit, and (3) Receive. Since serial is asynchronous, the port is able to transmit data on one line while receiving data on another. Other lines are available for handshaking, but are not required. The important serial characteristics are baud rate, data bits, stop bits, and parity. For two ports to communicate, these parameters must match. Baud rate: It is a speed measurement for communication. It indicates the number of bit transfers per second. For example, 300 baud is 300 bits per second. When a clock cycle is referred it means the baud rate. For example, if the protocol calls for a 4800 baud rate, then the clock is running at 4800Hz. This means that the serial port is sampling the data line at 4800Hz. Common baud rates for telephone lines are 14400, 28800, and 33600. Baud rates greater than these are possible, but these rates reduce the distance by which devices can be separated. These high baud rates are used for device communication where the devices are located together.
Data bits: A measurement of the actual data bits in a transmission. When the computer sends a packet of information, the amount of actual data may not be a full 8 bits. Standard values for the data packets are 5, 7, and 8 bits. in Which settings chosen depends on what information transferred. For example, standard ASCII has values from 0 to 127 (7 bits). Extended ASCII uses 0 to 255 (8 bits). If the data being transferred is simple text (standard ASCII), then sending 7 bits of data per packet is sufficient for communication. A packet refers to a single byte transfer, including start/stop bits, data bits, and parity. Since the number of actual bits depend on the protocol selected, the term packet is used to cover all instances. Stop bits: These bits are used to signal the end of communication for a single packet. Typical values are 1, 1.5, and 2 bits. Since the data is clocked across the lines and each device has its own clock, it is possible for the two devices to become slightly out of sync. Therefore, the stop bits not only indicate the end of transmission but also give the computers some room for error in the clock speeds. The more bits that are used for stop bits, the greater the lenience in synchronizing the different clocks, but the slower the data transmission rate.
Parity: A simple form of error checking that is used in serial communication. There are four types of parity: even, odd, marked, and spaced. The option of using no parity is also available. For even and odd parity, the serial port sets the parity bit (the last bit after the data bits) to a value to ensure that the transmission has an even or odd number of logic high bits. For example, if the data is 011, then for even parity, the parity bit is 0 to keep the number of logic-high bits even. If the parity is odd, then the parity bit is 1, resulting in 3 logic-high bits. Marked and spaced parity does not actually check the data bits, but simply sets the parity bit high for marked parity or low for spaced parity. This allows the receiving device to know the state of a bit to enable the device to determine if noise is corrupting the data or if the transmitting and receiving device clocks are out of sync. RS 232C PROTOCOL: RS-232 (ANSI/EIA-232 Standard) is the serial connection found on IBM-compatible PCs. It is used for many purposes, such as connecting a mouse, printer, or modem, as well as industrial instrumentation. Because of improvements in line drivers and cables, applications often increase the performance of RS-232 beyond the distance and speed listed in the standard. RS-232 is limited to point-to-point connections between PC serial ports and devices. RS232 hardware can be used for serial communication up to distances of 50 feet. DB-9 pin connector: 12345 6789
(end of cable Out of computer and exposed) PIN FUNCTONS: Data: Handshake:
TxD on pin 3, RxD on pin 2 RTS on pin 7, CTS on pin 8, DSR on pin 6, CD on pin 1, DTR on pin 4 Common: Common pin 5(ground) Other: RI on pin 9 The method used by RS-232 for communication allows for a simple connection of three lines: Tx, Rx, and Ground The three essential signals for 2 ways RS-232 Communications are these: TXD: carries data from DTE to the DCE. RXD: carries data from DCE to the DTE SG: signal ground
ECTION DIAGRAM:
GND
MAX TMOD:
T :
TH T
D i id e d b
D i id e d b
D i id e d b X B a u d R a te UART
Di ided b X box can be replaced with T timer so that b changing the alue of timer we can obtain the required b aud rate. et XCl = . 59 MHz / 6/ /X ) Baud Rate = (XCl / For attaining 96 baud Rate, Xcan be calculated = . 59 x 6 / / 6/ = aud So set the s Complement of in Timer so that we can achie e 96 b rates.
XC l
SM
SM
SM
Embedded Controller
RX D
TX D
TX D
RX D
Note: Assuming 8- it Auto reload mode and 8- it varia le aud rate modes. FLOW C ART: TX Loop:
RX Loop:
TART
TOP
: CONNECT ONS IN MAX f e ant to do a general R -232 onne tion, e ould take a un of long ires and solder t em dire tl to t e ele troni ir uits of t e equipment ou are using, ut t is tends to make a ig mess and often t ose solder onne tions tend to reak and ot er pro lems an develop. To deal it t ese issues, and to make it easier to setup or take do n equipment, some standard onne tors ave een developed t at is ommonl found on most equipment using t e R -232 standards. T ese onne tors ome in t o forms: A male and a female onne tor. T e female onne tor as oles t at allo t e pins on t e male end to e inserted into t e onne tor. T is is a female "D -9" onne tor (properl kno n as DE9F):
Fig Female Connector T e female D -9 onne tor is t pi all used as t e "plug" t at goes into a t pi al PC. f ou see one of t ese on t e a k of our omputer, it is likel not to e used for serial ommuni ation, ut rat er for t ings like earl VGA or CGA monitors (not VGA) or for some spe ial ontrol/jo sti k equipment. And t is is a male "D -9" onne tor (properl kno n as DE9M ):
!
C op
F in to Mem o r
# ""
n itiali a tio n : L o ad F R s
i t R esp e t iv e v alu es
C lr R
This is the connector that you are more likely to see for serial communications on a "generic" C. Often you will see two of them side y side (for COM1 and COM2). Special equipment that you might communicate with would have either connector, or even one of the DB connectors listed -25 elow. The wiring of RS-232 devices involves first identifying the actual pins that are eing used. ere is how a female DB-9 connector is num ered:
If the num ers are hard to read, it starts at the top-right corner as "1", and goes left until the end of the row and then starts again as pin 6 on the next row until you ge to pin 9 on the ottom-left pin. t "Top" is defined as the row with 5 pins. The male connector (like what you have on your C) is simply this same order, ut reversed from right to left. ere each pin is usually defined as: 9-pin 1 2 3 4 5 6 7 8 9 25-pin 8 3 2 20 7 6 4 5 22 TX ( DT G DSR R C pin definition
Table. Pin Definition of Connectors One thing to keep in mind when discussing these pins and their meaning is that they are very closely tied together with modems and modem protocols. Often we don't have a modem attached in the loop, ut we still treat the equipment as if it were a modem on a theoretical level. BAUD RATES: Baud and B S (Bits er Second) are usually not the same thing, although they are often used interchangea le, particular in marketing literature. Only originally they were the same. There are
several ways to determine what the actual data rate of a particular piece of equipment is, but in popular marketing literature, or even general reference texts, they will almost always refer to "Baud Rate", even if they are referring to bits per second. Language purists and engineers who know what they are talking about will go into a more literal definition of Baud meaning the number of changes to the transmission media per second in a modulated signal. If each transmission event contains more than one bit of information, than Baud and BPS are not the same. E.g. if each event contains two bits (two bits modulated in an event), then the BPS of such a transmission would be twice as large as the Baud rate. This is not a theoretical case. Typical "high speed" modems use sophisticated modulation on the telephone line, were the bit rate and Baud rate differ significantly on the line. It is important to know this when you build measurement equipment, decoders (demodulators), encoders (modulators), and all sorts of transmission equipment for a particular protocol. However, software developers typically like to ignore the difference of bit rate and baud rate, because in their small world, a bit can either have the value true or false - an "event" (a bit) always only has two possible states. They have no basic unit which can e.g. hold four different states. In other words, on the software site the modulation has already been flattened by the demodulator. If a modulation was used which can e.g. transmit 8 bits in an event, the software developer sees them already as a series of 8 consecutive bits, each either true or false. The demodulator took care of that. When it got an event it turned the single 8-bit event into eight single-bit events. Software developers don't see the original single entity with 256 different states (voltages, phases). Since the modulation has been flattened they don't experience the difference between Baud rate and bit rate any more. This is not the fault of the people who defined a Baud or a BPS. It is just a (welcome) limitation of digital computer hardware. Baud is actually a shortened term named in honor of mile Baudot, a French inventor of early teleprinter machines that replaced the telegraph key using Morse Code. Basically two typewriters that could be connected to each other with some wires. He came up with some of the first digital character encoding schemes, and the character codes were transmitted with a serial data connection. In order for serial data communication to happen, we need to agree on a clock signal, or baud rate, in order to get everything to be both transmitted and received properly. This is where the language purists get into it, because it is this clock signal that actually drives the "baud rate" Data Transmission Rates: We got into a discussion of baud rate vs. bits per second. Here is where baud as the number of bits being transmitted is still off, even if the nominal bits per second is also the same as the baud rate. By adding start bits, stop bits, and parity bits, that is going to add overhead to the transmission protocol. All digital transmission protocols have some sort of overhead on them, so this shouldn't be that much of a surprise. As we get more into data packets and other issues, the actual amount of data being transmitted will drop even further. Keep in mind that If we are transmitting with 6 data bits, 2 Stop bits, and Even Parity, you are transmitting only six bits of data and four other bits of data. That means that even with 9600 baud, you are only transmitting 5,760 bits of data per second. That really is a big difference, and that is
still only raw bits once it gets through the actual serial communications channel. A more typical 8 data bits, 1 Stop Bit, No Parity will be a little bit better at 9600 baud, with eight bits of data and only two bits used for overhead. That gives a total throughput of 7,680 bits per second. A little bit better, but we can't simply presume that the baud rate indicates how much data is going to be transmitted. There is one final topic that we should keep in mind when you are doing serial communication over RS-232. There are some hard physical limits to how far serial data communication can occur over a piece of wire. When we apply a voltage onto a wire it takes some time for that voltage to go down the full length of the wire and there are other unstable conditions that happen when we send a "pulse" down the wire and change voltages too quickly. This problem is worse as wires become longer and the frequency (i.e. baud rate) increases. This distance can vary based on a number of factor, including the thickness of the wires involved, RF interference on the wires, quality of the wires during the manufacturing process, how well they were installed... e.g., are there any "kinks" in the wires that force it into a sharp bend, and finally the baud rate that we are transmitting the data. This table presumes a fairly straight and uniform cable that is typical for most low-voltage applications (i.e., not a power circuit that uses 110V to run your refrigerator, toaster, and television). Typically something like a CAT-5 cable (also used for local networks or phone lines) should be more than sufficient for this purpose. Baud rate 2400 4800 9600 1900 . Minimum distance 30 100 500 50
AT89S52 (MICROCONTROLLER) :
The Atmel AT89S8252 provides the following standard features: 8K bytes of downloadable Flash, 2K bytes of EEPROM, 256 bytes of RAM, 32 I/O lines, programmable watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S8252 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Powerdown mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next external interrupt or hardware reset.
Fig . IC7805
The 78xx (also sometimes known as LM78xx) series of devices is a family of self-contained fixed linear voltage regulator integrated circuits. The 78xx family is a very popular choice for
many electronic circuits which require a regulated power supply, due to their ease of use and relative cheapness. When specifying individual ICs within this family, the xx is replaced with a two-digit num er, which indicates the output voltage the particular device is designed to provide (for example, the 7805 has a 5 volt output, while the 7812 produces 12 vol s). The t 78xx line are positive voltage regulators, meaning that they are designed to produce a voltage that is positive relative to a common ground. There is a related line of 79xx devices which are complementary negative voltage regulators. 78xx and 79xxICs can e used in com ination to provide oth positive and negative supply voltages in the same circuit, if necessary.
78xx ICs have three terminals and are most commonly found in the TO220 form factor, although smaller surface-mount and larger TO3 packages are also availa le from some manufacturers. These devices typically support an input voltage which can e anywhere from a couple of volts over the intended output voltage, up to a maximum of 35 or 40 volts, and can typically provide up to around 1 or 1.5 amps of current (though smaller or larger packages may have a lower or higher current rating). TRANSFORMER:
Definition: The transformer is a static electro-magnetic device that transforms one alternating voltage (current) into another voltage (current). owever, power remains the some during the transformation. Transformers play a major role in the transmission and distri ution of ac power.
Princi le: Transformer works on the principle of mutual induction. A transformer consists of laminated magnetic core forming the magnetic frame. rimary and secondary coils are wound upon the two cores of the magnetic frame, linked y the common magnetic flux. When an alternating voltage is applied across the primary coil, a current flows in the primary coil producing magnetic flux in the transformer core. This flux induces voltage in secondary coil. Thus the working of the transformer.
Transformers are classified as: (a) Based on position of the windings with respect to core i.e. 1) Core type transformer 2) Shell type transformer (b) Transformation ratio: 1) Step up transformer 2) Step down transformer a) Core & shell types: Transformer is simplest electrical machine, which consists of windings on the laminated magnetic core. There are two possibilities of putting up the windings on the core. 1) Winding encircle the core in the case of core type transformer 2) Cores encircle the windings on shell type transformer. b) Step up and Step down: In these voltage transformation takes place according to whether the primary is high voltage coil or a low voltage coil. 1) 2) Lower to higher-> Step up Higher to lower-> Step down
CRYSTAL:
A piezoelectric crystal is an electronic circuit that uses the mechanical resonance of a vibrating crystal of piezoelectric material to create an electrical signal with a very precise frequency. This frequency is commonly used to keep track of time (as in quartz wristwatches), to provide a stable clock signal for digital integrated circuits, and to stabilize frequencies for radio transmitters and receivers. The most common type of piezoelectric resonator used is the quartz crystal, so oscillator circuits designed around them were called "crystal oscillators".
Fi ure. Crystal
The crystal oscillator circuit sustains oscillation by taking a voltage signal from the quartz resonator, amplifying it, and feeding it back to the resonator. The rate of expansion and contraction of the quartz is the resonant frequency, and is determined by the cut and size of the crystal. When the energy of the generated output frequencies matches the losses in the circuit, an oscillation can be sustained. A regular timing crystal contains two electrically conductive plates, with a slice or tuning fork of quartz crystal sandwiched between them. During startup, the circuit around the crystal applies a random noise AC signal to it, and purely by chance, a tiny fraction of the noise will be at the resonant frequency of the crystal. The crystal will therefore start oscillating in synchrony with that signal. As the oscillator amplifies the signals coming out of the crystal, the signals in the crystal's frequency band will become stronger, eventually dominating the output of the oscillator. Natural resistance in the circuit and in the quartz crystal filter out all the unwanted frequencies. 4.2.6. DIODE:-
Fi ure. Diode
A diode is a two-terminal device. Diodes have two active electrodes between which the signal of interest may flow, and most are used for their unidirectional electric current property. The unidirectionality most diodes exhibit is sometimes generically called the rectifying property. The most common function of a diode is to allow an electric current in one direction (called the forward biased condition) and to block the current in the opposite direction (the reverse biased condition). Thus, the diode can be thought of as an electronic version of a check valve.
&
Real diodes do not display such a perfect on-off directionality but have a more complex non-linear electrical characteristic, which depends on the particular type of diode technology. Diodes also have many other functions in which they are not designed to operate in this on-off manner.
RESISTORS:
A Resistor is a heat-dissipating element and in the electronic circuits it is mostly used for either controlling the current in the circuit or developing a voltage drop across it, which could be utilized for many applications. There are various types of resistors, which can be classified according to a number of factors depending upon: (I) (II) (III) Material used for fabrication Wattage and physical size cost
SOURCE CODE FOR "PC BASED DEVICE CONTROL" CPU = 89S52 11.0592 MHZ
XAT1 =
DELAY_TEMP_3 DELAY_TEMP_2 DELAY_TEMP_1 DEV_FLAG DEV4 DEV3 DEV2 DEV1 ORG MOV MOV 00H
30H 31H 32H 33H P2.0 P2.1 P2.2 P2.4 ; start here
P2, #00H
DEV_FLAG, #0FFH ;
SERIAL_MODE: ;*************settings for serial mode activation***************** MOV TMOD, #20H MOV TH1, #0FDH MOV SCON, #50H SETB TR1 CALL D_1SEC MOV DPTR, #WELCOME_MESSAGE LOOP_WELCOME_MSG: CLR A ; wait for 1 sec ; welcome message
WELCOME_EXIT: CALL NEW_LINE MOV CALL CALL A, #0DH TRANS D_1SEC ; NEW LINE
CALL CALL
GENERAL_MSG RECIVE_DATA
************LOOP FOR CONTROLLING DEVICE 1************* CJNE MOV JB CALL SETB MOV CALL A,#"1",CHK2 A, DEV_FLAG ACC.7,OFF_DEV1 DEV1_OFF ACC.7 DEV_FLAG,A NEW_LINE ;compare with 1 if match come down....if not jump to CHK2
JZ CALL INC JMP EXT11: CALL JMP OFF_DEV1: CLR MOV CALL CALL CALL MOV LOOP12: CLR MOVC JZ CALL INC JMP EXT12: JMP
DEV1_ON WELCOME_EXIT
WELCOME_EXIT
;***********************************************************
CHK2: CJNE MOV JB CALL SETB MOV CALL CALL MOV LOOP21: CLR MOVC JZ A A, @A+DPTR EXT21 A, #"2", CHK3 ; compare with 2 if match come down....if not jump to CHK3 A, DEV_FLAG ; copy device ON/OFF information ; check if ON/OFF ; call device off
OFF_DEV2: CLR MOV CALL CALL CALL MOV LOOP22: ACC.6 DEV_FLAG, A DEV2_ON NEW_LINE D_5MSEC DPTR, #DEV2_ON_MSG ; print device on msg
CLR
MOVC A, @A+DPTR JZ CALL INC JMP EXT22: JMP WELCOME_EXIT EXT22 TRANS DPTR LOOP22
;******************************************************************** ;**************LOOP FOR CONTROLLING DEVICE 3******************* CHK3: CJNE MOV JB A, A, ACC.5, #"3"CHK4 DEV_FLAG OFF_DEV3
CALL DEV3_OFF SETB ACC.5 MOV CALL CALL MOV LOOP31: CLR MOVC JZ CALL A A,@A+DPTR EXT31 TRANS DEV_FLAG,A NEW_LINE D_5MSEC DPTR, #DEV3_OFF_MSG
INC JMP EXT31: JMP OFF_DEV3: CLR MOV CALL CALL CALL MOV LOOP32: CLR MOVC JZ CALL INC JMP EXT32: JMP
DPTR LOOP31
WELCOME_EXIT
A A, @A+DPTR
WELCOME_EXIT
;**************LOOP FOR CONTROLLING DEVICE 3******************* CHK4: CJNE A, #"4", EXIT MOV A, JB ACC.4, DEV_FLAG OFF_DEV4
MOV DPTR, #DEV4_OFF_MSG LOOP41: CLR MOVC A, JZ CALL INC JMP EXT41: JMP OFF_DEV4: CLR MOV CALL CALL CALL MOV LOOP42: CLR MOVC A, JZ CALL A @A+DPTR EXT42 TRANS ACC.4 DEV_FLAG,A DEV4_ON NEW_LINE D_5MSEC DPTR,#DEV4_ON_MSG WELCOME_EXIT A @A+DPTR EXT41 TRANS DPTR LOOP41
DPTR LOOP42
WELCOME_EXIT
;******************************************************************** EXIT: CALL MOV ERR_LOOP: CLR MOVC JZ CALL INC JMP ERR_EXIT: CALL JMP D_1SEC WELCOME_EXIT A A, @A+DPTR ERR_EXIT TRANS DPTR ERR_LOOP NEW_LINE DPTR,#ERR_MSG
*************************************************** DEV1_ON: SETB RET DEV1_OFF: CLR RET DEV2_ON: SETB DEV2 ; ON DEVICE 2 DEV1 ; OFF DEVICE 1 ; RETURN DEV1 ; ON DEVICE 1 ; RETURN
RET DEV2_OFF: CLR RET DEV3_ON: SETB RET DEV3_OFF: CLR RET DEV4_ON: SETB RET DEV4 DEV3 DEV3 DEV2
; RETURN
; ON DEVICE 3 ; RETURN
; ON DEVICE 4 ; RETURN
***************LOOP FOR DISPLAYING GENERAL_MSG*************** GENERAL_MSG: CALL MOV NEW_LINE DPTR, #GENERAL_MSG1
INC JMP
DPTR GEN_MSG1_LOOP
GEN_MSG2_LOOP: CLR MOVC JZ CALL INC JMP A A, @A+DPTR START_GEN_MSG3 TRANS DPTR GEN_MSG2_LOOP
MOV DPTR, #GENERAL_MSG3 GEN_MSG3_LOOP: CLR MOVC JZ CALL INC JMP A A, @A+DPTR
GEN_MSG4_LOOP: CLR A
A,
EXIT_GEN_MSG: CALL RET ;************************************************************ NEW_LINE: MOV A, CALL MOV CALL RET ;******************************************************** ;**********loop for transmitting*************** ;******************************************************** TRANS: MOV JNB CLR RET SBUF, A TI, TI $ A, #0AH TRANS #0DH TRANS NEW_LINE
RECIVE_DATA: CLR JNB MOV CLR RET ;******************************************************** ;************************** ****************************** D_5MSEC: MOV YY: Y1: MOV NOP NOP DJNZ DJNZ RET DELAY_TEMP_1, Y1 DELAY_TEMP_2, YY DELAY_TEMP_2, #5 DELAY_TEMP_1, #230 A, RI RI, $ SBUF RI
D_1SEC: MOV YYY4: YYY3: YYY2: MOV MOV NOP NOP DJNZ DELAY_TEMP_1, YY2 DJNZ DELAY_TEMP_2, YYY3 DJNZ DELAY_TEMP_3, YYY4 DELAY_TEMP_3, #10 DELAY_TEMP_2, #100 DELAY_TEMP_1, #230
5.RESULT
In our project we are using serial communication between the computer and the microcontroller and the devices. RS-232 is the communication medium between the microcontroller and the pc. Hence the device can be on/off by pressing the concerned keys on the keyboard. The main applications of the project are the home automation, industrial control and automation systems. We can increase to more than four also by increasing the relays and writng the code for the other systems. Hence, we can use this technology for the home automation system and industrial automation systems also.
6. FUTURE SCOPE
Further this project can be extended to more than four devices also by connecting the relays to the circuit and writing the code for the required devices. This can also be extended to the RF mode of communication by using the relays and the RF module, thus it can operated from far of a distance without any cable. This project can be done on mobile communication platform also.
7.BIBILIOGRAPHY