Professional Documents
Culture Documents
Advance Technology SCO-160, 1st Floor, Sec-24D Chandigarh 160022 Tel. No.: 0172 5086213
1
FOREWORD
With changing times micro-controller has evolved and today is part of almost every application viz. consumer electronics, communication systems automotive medical etc. With various controller architectures and easy to use compilers it has become easy to use a controller in wide range of applications with ease. There are many micro controllers available in market 89C51(ATMEL, PHILPS) PIC(MICROCHIP) etc.
With change in technology trends and introduction of latest protocols (CAN, MODBUS, I2C, SPI, USB) it is important to learn basics of micro controller with interfacing devices like SRAM, E2PROM, Stepper Motor, DC Motor, RTC, ADC, DAC, Relays, Displays. Keeping trends in mind Advance Technology has designed Universal Board. The feature that separates this board from others is the configuration of these different devices in desired fashion. User is free to assign any controller Port to the device with provided connectors. Since the Time to Market is crucial UNIVERSAL BOARD can reduce the development time since testing of basic devices can be done and by the time PCBs are manufactured designer is ready with the tested code.
2
INDEX
Sr.No.
1. 1.1 1.2 1.3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
TOPIC
Introduction of Microcontroller Board Hardware Description Software description In system Programming Mode Picture of Microcontroller board 8051 Microcontroller Section Block Diagram of 8051 8051 Microcontroller Board Sections Keyboard Section Buzzer Section ADC Section RS 232 Section LCD 16x2 Section LED Section 7-Segment Section Relay Section Stepper Motor Section DAC Section RTC& EPROM Section DIP Switch 4x4 Matrix Keypad Use of compiler
Page No.
5 5 5 5 6 7 10 11 13 13 14 17 19 20 21 22 24 27 28 30 32 33
20 21
Use of flash magic/ECE flash burner Experiments for 8051 microcontroller in c language
44 54
Section
you can choose any one to see output
KEYBOARD 4X4 KEY MATRIX BOARD DIP SWITCH DAC I2C ADC RELAY
Total Pin of Microcontroller = 40 Total I/O Lines Available = 32 Reserved for VCC & GND = 2
4
Reserved for Crystal Input & Output =2 Reserved for Programming & memory Interface = 4
INTRODUCTION
8051 MICROCONTROLLER BOARD
Hardware description The evaluation board consists of two major parts and provides a function to convert the parallel data bus to RS232 serial port and vice versa. Also, it provides an in-system programming function. The functions of the three two parts are described as follows: Philips P89v51RD2/P89c51RD2 is an 8051 microcontroller. The microcontroller connection to the RS232 is through the serial data bus and control signals - address, write, read, reset, and chip select signals. Philips RS-232 drivers/receivers are the transceivers. The first one allows the microcontroller to be in-system programmed through a PCs serial port such as COM1. The RS-232 mainlyconsists of two sections: drivers (transmitters) and receivers. The drivers convert the CMOS-logic output levels to RS-232 signals, whereas the receivers convert theRS-232 signals to CMOS-logic output levels. Software description The programming of the demo board can be done by writing firmware code requires the following software. Raisonance is one of the embedded system vendors that provide the development tools for the 8051 microcontroller. The software compiles the firmware code and generates an Intel Hex file. Flash Magic is a free Windows application software that allows easy programming of Philips Flash Microcontrollers. The software loads the Intel Hex file to the microcontroller by using its in-system programming mode communicating through serial port. In-system programming mode Philips P89C51RD2/P89V51RD2 microcontroller has an on-chip Flash program memory with ISP (In-System Programming), which allows the microcontroller to be programmed without removing the microcontroller from the board and also the microcontroller, which previously programmed can be reprogrammed without removal from the board. 5
The microcontroller must be powered up in a special ISP mode to perform the ISP operation. The ISP mode allows the microcontroller to communicate with a host device such as PC through a serial port. The host sends commands and data to the microcontroller. The commands can be erase, read, and write. After the completion of the ISP operation, the microcontroller is reconfigured and has to be reset or power cycled so the microcontroller will operate normally. The ISP programming for the device can be done using a Windows application software,which uses an Intel Hex file as input to program it. Conclusion The use of the evaluation kit allows the user to understand how the different external world devices are interfacing with a microcontroller such as 8051. The board shows the different peripheral devices. Which are describe below.
8051 microcontroller (P89C51RD2/P89V51RD2) section The P89C51RB2/RC2/RD2 device contains a non-volatile 16kB/32kB/64kB Flash program memory that is both parallel programmable and serial In-System and In-Application Programmable. In-System Programming (ISP) allows the user to download new code while the microcontroller sits in the application. In-Application Programming (IAP) means that the microcontroller fetches new program code and reprograms itself while in the system. This allows for remote programming over a modem link. A default serial loader (boot loader) program in ROM allows serial In-System programming of the Flash memory via the UART without the need for a loader in the Flash code. For In-Application Programming, the user program erases and reprograms the Flash memory by use of standard routines contained in ROM. This device executes one machine cycle in 6 clock cycles, hence providing twice the speed of a conventional 80C51. An OTP configuration bit lets the user select conventional 12 clock timing if desired. This device is a Single-Chip 8-Bit Microcontroller manufactured in advanced CMOS process and is a derivative of the 80C51 microcontroller family. The instruction set is 100% compatible with the 80C51 instruction set. The device also has four 8bit I/O ports, three 16-bit timer/event counters, a multi-source, four-priority-level, nested interrupt structure, an enhanced UART and on-chip oscillator and timing circuits. The added features of the P89C51RB2/RC2/RD2 makes it a powerful microcontroller for applications that require pulse width modulation, high-speed I/O and up/down counting capabilities such
JP1 PORT P0
JP4 PORT P2
8051 reset
connectors jp1,j p4, jp6, jp9 & jp10. There is flexibility to connect any port of 8051 with any section available on hardware board. port1 is devided into lower and upper for more flexibility to use. For the details of used select lines(i/o lines) for different hardware sections please study our example programs before work on hardware. Abbrivations use1L- lower four bits of port 1. 1u - upper four bits of port 1. Pin details for on board 6 & 10 pin connectors, all 6 pin & 10 pin connectors available on hardware board are standard pin specified according to images shown below. 6 pin connector
Gn d
3 2 1 0 Port bits
Vcc
Port bits 2 4
6 Gnd pin 10
Vcc pin 1
3 5 7 Port bits
10
(a) ADC section. (b) RTC & EEPROM section. (c) DISPLAY (LCD, LED, & 7-SEG) section. (d) INPUT SWITCHES (PUSH BUTTON & DIP SWITCH) section. (e) RELAY section. (f) BUZZER section (g) RS232 SECTION (h) 4X4 MATRIX KEYPAD SECTION (i) POWER SUPPLY SECTION (j) STEPPER MOTOR SECTION (k) DAC SECTION
PERIPHERALS
Part No. ADC0809CCN RTC DS1307 EPROM 24C04 LCD BUZZER RELAY DAC0808 STEPPER MOTOR 7-SEGMENT LED Specifications 8-BIT 8-CHANNEL, 100s. 64X8, SERIAL I2C Real Time Clock. 4K serial EEPROM. 16 x 2 character LCD 5V 5A/250V AC 8 bit+12vdc,-15v dc 5V COMMON ANODE 1.5V
POWER SUPPLY REQUIREMENTS Voltage Rating +/- 5 V +/- 12V Current Rating 1A 1A
12
13
KEY BOARD SECTION Key board is an input section with 4 switches to give input to microcontroller.with use of keyboard section we can put conditions on microcontroller to give or not give output. In this section a 6 pin connector is provided to connect with microcontroller any port .From right first pin is +5v dc(Vcc),second to fourth are switch select pin,with each pin switch is connected,from left first pin is ground(GND).
A Buzzer is output device having +ve and ve terminals ,which generate a tone when it get high signal on its positive terminal.these devices are capable of geneate sound ,such kind of devices can be used in hardwares like security systems and sensitive equipments to protect them from burn.For example if temperature of particular area rise over than prespecified temperature then a sound should generate.
Piecoelectric buzzer
CONNECTIONS-Connect jp23 of buzzer section with any port of microcontroller. For details of select pins(used i/o lines) see program of relay buzzer or simple buzzer program. buzzer or beeper is a signalling device, usually electronic, typically used in automobiles, household appliances such as a microwave oven, or game shows. It most commonly consists of a number of switches or sensors connected to a control unit that determines if and which button was pushed or a preset time has lapsed, and usually illuminates a light on the appropriate button or control panel, and sounds a warning in the form of a continuous or intermittent buzzing or beeping sound. Initially this device was based on an electromechanical system which was identical to an electric bell without the metal gong (which makes the ringing noise). Often these units were anchored to a wall or ceiling and used the ceiling or wall as a sounding board. Another implementation with some ACconnected devices was to implement a circuit to make the AC current into a noise loud enough to drive a loudspeaker and hook this circuit up to a cheap 8-ohm speaker. Nowadays, it is more popular to use a ceramic-based piezoelectric sounder which makes a high-pitched tone. Usually these were hooked up to "driver" circuits which varied the pitch of the sound or pulsed the sound on and off.
15
16
Input to 8 channels IN0 IN1 IN2 IN3 IN4 IN5 IN6 IN7
LM 35 temperature sensor
8 varaiable resistors are provided in adc section , each is connected to channel input. IN0,IN1,IN2,IN3.IN4,IN5,IN6,IN7 to give input to adc .Either input can give from out side by shifting jumpers between jp36 and jp37 from 1 to 8( left to right ).jumpers can be selected optionally according to channel selection(for example if choose channel 4 then can shift jumper 4 from left to right ) .connect input from outside to any pin number from 2 to 8 of jumper jp39 . First number pin of jp39 is reserved for LM35 which is connected to first channel input IN0.On board temperature sensor LM35 is provided as input source to adc. To get input from LM35 shift only first jumper between jp36 and jp37 from left.
17
Features:
Easy interface to all microprocessors Operates ratio metrically or with 5 VDC or analog span adjusted voltage reference No zero or full-scale adjust required 8-channel multiplexer with address logic 0V to 5V input range with single 5V power supply Outputs meet TTL voltage level specifications ADC0808 equivalent to MM74C949 ADC0809 equivalent to MM74C949-1
Key Specifications
Resolution 8 Bits Total Unadjusted Error 12 LSB and 1 LSB Single Supply 5 VDC Low Power 15 mW Conversion Time 100
RS232 SECTION
This section is on board to program the microcontroller through pc serial port either u can use usb to serial convertor to program microcontroller chip. The Serial Port is harder to interface than the Parallel Port. In most cases, any device you connect to the serial port will need the serial transmission converted back to parallel so that it can be used. This can be done using a UART. On the software side of things, there are many more registers that you have to attend to than on a Standard Parallel Port. (SPP)
So what are the advantages of using serial data transfer rather than parallel? 18
1. Serial Cables can be longer than Parallel cables. The serial port transmits a '1' as -3 to 25 volts and a '0' as +3 to +25 volts where as a parallel port transmits a '0' as 0v and a '1' as 5v. Therefore the serial port can have a maximum swing of 50V compared to the parallel port which has a maximum swing of 5 Volts. Therefore cable loss is not going to be as much of a problem for serial cables than they are for parallel. RS232 SECTION
2. You don't need as many wires than parallel transmission. If your device needs to be mounted a far distance away from the computer then 3 core cable (Null Modem Configuration) is going to be a lot cheaper that running 19 or 25 core cable. However you must take into account the cost of the interfacing at each end. 3. Infra Red devices have proven quite popular recently. You may of seen many electronic diaries and palmtop computers which have infra red capabilities build in. However could you imagine transmitting 8 bits of data at the one time across the room and being able to (from the devices point of view) decipher which bits are which? Therefore serial transmission is used where one bit is sent at a time. IrDA-1 (The first infra red specifications) was capable of 115.2k baud and was interfaced into a UART. The pulse length however was cut down to 3/16th of a RS232 bit length to conserve power considering these devices are mainly used on diaries, laptops and palmtops. 4. Microcontroller's have also proven to be quite popular recently. Many of these have in built SCI (Serial Communications Interfaces) which can be used to talk to the outside world. Serial Communication reduces the pin count of these MPU's. Only two pins are commonly used, Transmit Data (TXD) and Receive Data (RXD) compared with at least 8 pins if you use a 8 bit Parallel method (You may also require a Strobe).
19
LCD DISLAY SECTION A liquid crystal display (LCD) is a thin, flat panel used for electronically displaying information such as text, images, and moving pictures. Its uses include monitors for computers, televisions, instrument panels, and other devices ranging from aircraft cockpit displays, to every-day consumer devices such as video players, gaming devices, clocks, watches, calculators, and telephones. Among its major features are its lightweight construction, its portability, and its ability to be produced in much larger screen sizes than are practical for the construction of cathode ray tube (CRT) display technology. Its low electrical power consumption enables it to be used in battery-powered electronic equipment. It is an electronically-modulated optical device made up of any number of pixels filled with liquid crystals and arrayed in front of a light source (backlight) or reflector to produce images in color or monochrome. The earliest discoveries leading to the development of LCD technology date from 1888. By 2008, worldwide sales of televisions with LCD screens had surpassed the sale of CRT units.
20
CONNECTIONS- Connect any port of 8051(carrying data) from microcontroller with jp2(in case of 8 bit data mode )and with jp44(in case of 4 bit data mode) data port of lcd (D0-D7) and control port with jp5(0-RS and 1-E) or jp31(0-RS and 1-E) of lcd.For more details see program of lcd display. FEATURES 5 x 8 dots with cursor Built-in controller (KS 0066 or Equivalent) + 5V power supply (Also available for + 3V) 1/16 duty cycle B/L to be driven by pin 1, pin 2 or pin 15, pin 16 or A.K (LED) N.V. optional for + 3V power supply LED SECTION A light-emitting diode (LED) is an electronic light source. LEDs are based on the semiconductor diode. When the diode is forward biased (switched on), electrons are able to recombine with holes and energy is released in the form of light. This effect is called electroluminescence and the color of the light is determined by the energy gap of the semiconductor. The LED is usually small in area (less than 1 mm2) with integrated optical components to shape its radiation pattern and assist in reflection.
8 led display
CONNECTIONS- connect input (data) port from 8051 with output port port of led section
to see output.
LEDs present many advantages over traditional light sources including lower energy consumption, longer lifetime, improved robustness, smaller size and faster switching. However, they are relatively expensive and require more precise current and heat management than traditional light sources. Applications of LEDs are diverse. They are used as low-energy indicators but also for replacements for traditional light sources in general lighting and automotive lighting. The compact size of LEDs has allowed new text and video displays and sensors to be developed, while their high switching rates are useful in communications technology. SEVEN SEGMENT DISLAY SECTION A seven-segment display -less commonly known as a seven-segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot-matrix displays. Seven-segment displays are widely used in digital clocks, electronic meters, and other electronic devices for displaying numerical information. Concept and visual structure -The individual segments of a seven-segment display.A seven segment display, as its name indicates, is composed of seven elements. Individually on or off, they can be combined to produce simplified representations of the arabic numerals. Often the seven segments are arranged in an oblique, or italic, arrangement, which aids readability. Each of the numbers 0, 6, 7 and 9 may be represented by two or more different glyphs on seven-segment displays.
22
CONNECTIONS- connect data carrying port of 8051 with jp21 data port of 7 segment section and control port with jp13 of seven segment section to see output. The seven segments are arranged as a rectangle of two vertical segments on each side with one horizontal segment on the top, middle, and bottom. Additionally, the seventh segment bisects the rectangle horizontally. There are also fourteen-segment displays and sixteen-segment displays (for full alphanumerics); however, these have mostly been replaced by dot-matrix displays. The segments of a 7-segment display are referred to by the letters A to G, as shown to the right, where the optional DP decimal point (an "eighth segment") is used for the display of non-integer numbers.
RELAY SECTION
A relay is an electrical switch that opens and closes under the control of another electrical circuit. In the original form, the switch is operated by an electromagnet to open or close one or many sets of contacts. It was invented by Joseph Henry in 1835. Because a relay is able to control an output circuit of higher power than the input circuit, it can be considered to be, in a broad sense, a form of an electrical amplifier.
23
Relay
24
CONNECTIONS- connect input from microcontroller to jp27 and connect device which want to control with jp32 relay2 out connector or jp22 relay1 out connector. Connect +12v dc supply from power supply section with 2 pin connector jp30(+12v dc to relay coil). A relay coil is copper wire wound many times on and around a bobbin in which an iron core is situated. When a voltage of sufficient magnitude is impressed across the coil, the coil and core develop magnetism which attracts the armature. The armature, in turn, controls contact movement. Depending on the total length of the wire and its unit crosssectional area, the coil exhibits a certain amount of resistance to the flow of electric current. According to Ohms Law, for a given amount of resistance, current is directly proportional to voltage. That is: I = E / R where; I = current in amperes E = voltage in volts R = resistance in ohms Thus, a 12V DC coil that has 120 ohms of resistance pulls 0.1 amp of current.Some relay coils accept DC voltage, while others accept AC voltage. DC (direct current) voltage has a constant, unchanging value. At any given instant of time, a 12V DC power source measures exactly 12 volts (give or take a few tenths of a volt, normally).
to the next position. This is what makes the rotor feel like it is clicking from one position to the next as you rotate the rotor by hand with no power applied.
Stepper motor
fig 1.
Fig 1. Diagram that shows the position of the six-pole rotor and eight-pole stator of a typical stepper motor. When power is applied, it is directed to only one of the stator pairs of windings, which will cause that winding pair to become a magnet. One of the coils for the pair will become the North Pole, and the other will become the South Pole. When this occurs, the stator coil that is the North Pole will attract the closest rotor tooth that has the opposite polarity, and the stator coil that is the South Pole will attract the closest rotor tooth that has the opposite polarity. When current is flowing through these poles, the rotor will now have a much stronger attraction to the stator winding, and the increased torque is called holding torque.
26
By changing the current flow to the next stator winding, the magnetic field will be changed 45. The rotor will only move 15 before its magnetic fields will again align with the change in the stator field. The magnetic field in the stator is continually changed as the rotor moves through the 24 steps to move a total of 360. Figure 2 shows the position of the rotor changing as the current supplied to the stator changes.
FIGURE 2. Movement of the stepper motor rotor as current is pulsed to the stator. (a) Current is applied to the A and A windings, so the A winding is north, (b) Current is applied to B and B windings, so the B winding is north, (c) Current is applied to the C and C windings, so the C winding is north, (d) Current is applied to the D and D windings so the D winding is north. (e) Current is applied to the A and A windings, so the A winding is north.
27
CONNECTIONS- Stepper motor section have two connectors, jp16 & jp12 .jp12 is input connector from microcontroller and jp16 is output connector to stepper motor.
DAC0808 SECTION
In electronics, a digital-to-analog converter (DAC or D-to-A) is a device for converting a digital (usually binary) code to an analog signal (current, voltage or electric charge). A DAC converts an abstract finite-precision number (usually a fixed-point binary number) into a concrete physical quantity (e.g., a voltage or a pressure). In particular, DACs are often used to convert finite-precision time series data to a continually-varying physical signal. A typical DAC converts the abstract numbers into a concrete sequence of impulses. that are then processed by a reconstruction filter using some form of interpolation to fill in data between the impulses. Other DAC methods (e.g., methods based on Delta-sigma modulation) produce a pulse-density modulated signal that can then be filtered in a similar way to produce a smoothly-varying signal.
DAC 0808 (8 bit d/a convertor) The DAC0808 is an 8-bit monolithic digital-to-analog converter (DAC) featuring a full scale output current settling time of 150 ns while dissipating only 33 mW with 5V supplies. No reference current (IREF) trimming is required for most applications since the full scale output current is typically 1 LSB of 255 IREF/256. Relative accuracies of better than 0.19% assure 8-bit monotonicity and linearity while zero 28
level output current of less than 4 A provides 8-bit zero accuracy for IREF2 mA. The power supply currents of the DAC0808 is independent of bit codes, and exhibits essentially constant device characteristics over the entire supply voltage range. The DAC0808 will interface directly with popular TTL, DTL or CMOS logic levels, and is a direct replacement for the MC1508/MC1408. For higher speed applications, see DAC0800 data sheet. Features Relative accuracy: 0.19% error maximum Full scale current match: 1 LSB type Fast settling time: 150 ns typ Noninverting digital inputs are TTL and CMOS ompatible High speed multiplying input slew rate: 8 mA/s Power supply voltage range: 4.5V to 18V Low power consumption: 33 mW @ 5V
the 24- hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in powersense circuit that detects power failures and automatically switches to the battery supply.
Real-time clock (RTC) counts seconds, minutes, hours, date of the month, month, day of the week, and year with leap-year compensation valid up to 2100 56-byte, battery-backed, nonvolatile (NV) RAM for data storage Two-wire serial interface Programmable square wave output signal Automatic power-fail detect and switch circuitry Consumes less than 500nA in battery backup mode with oscillator running Optional industrial temperature range: -40C to +85C Available in 8-pin DIP or SOIC Underwriters Laboratory (UL) recognized
E2PROM 24C04 FEATURES Low-voltage and Standard-voltage Operation 2.7 (VCC = 2.7V to 5.5V) 1.8 (VCC = 1.8V to 5.5V) Internally Organized 128 x 8 (1K), 256 x 8 (2K), 512 x 8 (4K), 1024 x 8 (8K) or 2048 x 8 (16K) 2-wire Serial Interface Schmitt Trigger, Filtered Inputs for Noise Suppression Bi-directional Data Transfer Protocol 100 kHz (1.8V) and 400 kHz (2.5V, 2.7V, 5V) Compatibility Write Protect Pin for Hardware Data Protection 8-byte Page (1K, 2K), 16-byte Page (4K, 8K, 16K) Write Modes Partial Page Writes are Allowed Self-timed Write Cycle (5 ms max) High-reliability Endurance: 1 Million Write Cycles Data Retention: 100 Years Automotive Grade, Extended Temperature and Lead-Free Devices Available
30
RTC DS1307
31
A DIP switch is a set of manual electric switches that are packaged in a group in a standard dual in-line package (DIP) (the whole package unit may also be referred to as a DIP switch in the singular). This type of switch is designed to be used on a printed circuit board along with other electronic components and is commonly used to customize the behavior of an electronic device for specificsituations.
DIP switches are an alternative to jumper blocks. Their main advantages are that they are quicker to change and there are no parts to lose. DIP switch types There are many different kinds of DIP switches. Some of the most common are the rotary, slide, and rocker types. Rotary DIP switches contain multiple contacts, one of which is selected by rotating the switch to align it with a number printed on the package. The slide and rocker types, which are very common, are arrays of simple SPDT (singlepole, single-throw) contacts, which can be either on or off. This allows each switch to select a one-bit binary value. The values of all switches in the DIP package can also be interpreted as one number. For example, seven switches offer 128 combinations, allowing them to select a standard ASCII character. Eight switches offer 256 combinations, which is equivalent to one byte. The DIP switch package also has socket pins or mounting leads to provide an electrical path from the switch contacts to the circuit board. Although circuits can use the electrical contacts directly, it is more common to convert them into high and low signals. In this case the circuit board also needs interface circuitry for the DIP switch, consisting of a series of pull-up or pull-down resistors, a buffer, decode logic, and other components. Typically the device's firmware reads the DIP switches. They were also often used on arcade games in the 1980s and early 1990s to store settings, before the advent of cheaper, battery-backed RAM and were very commonly used to set security codes on garage door openers as well as on some early cordless phones. This design, which used up to twelve switches in a group, was used to avoid interference from other nearby door opener remotes or other devices. Current garage door openers use rolling code systems for better security.
32
These type of switches were used on early video cards for early computers to facilitate compatibility with other video standards. For example, CGA cards allowed for MDA compatibility. Recently (since the late 1990s), DIP switches have become less common in consumer electronics. Reasons include the trend toward smaller products, the demand for easier configuration through setting screens, and the falling price of non-volatile memory. But DIP switches are still widely used in industrial equipment because they are inexpensive and easy to incorporate into circuit designs, and because they allow settings to be checked at a glance without powering the system on.
Fig. 1 A 4x4 keypad can be very easily interfaced to the 8051 PORTS (Figure 1). Eight lines (0 - 7) are ssigned to matrix keypad. Four lines (0 - 3) are used to select the columns C1, C2, C3 & C4. The four lines (4 - 7) of same port are used to select rows R1,R2,R3 & R4. CONNECTIONS- Make connections for lcd display by connecting data and control port of 8051 and connect keypad connector jp40 with 8051 port(selected for keypad interface).for more details how to use see program of matrix keypad.
33
34
35
36
37
38
9. Write or copy your code there & save it with extension .c or .asm depending on your coding.
10.Go to target & then source group, right click on there & click on the option add files to the project.
39
40
12.Go to the option for target, click on output &tick on create hex file option
42
After performing all these steps the chip will be configured through Flash Magic .Let us hand on the steps of chip configuration through Flash Magic
Special Notes:
Make all the DIP switches in off position before burning the program in the controller. Connect the Programming Cable on your Kit (prog. Conn.)And other side of cable with the COM Port of the Computer.
Burn the Program in the microcontroller with help of FLASH MAGIC or ECE FLASH as explained in the next section.
43
Now set the parameters as shown below Click on communication options and set parameters as show in fig below.
45
Click on hardware config and set parameters T1(200)and T2(300). Now disable option use DTR and RST shown in fig below.
46
Click on timeouts option and set parameters regular timeout 30, long timeout 120 and diasable option use my timeouts for ISP operations as shown in fig below.
47
now click ok main front window will appear. Now select device name 89V51RD2XXX as shown in fig below.
48
After selection of the chip (P89v51RD2xx) , Port (Com1), Osc.Mhz(11.0592) we can see the window as below:
49
Browse for the hex file to be loaded. Press start reset window will appear as shown in fig below.
50
Press reset button on hardware or ON/OFF power for a while to reset to make hardware in programming mode. Within 5-6 seconds message will appear ************FINISHED.*********** Now press again reset on hardware to see output or to run program.
51
To burn chip 89V51RDRXX through ECE flash it required less . Double click on icon as shown below.
Set baud rate 9600 ,select working comport of PC to hardware and software communication as shown below.
52
Now select hex file to burn in chip through browse option as shown below.
Now press reset switch on hardware board and flash will burn with 5-6 Seconds. Again press reset switch on hardware board to run your program or to see output.
54
55
EXPERIMENT NO: 1
AIM: Program of right shift of LEDS
CONNECTIONS:
56
74LS244
1. load programme using Flash Magic 2 .Out of P0 connected to 10 pin box header 3.Led rotating in Right side. 4.We can changed the direction according to the program.
57
EXPERIMENT NO: 2
AIM: Program to display counter of 0 to 9999 on Seven Segment Display CONNECTIONS:
Connect Port2 (P2) to CONTROL(JP4) OF 7-Segment Section. Connect Port0 (P0) to DATA (JP21)OF 7-Segment Section.
#include<reg51.h> char arr[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xe7}; void delay(void); void main(void) { int a,b,c,d,e; for(a=0;a<10;a++) { for(b=0;b<10;b++) { for(c=0;c<10;c++) { for(d=0;d<10;d++) { for(e=0;e<300;e++) { P2=0x08; P0=arr[a]; delay(); P2=0x04; P0=arr[b]; delay(); P2=0x02; P0=arr[c]; delay(); P2=0x01; P0=arr[d]; delay(); }} } } } } void delay(void) { int f; for(f=0;f<20;f++); } 58
Controlled Pins
Data Pins
ULN2003
59
EXPERIMENT NO: 3
AIM: Program of LCD
CONNECTIONS:
Connect Port2 (P2) to JP2 OF LCD Section. Connect Port0 (P0) to JP5 OF LCD Section.
/////PORT0-----LCD CONTRL /////PORT2-----LCD DATA
#include<reg51.h> sbit RS=P0^0; sbit E=P0^1; void cmddiply() { RS=0; E=1; E=0; } void datadiply() { RS=1; E=1; E=0; } void delay() { int i; for(i=0;i<30000;i++); } void main() { while(1) { P2=0x38; cmddiply(); delay(); P2=0x0E; cmddiply(); 60
delay(); P2=0x06; cmddiply(); delay(); P2=0x01; cmddiply(); delay(); P2=0x80; cmddiply(); delay(); P2='A'; datadiply(); delay(); P2='D'; datadiply(); delay(); P2='V'; datadiply(); delay(); P2='A'; datadiply(); delay(); P2='N'; datadiply(); delay(); P2='C'; datadiply(); delay(); P2='E'; datadiply(); delay(); P2=0xC0; cmddiply(); delay(); P2='T'; datadiply(); delay(); P2='E'; datadiply(); delay(); P2='C'; datadiply(); delay(); P2='H'; datadiply(); 61
delay(); P2='8'; datadiply(); delay(); P2='5'; datadiply(); delay(); P2='1'; datadiply(); delay(); } }
LCD display
62
EXPERIMENT NO: 4
AIM: Program for Dip Test
CONNECTIONS:
Connect Port2 (P2) to LED Section. Connect Port0 (P0) to DIP switch Section.
#include<reg51.h> #include<intrins.h> typedef unsigned char uchar; typedef unsigned long ulong; typedef unsigned int uint; #define TIMER_RELOAD (-921) #define port_delay() _nop_(), _nop_(), _nop_(), _nop_() uint count; ulong value; uchar state,rdata; void timer0(void) interrupt 1 using 1 { count++; TH0 = (uchar)(TIMER_RELOAD>>8); TL0 = (uchar)TIMER_RELOAD; } /* void delay(uint n) { n = count + n; while (n != count); } */ void io_open(void) { TMOD = 0x21; IE = 0x92; //1001 0010 SCON = 0x50; //0101 0000 REN = 1; TL0 = (uchar)TIMER_RELOAD; TH0 = (uchar)TIMER_RELOAD >> 8; TH1 = TL1 = 0xFA; TR0 = 1; 63
DIP SWITCH
ON
OFF
64
EXPERIMENT NO: 5
Aim: Program to Control the Operation of Relay and Buzzer
CONNECTIONS:
65
EXPERIMENT NO:6
AIM: Program to enter name and roll number using four keys on LCD
CONNECTIONS:
Connect Port1 (P1) to KEYPAD Section. Connect Port2 (P2) to JP5 OF LCD Section. Connect Port0 (P0) to JP2 OF LCD Section.
#include<reg51.h> sbit sw1=P1^0; sbit sw2=P1^1; sbit sw3=P1^2; sbit sw4=P1^3;
sbit RS=P2^0; //RS for register select sbit EN=P2^1; //en for enable void delay() { int i; for(i=0;i<700;i++); } //function to write command to character generate register. void comwrt(char ch) { RS=0; P0=ch;//to select command register EN=1; EN=0; } void intialise() { comwrt(0x38); //2 lines and 5*7 matrix delay(); comwrt(0x0c); //display on ,cursor not blinking delay(); comwrt(0x01); //clear display delay(); comwrt(0x06); // to set entry mode delay(); 66
comwrt(0x80); delay(); }
//function to write the data into data display register. void datawrt(char ch) { RS=1; //to select data display register P0=ch; EN=1; //for high to low pulse EN=0; } //function to display a string on LCD void strwrt(char *ptr) { int i; for(;*ptr!='\0';ptr++) { datawrt(*ptr); delay(); for(i=0;i<25;i++) delay(); } } void main() { char i=0,l=0; // i for alphabet number and l for location on LCD intialise(); strwrt(" sw1 for menu"); delay(); sw1=0; while(sw1==0); if(sw1==1) { while(sw1==1); // while switch 1 is not released comwrt(0x01); // to clear display delay(); comwrt(0x80); //to force the cursor to starting of first line delay(); strwrt(" sw1 for name "); comwrt(0xC0); //to force the cursor to starting of second line delay(); strwrt(" sw2 for rollno: "); while(1) { 67
if(sw1==1) { while(sw1==1); comwrt(0x01); //to clear display delay(); comwrt(0x80); //to force the cursor to starting of first line delay(); strwrt(" -----------------"); delay(); comwrt(0xc0); strwrt(" enter name "); sw1=0; comwrt(0x81); comwrt(0x0f); while(1) { if(sw1==1) { while(sw1==1); comwrt(0x81+l); delay(); datawrt((char)'A'+i); delay(); i++; if(i==26) i=0; sw1=0; }else if(sw2==1) { while(sw2==1); l++; if(l==14) l=0; i=0; } else if(sw3==1) { while(sw3==1); l--; i=0; } else if(sw4==1) { comwrt(0x01); 68
comwrt(0x80); strwrt(" saved "); } } break; } else if(sw2==1)//rollno { while(sw2==1) ; comwrt(0x01); comwrt(0x80); strwrt(" ---------------"); sw1=0; delay(); comwrt(0xc0); strwrt(" enter roll no "); comwrt(0x81); comwrt(0x06); comwrt(0x0f); while(1) { if(sw1==1) { while(sw1==1); comwrt(0x81+l); delay(); datawrt((char)'0'+i); delay(); i++; if(i==26) i=0; sw1=0; }else if(sw2==1) { while(sw2==1); if(l<15) l++; i=0; } else if(sw3==1) { while(sw3==1); if(l>0) l--; 69
i=0; } else if(sw4==1) { comwrt(0x01); comwrt(0x80); strwrt(" saved "); break; } } break; } } delay(); } while(1); }
70
EXPERIMENT NO: 7
AIM: PROGRAM OF ANALOG TO DIGITAL CONVERTER
CONNECTIONS:
Connect Port3 (P3) to ADC Section. Connect Port2 (P2) to JP2 OF LCD Section. Connect Port0 (P0) to JP5 OF LCD Section. Connect Port1 (P1) to 8-bit digital data OF ADC Section.
#include<reg52.h> #include<intrins.h> typedef unsigned char uchar; typedef unsigned long ulong; typedef unsigned int uint; #define #define sbit LRS sbit LEN sbit OE sbit SOC sbit ALE1 sbit EOC sbit ADC_CLK sbit SEL0 sbit SEL1 sbit SEL2 uint count,value; uchar adc_val,state; void timer0(void) interrupt 1 using 1 { count++; TH0 = (uchar)(TIMER_RELOAD>>8); TL0 = (uchar)TIMER_RELOAD; ADC_CLK = ~ADC_CLK; 71 TIMER_RELOAD (-921) port_delay() _nop_(), _nop_(), _nop_(), _nop_() = = = = = = = = = = P0 ^ 0; P0 ^ 1; P1 ^ 7; P1 ^ 6; P1 ^ 5; P1 ^ 4; P1 ^ 3; P1 ^ 2; P1 ^ 1; P1 ^ 0;
} void delay(uint n) { n = count + n; while (n != count); } void dispstr(uchar *str, uchar stcol, uchar encol) { uint q; if(stcol <= 15) P2 = 0x80 + stcol; else P2 = 0xB0 + stcol; LRS = 0; LEN = 1; LEN = 0; delay(1); LRS = 1; q=0; for(; stcol <= encol; stcol++) { if(stcol == 16) { P2 = 0xB0 + stcol; LRS = 0; LEN = 1; LEN = 0; delay(1); LRS = 1; } P2 = str[q]; q++; LEN = 1; LEN = 0; delay(1); } }
LEN = 0; delay(6); }
void io_open(void) { LEN = 0; TMOD = 0x21; IE = 0x92; //1001 0010 TL0 = (uchar)TIMER_RELOAD; TH0 = (uchar)TIMER_RELOAD >> 8; TR0 = 1; } void initlcd(void) { LEN = 0; LRS = 0; delay(20); P2 = 0x30; LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x30; LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x30; LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x38; //funtion set LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x0c8; //display off 73
LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x01; //clear display; LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x06; //entry mode set LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x0c; //display on LEN = 1; delay(1); LEN = 0; delay(6); } void dispnum(uint no, uchar stcol, uchar encol) { uchar temp[5]; uchar i,k; for (i = 0; i < 5; i++) { temp[i] = no % 10; no /= 10; } if(stcol <= 15) P2 = 0x80 + stcol; else P2 = 0xB0 + stcol; LRS = 0; LEN = 1; LEN = 0; delay(1); LRS = 1; i = k = 4; for(; stcol <= encol; stcol++) { 74
if( k == 1) { k = 200; dispstr(".",stcol,stcol); } else { P2 = temp[i] + 0x30; i--; k--; LEN = 1; LEN = 0; delay(1); } } }
void read_adc(void) { ALE1 = 1; OE = 0; SOC = 1; ALE1 = 0; SOC = 0; delay(100); while(!EOC); OE = 1; adc_val = P3; } void main(void) { io_open(); initlcd(); clrlcd (); dispstr(" ADVANCE delay(2000); state = 0; while(1) { switch(state) { case 0:
",0,15);
/255;
dispstr("CHANNEL2 ",0,15); SEL0 = 0; SEL1 = 0; SEL2 = 1; read_adc(); value = (adc_val * 400) /255; dispnum(value,16,21); delay(3000); state = 2; break; case 2: dispstr("CHANNEL3 ",0,15); SEL0 = 0; SEL1 = 1; SEL2 = 0; read_adc(); value = (adc_val * 400) /255; dispnum(value,16,21); delay(3000); state = 3; break; case 3: dispstr("CHANNEL4 ",0,15); SEL0 = 0; SEL1 = 1; SEL2 = 1; read_adc(); value = (adc_val * 400) /255; dispnum(value,16,21); delay(3000); state = 0; break; } } }
76
PRESET
EXTERNAL INPUT
INTERNA L INPUT
1. Load programme using Flash Magic 2 Connect Port3 (P3) to ADC CONTROLE SECTION
3 Connect Port2 (P2) to JP2 OF LCD Section. 4 Connect Port0 (P0) to JP5 OF LCD Section. 5 Connect Port1 (P1) to 8-bit digital data OF ADC Section. 6 Out put display ON LCD
77
EXPERIMENT NO: 8
AIM: PROGRAM OF REAL TIME CONTROL
CONNECTIONS:
Connect Port1 (P1) to RTC Section. Connect Port2 (P2) to JP2 OF LCD Section. Connect Port0 (P0) to JP5 OF LCD Section.
#include<reg51.h> #include<intrins.h> typedef unsigned char uchar; typedef unsigned long ulong; typedef unsigned int uint; #define #define #define sbit LRS sbit LEN sbit ICLK sbit IDAT TIMER_RELOAD (-921) port_delay() _nop_(), _nop_(), _nop_(), _nop_() AVG 10 = P0 ^ 0; = P0 ^ 1; = P1 ^ 3; = P1 ^ 1;
void timer0(void) interrupt 1 using 1 { count++; TH0 = (uchar)(TIMER_RELOAD>>8); TL0 = (uchar)TIMER_RELOAD; } void delay(uint n) { n = count + n; while (n != count); } 78
void dispstr(uchar *str, uchar stcol, uchar encol) { uint q; if(stcol <= 15) P2 = 0x80 + stcol; else P2 = 0xB0 + stcol; LRS = 0; LEN = 1; LEN = 0; delay(1); LRS = 1; q=0; for(; stcol <= encol; stcol++) { if(stcol == 16) { P2 = 0xB0 + stcol; LRS = 0; LEN = 1; LEN = 0; delay(1); LRS = 1; } P2 = str[q]; q++; LEN = 1; LEN = 0; delay(1); } }
void dispnum(uint no, uchar stcol, uchar encol) { uchar temp[5]; uchar i; for (i = 0; i < 2; i++) { temp[i] = no % 10; no /= 10; } if(stcol <= 15) P2 = 0x80 + stcol; else 79
P2 = 0xB0 + stcol; LRS = 0; LEN = 1; LEN = 0; delay(1); LRS = 1; i = 1; for(; stcol <= encol; stcol++) { P2 = temp[i] + 0x30; i--; LEN = 1; LEN = 0; delay(1); } } void clrlcd() { LRS = 0; P2 = 0x01; LEN = 1; LEN = 0; delay(6); } void str1307(void) { IDAT = 1 ; _nop_() , _nop_() , _nop_() ; ICLK = 1 ; _nop_() , _nop_() , _nop_() ; IDAT = 0 ; _nop_() , _nop_() , _nop_() ; ICLK = 0 ; _nop_() , _nop_() , _nop_() ; } void stp1307(void) { IDAT = 0 ; _nop_() , _nop_() , _nop_() ; ICLK = 1 ; _nop_() , _nop_() , _nop_() ; IDAT = 1 ; _nop_() , _nop_() , _nop_() ; 80
ICLK = 0 ; _nop_() , _nop_() , _nop_() ; } void clock(void) { _nop_() ; _nop_() ; _nop_() ; ICLK = 1 ; _nop_() ; _nop_() ; _nop_() ; ICLK = 0 ; _nop_() ; _nop_() ; _nop_() ; } void ack1307(void) { IDAT = 0 ; clock() ; } void nack1307(void) { IDAT = 1 ; clock() ; } void opdat(char rtcdata) { char i ; for ( i = 0 ; i < 8 ; i++ ) { if ( ( rtcdata >> ( 7 - i ) ) & 0x01 ) IDAT = 1 ; else IDAT = 0 ; clock() ; } } void waitack(void) { // watch() ; IDAT = 1 ; _nop_() , _nop_() , _nop_() ; while ( IDAT ) ; ICLK = 1 ; _nop_() , _nop_() , _nop_() ; ICLK = 0 ; 81
} char getdat(void) { char i , dat ; // watch() ; IDAT = 1 ; _nop_() , _nop_() , _nop_() ; for ( i = 0 ; i < 8 ; i++ ) { ICLK = 1 ; dat = ( ( ( dat << 1 ) & 0xfe ) | IDAT ) ; _nop_() , _nop_() , _nop_() ; ICLK = 0 ; _nop_() , _nop_() , _nop_() ; } return dat ; } /* void gortc(void) { str1307() ; opdat(0xd0) ; waitack() ; opdat(0x07); waitack(); opdat(0x90); waitack(); stp1307(); } */ void getrtc(void) { char rdata ; // watch() ; str1307() ; opdat(0xd0) ; waitack() ; opdat(0x00) ; waitack() ; stp1307() ; _nop_() , _nop_() , _nop_() ; str1307() ; opdat(0xd1) ; 82
waitack() ; rdata = getdat() ; ack1307() ; second = ( rdata & 0x7f) ; rdata = getdat() ; ack1307() ; minute = ( rdata & 0x7f) ; rdata = getdat() ; ack1307() ; hour = ( rdata & 0x3f) ; rdata = getdat() ; ack1307() ; // watch() ; day = ( rdata & 0x07) ; rdata = getdat() ; ack1307() ; date = ( rdata & 0x3f) ; rdata = getdat() ; ack1307() ; month = ( rdata & 0x1f) ; rdata = getdat() ; nack1307() ; year = rdata ; stp1307() ; } void setrtc(void) { char rdata ; // watch() ; str1307() ; opdat(0xd0) ; waitack() ; opdat(0x00) ; waitack() ; rdata = ( second & 0x7f) ; opdat(rdata) ; waitack() ; rdata = ( minute & 0x7f) ; opdat(rdata) ; waitack() ; rdata = ( hour & 0x3f) ; opdat(rdata) ; waitack() ; rdata = ( day & 0x07) ; opdat(rdata); 83
waitack(); rdata = ( date & 0x3f); opdat(rdata) ; waitack() ; rdata = ( month & 0x1f); opdat(rdata); waitack() ; rdata = year ; opdat(rdata) ; waitack() ; stp1307() ; } unsigned char bcdtime(unsigned char x) { return ( ( ( x / 10 ) << 4 ) + ( x % 10 ) ) ; } unsigned char binarytime(unsigned char x) { return ( ( ( x >> 4 ) * 10 ) + ( x & 0xf ) ) ; } void getrtc1(void) { getrtc() ; // watch() ; year = binarytime( year ); month = binarytime( month ); date = binarytime( date ); hour = binarytime( hour ); minute = binarytime( minute ); second = binarytime( second ); } void setrtc1(void) { // watch() ; year = bcdtime( year ) ; month = bcdtime( month ) ; date = bcdtime( date ) ; hour = bcdtime( hour ) ; minute = bcdtime( minute ) ; second = bcdtime( second ) ; setrtc() ; } 84
/* void initrtc1(void) { // gortc(); // getrtc(); setrtc1(); // watch(); /* year = binarytime( year ); month = binarytime( month ); date = binarytime( date ); hour = binarytime( hour ); minute = binarytime( minute ); second = binarytime( second ); getrtc1(); setrtc1(); } */ void io_open(void) { LEN = 0; TMOD = 0x21; IE = 0x92; //1001 0010 SCON = 0x50; //0101 0000 REN = 1; TL0 = (uchar)TIMER_RELOAD; TH0 = (uchar)TIMER_RELOAD >> 8; TH1 = TL1 = 0xFA; TR0 = 1; TR1 = 1; } void initlcd(void) { LEN = 0; LRS = 0; delay(20); P2 = 0x30; LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x30; 85
LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x30; LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x38; //funtion set LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x0c8; LEN = 1; delay(1); LEN = 0; delay(6); //display off
P2 = 0x01; //clear display; LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x06; //entry mode set LEN = 1; delay(1); LEN = 0; delay(6); P2 = 0x0c; //display on LEN = 1; delay(1); LEN = 0; delay(6); } void main(void) { 86
io_open(); initlcd(); clrlcd (); dispstr(" ADVANCE delay(2000); minute = 52; hour = 3; second = 1; date = 18; month = 5; year = 4;
",0,15);
//
87
EXPERIMENT NO: 9
AIM: PROGRAM TO CONTROL THE OPERATION OF STEPPER MOTOR
CONNECTIONS:
} void positive_step(void) { P2 = 0x11; delay(100); P2 = 0x22; delay(100); P2 = 0x44; delay(100); P2 = 0x88; delay(100); } void negative_step(void) { P2 = 0x41; delay(40); P2 = 0x82; delay(40); P2 = 0x28; delay(40); P2 = 0x14; delay(40); } void left_90(void) { P2 = 0x44; delay(40); P2 = 0x88; delay(40); P2 = 0x22; delay(40); P2 = 0x11; delay(40); } void right_90(void) { P2 = 0x88; delay(40); P2 = 0x44; delay(40); P2 = 0x22; delay(40); P2 = 0x11; delay(40); } 89
void forward(uchar step) { uchar i; for(i = 0;i < step;i++) { positive_step(); } } void back(uchar step) { uchar i; for(i = 0;i < step;i++) { negative_step(); } } void left(uchar step) { uchar i; for(i = 0;i < step;i++) { left_90(); } } void right(uchar step) { uchar i; for(i = 0;i < step;i++) { right_90(); } } void main(void) { io_open(); while(1) { forward(25); //right(20); //forward(25); //left(20); 90
} /*forward(28); while(1);*/ }
ULN2003
91
EXPERIMENT NO.10
AIM: PROGRAM TO CONTROL THE OPERATION OF TRAFFICE LIGHT CONNECTION: P2 and P0 connected to traffic light module
org 00h traffic:;mov p2,#00h ; mov p0,#00h ;acall delay traffic_again: mov p2,#0dbh mov p0,#0aeh acall delay mov p2,#0ddh mov p0,#0eeh acall delay1 mov p2,#09eh mov p0,#0ebh acall delay mov p2,#0deh mov p0,#0edh acall delay1 mov p2,#076h mov p0,#0eeh acall delay mov p2,#0eeh mov p0,#0eeh acall delay1 mov p2,#0deh mov p0,#05eh acall delay mov p2,#0deh mov p0,#0f6h acall delay1 jmp traffic_again
92
delay1: mov r3,#0ffh loop4: mov r4,#0ffh loop3: mov r5,#08h loop5: djnz r5,loop5 djnz r4,loop3 djnz r3,loop4 ret delay: mov r3,#0ffh loop1: mov r4,#0ffh loop2: mov r5,#01fh loop: djnz r5,loop djnz r4,loop2 djnz r3,loop1 ret end
93