An AT89S52 Microcontroller-Based Single Board Computer for Teaching an Instrumentation System Course KHAIRURRIJAL, MUHAMMAD M. MUNIR, ASEP SUHENDI, HENDRAYANA THAHA, MAMAN BUDIMAN Department of Physics, Institut Teknologi Bandung, Jalan Ganesa 10, Bandung 40132, Indonesia
Received 25 July 2005; accepted 2 August 2006
ABSTRACT: A single board computer (SBC) based on the AT89S52 (a member of MCS-51 family) microcontroller with an ADC, serial and parallel communications, and input/output devices such as a pushbutton, a keypad, LEDs, 7-segment displays, and an LCD was developed for teaching an instrumentation system course to the sophomore students. Five microcontroller-related laboratory experiments offered to the students within the 15-week semester are (i) basic programming of the microcontroller, (ii) interfacing the DIP switches, LEDs, and 7-segment displays, (iii) application of the analog multiplexer and the ADC with the LCD, (iv) serial communication and application of the HyperTerminal, and (v) measurement of water temperature, displaying the measurement result, and application of the LabView. ß 2007 Wiley Periodicals, Inc. Comput Appl Eng Educ 15: 166 173, 2007; Published online in Wiley InterScience (www.interscience.wiley.com); DOI 10.1002/cae.20107
Keywords: single board computer (SBC); AT89S52; MCS-51 microcontroller; instrumentation system; HyperTerminal; LabView
Correspondence to Khairurrijal (
[email protected]). ß 2007 Wiley Periodicals Inc.
166
AN AT89S52 MICROCONTROLLER-BASED SBC
INTRODUCTION Microcontroller courses have traditionally been taught within electrical engineering departments [1]. Mechanical engineering departments have also recognized the important role of the microcontroller in mechatronic systems [2]. Few departments that are neither electrical nor mechanical engineering which offer microcontroller courses in their curricula. The Department of Biological and Agricultural Engineering at the University of Georgia, USA, has introductory and advanced microcontroller courses since biological and agricultural engineers face processes becoming increasingly complex with microcontrollers embedded in them [3]. An experiment using a microcontroller has been tried in the teaching of process control to chemical engineering students at the University of Minnesota Duluth, USA [4] and to students in the Department of Applied Physics, Electronics, and Systems at the University of La Laguna, Spain [5]. Many physical quantities such as temperature, pressure, length, mass, time, current, and intensity must be measured. Most modern instruments used in measuring the quantities include microcontrollers. Therefore, the development of expertise in microcontrollers is also important to physicists. In this article, we describe an AT89S52 microcontroller-based single board computer (SBC) that is used for teaching the instrumentation system course to sophomore students in the Department of Physics at
167
the Institut Teknologi Bandung (ITB), Indonesia. Some laboratory works supporting the course are explained.
DESCRIPTION OF THE SINGLE BOARD COMPUTER AND ASSOCIATED SOFTWARE PACKAGES For introductory microcontroller courses, 8-bit microcontrollers are widely utilized because they are simpler to describe, easier to use and lower cost than 16-bit or 32-bit microcontrollers. Among of the 8-bit microcontrollers, the MCS-51 family microcontrollers were chosen due to its wide-spread popularity especially as an industry standard, its simple architecture, and the likelihood that they will remain important for years to come [6]. In teaching the instrumentation system course to the sophomore students, we need a SBC that integrates the MCS-51 microcontroller with light emitting diodes (LEDs), 7-segment displays, a liquid crystal display (LCD), a pushbutton, a keypad, and an analog to digital converter (ADC) so that students who take the course can do laboratory works in a more comfortable way. In addition, the SBC has the ability to perform serial and parallel communications. Unfortunately, such SBC is not available in the market. We therefore decided to design and develop the SBC as shown in Figures 1 and 2 with the features are as follows:
Figure 1 (a) Front view of the AT89S52 microcontroller-based single board computer (SBC) with a 220 V AC power supply and cables in the brief case and (b) enlargement of the SBC. [Color figure can be viewed in the online issue, which is available at www.interscience.wiley. com.]
168
KHAIRURRIJAL ET AL.
(d)
(e)
Figure 2 Block diagram of the AT89S52 microcontrollerbased SBC.
(f) (g)
(a) An AT89S52 8-bit microcontroller (1) with 8 kb of ISP (in-system programmable) flash memory (ATMEL AT89S52 at http://www.atmel.com/). The microcontroller is compatible with the industry-standard 80C51 instruction set and pinout. The on-chip flash memory allows the program memory to be reprogrammed in-system/by a personal computer (PC). In addition, the microcontroller provides 256 bytes of random access memory (RAM), 32 programmable input/ output (I/O) lines, three 16-bit timer/counters, eight interrupt sources, a full duplex serial port, and a watchdog timer. (b) Various input and output devices such as: an 8-pin dual in-line package (DIP) switches (2), a push button (3), a 4 3 hexadecimal keypad (4), eight LEDs (5), four 7-segment displays (6), and an HD44780 compatible 2 16 alphanumeric LCD (7). The status of the input devices (the DIP switches, push button, and keypad) are read and then sent to the microcontroller through the input ports while data from the microcontroller are sent to the output devices (LEDs and displays) through the output ports. (c) A 0804 8-bit microcontroller compatible analog to digital converter (ADC) (8) (National Semiconductor at http://www.national.com/).
The conversion type of this ADC is the successive approximation register (SAR) with the conversion time of 100 ms. The ADC appears like memory locations or I/O ports to the microcontroller and therefore no interfacing logic is needed. Analog input of the ADC, which is in the range of 0 5 V with single 5 V supply, can be either two potentiometers (9) or from external connected to the connectors (10) in the board. Input selection is done by the CD4051 8-channel analog multiplexer (11). The potentiometers simulate analog voltage levels to be fed into the multiplexer. A serial communication port that is provided by the DB9 connector (12). Using the MAX232 (Dallas Semiconductor MAXIM at http://www.maxim-ic.com/), the SBC can communicate serially with another SBC or a PC. A DB25 parallel communication port (13) for downloading/uploading a program onto the microcontroller/PC. A power supply input (14). A dc unregulated voltage in the range of 7 12 V can be used. A button for resetting the microcontroller (15).
There are two steps that have to be performed to program the AT89S52 microcontroller. First, a program is created by development software packages on the PC. The development software package should include an editor and compiler. Many software packages are available for that purposes and some of them are Read51 (Rigel Corp., Gainesville, FL; http://www. rigelcorp.com/) and Proview 32 (Franklin Software, Inc., Campbell, CA; http://www.fsinc.com/). After having edited and compiled the program, a hex file is obtained. Second, the hex file is downloaded into the microcontroller of the SBC by using, for instance, the AEC_ISP (AEC Electronics Ltd, Christchurch, New Zealand; http://www.aecelectronics. co.nz/) or M. Asim Khan’s ISP software (http://chaokhun.kmitl.ac.th/kswichit/Pgm89v31_ web/Pgm89v31.html). In doing a serial communication between the PC and the SBC, the HyperTerminal application (Microsoft Corp., Redmond, WA; http://www.microsoft. com/) under the Microsoft Windows, which is ready after having installed the Windows, is a good choice because it is easy to use. The SBC is also compatible with the LabView under the Microsoft Windows, a commercial graphbased software from the National Instruments (Austin, TX; http://www.ni.com/labview/) that is widely used in industry and instrumentation education. With the
AN AT89S52 MICROCONTROLLER-BASED SBC
assistance of this software, various applications using the SBC become easier and more attractive.
SOME APPLICATIONS OF THE SBC FOR LABORATORY EXPERIMENTS Measurement is an essential part of the scientific processes and the technology of measurement is instrumentation. Figure 3 depicts a signal flow in the general block diagram of a microcontroller-based instrument. A sensor is a passive (in some cases an active) electronic device that converts a physical parameter or variable into an analog electrical signal. Since the analog electrical signal is sometimes not in the input range of the ADC, the conditioning circuits are needed to adapt the signal. The conditioned signal is then converted into a digital signal by the ADC to be processed by the microcontroller. The processed digital signal is finally presented by the digital display. In the Department of Physics at the ITB, the instrumentation system course is a three-credit course
169
that meets a 2-h lecture and a 3-h laboratory per week of the 15-week semester. The first 3 weeks are to cover basic operational amplifiers and basic digital devices. The next 7 weeks are devoted to the concept and integration of sensors, signal amplification, signal processing, data switching, data control, and data readout. The final 5 weeks are reserved for introducing microcontrollers and its role in the instrumentation system. Typical course contents are the following: *
*
*
*
*
*
Basic operational amplifiers: characteristics, basic amplifiers, current to voltage converter, bridge amplifier, and instrumentation amplifier. Basic digital devices: gates, flip-flops, and counters. Sensors: temperature, pressure, force, humidity, displacement, and electro-optics. Signal amplification and processing: filters, oscillators, modulation-demodulation, digital to analog and analog to digital conversion, and noise and noise reduction. Data switching, control, and readout: pulse timers and counters, multiplexing and demultiplexing, data communication, and display. Microcontrollers: architecture, instruction set, programming, input-output ports, interrupts, timers, interfaces with peripheral devices, and roles in instruments.
Based on the course contents and the SBC features, many possible experiments are provided by the SBC, in which some of them are listed below: (i) Programming the microcontroller. (ii) Interfacing the DIP switches, LEDs, 7segment displays, and LCD. (iii) Interfacing the keypad, LEDs, 7-segment displays, and LCD. (iv) Application of the analog multiplexer and ADC with the 7-segment displays or LCD. (v) Application of the serial communication. (vi) An instrumentation system including physical variable (for instance: temperature, pressure, or humidity) measurement, analog to digital conversion, and displaying the measurement results.
Figure 3 Signal flow in the block diagram of a microcontroller-based instrument.
For the 3-h laboratory per week of the 15-week semester, the course offers five microcontrollerrelated laboratory experiments: (a) basic programming of the microcontroller, (b) interfacing the DIP switches, LEDs, and 7-segment displays, (c) application of the analog multiplexer and the ADC with the LCD, (d) serial communication, and (e) measurement
170
KHAIRURRIJAL ET AL.
port (Fig. 4a). Next, the development software packages to edit and compile a program as well as to download the program into the SBC (Fig. 4b) are installed into the PC. Since a microcontroller is a microprocessor (central processing unit) with external units like a RAM, a read-only memory (ROM) and other support units and it functions to control input/output devices as illustrated in Figure 5, created programs in this experiment cover: (i) addressing modes: register, direct, indirect, immediate, relative, absolute, and long indexed, (ii) functional modes: arithmetic, logics, boolean, data transfer, and program branching.
Experiment 2: Reading From the DIP Switches and Writing to the LEDs and 7-Segment Displays
Figure 4 A program is downloaded into the single board computer (SBC) by using parallel communication. [Color figure can be viewed in the online issue, which is available at www.interscience.wiley.com.]
of water temperature and displaying the measurement result.
Experiment 1: Basic Programming of the Microcontroller The objectives of the Experiment 1 are to understand the AT89S52 microcontroller architecture and to program the microcontroller. In this experiment, first, the SBC parallel port is connected to the PC printer
The objectives of this experiment are to read the DIP switches voltage levels (logics) and to write to the LEDs and 7-segment displays. From the functional block diagram given in Figure 6a,b, it is shown that the inputs (the DIP 8-bit switches) are sent to port 0 of the microcontroller through the 74LS245 buffer chip. By making pin E of the buffer chip to be low, the buffer chip is activated and the 8-bit input data reach the microcontroller. In order to display the input data, port 2 of the microcontroller is connected to the LEDs or the 7-segment displays with the 74LS247 decoder. If pin E of the display is high, then the input data are displayed. In the case of LEDs, each bit of the input data is represented by each LED, in which if the bit is low/high, then the LED will turn on/off.
Experiment 3: Application of the Analog Multiplexer and the ADC With the LCD The functional block diagram of the experiment is shown in Figure 7. The objectives of the experiment
Figure 5 Functional block diagram of a microcontroller.
AN AT89S52 MICROCONTROLLER-BASED SBC
171
troller after enabling the 74LS245 buffer (P1.4). After the microcontroller processed the hexadecimal code, first 3-bits of port 1 (P1.0 P1.2) will send 3-bit control data to the control inputs of the analog multiplexer to select a channel. The selected analog input sends its analog voltage to the ADC which is enabled by bit 4 of the port 1 (P1.3). The analog voltage is converted into digital data by the ADC. The digital data are then received by the microcontroller through the port 0 to be displayed by the LCD which is connected to the port 2.
Experiment 4: Application of Serial Communication Figure 6 Block diagram of reading from the DIP switches and writing to (a) the LEDs and (b) the 7-segment displays.
By using the functional block diagram in Figure 8, the objectives of this experiment are to become familiar
are as follows: (i) to read analog voltage inputs (IN0 and IN7 stand for potentiometers in the SBC, IN1 IN6 are reserved for external inputs which are provided by connectors in the SBC), (ii) to select a channel of the analog multiplexer by pressing a button of the keypad, (iii) to display the selected data input to the LCD. If the keypad button is pressed, an interrupt request is sent to the microcontroller (INT0) and the hexadecimal code reaches port 0 of the microcon-
Figure 7 Block diagram of application of the analog multiplexer and the ADC with the LCD.
Figure 8 Block diagram of application of serial communication in the selection of an input channel and displaying the input data to the LCD.
172
KHAIRURRIJAL ET AL.
Figure 9 Serial communication between the SBC and the PC and the HyperTerminal display.
with the application of serial communication and the HyperTerminal. A PC is connected to the SBC through its serial port as shown in Figure 9. The PC sends command data to the microcontroller by using the serial communication. The command data ask the microcontroller to select a channel of the analog multiplexer by sending bits of P1.0, P1.1, and P1.2. An input is then selected to send its voltage level to the ADC. Next processes follow those explained in the Experiment 3 with the interrupt request of the keypad button is excluded.
Experiment 5: An Instrumentation System for Temperature Measurement Figure 10a gives an instrumentation system for measuring water temperature with the objectives are as follows: (i) to understand characteristics of the temperature sensors, (ii) to apply the knowledge obtained from the previous experiments to the instrumentation system, (iii) to get accustomed to the LabView as a software for simulation, real time measurement, and data processing (Fig. 10b).
Figure 10 (a) An instrumentation system for measuring temperature of water and (b) Temperature as a function of time is displayed by using the LabView. [Color figure can be viewed in the online issue, which is available at www.interscience.wiley.com.]
displays, an LCD, a pushbutton, a keypad, an ADC, serial and parallel communications. The SBC is used by the sophomore students of the Department of Physics at the Institut Teknologi Bandung (ITB), Indonesia who are taking the three-credit instrumentation system course to complete their laboratory experiments. There are five microcontroller-related laboratory experiments which are offered to the students within the 15-week semester. The laboratory experiments are (i) basic programming of the microcontroller, (ii) interfacing the DIP switches, LEDs, and 7-segment displays, (iii) application of the analog multiplexer and the ADC with the LCD, (iv) serial communication and application of the HyperTerminal, and (v) measurement of water temperature, displaying the measurement result, and application of the LabView.
SUMMARY
REFERENCES
We have designed and developed the SBC integrating the MCS-51 microcontroller with LEDs, 7-segment
[1] J. S. Mayer, T. N. Jackson, and M. E. Lockley, A new role for microcontroller courses: Integrating EE
AN AT89S52 MICROCONTROLLER-BASED SBC
curricula, 25th Annual Conference on Frontiers in Education, Atlanta, GA, 1995, Session 3a4. [2] M. Rabiee, ‘‘Design, construction, and analysis of a microcontroller system, Comput Educ J 6 (1996), 63 68. [3] T. K. Hamrita, Microcontrollers in the biological and agricultural engineering curriculum at the University of Georgia, Proceedings of the 2002 American Society for Engineering Education Annual Conference, Montreal, Canada, 2002, Session 1526. [4] K. B. Lodge, The programming of a microcontroller as an integral part of process control for undergraduate
173
chemical engineers, The 2002 North Midwest Section Annual Conference of the American Society for Engineering Education, Madison, WI, 2002, pp 1 10. [5] E. J. Gonzalez, A. Hamilton, L. Moreno, R. L. Marichal, and S. Torres, A set of microprocessor-based procedures for an industrial engineering course, Comput Appl Eng Educ 12 (2004), 145 151. [6] D. Beetner, H. Pottinger, and K. Mitchell, Laboratories teaching concepts in microcontrollers and hardwaresoftware co-design, 30th ASEE/IEEE Frontiers in Education Conference, Kansas City, 2000, Session S1C.
BIOGRAPHIES Khairurrijal received the BSc and MSc degrees in physics from Institut Teknologi Bandung (ITB), Bandung, Indonesia, in 1989 and 1993, respectively, and the Dr. Eng. degree from Hiroshima University, Hiroshima, Japan, in 2000. He joined the Faculty of Mathematics and Natural Sciences, ITB, in 1991 and is currently an associate professor of physics of electronic materials and devices. He is extensively involved in research on electronic materials and devices as well as electronics and instrumentation. Muhammad M. Munir received the BSc and MSc degrees in physics from Institut Teknologi Bandung (ITB), Bandung, Indonesia, in 2003 and 2005, respectively. He is currently pursuing the PhD degree in chemical engineering at Hiroshima University, Hiroshima, Japan. His research interests include electronic instrumentation, telemetry, and sensors.
Asep Suhendi received the BSc degree in physics from Institut Teknologi Bandung (ITB), Bandung, Indonesia, in 2005, where he is currently working toward the MSc degree. His research interests include electronic instrumentation, telemetry, and sensors.
Hendrayana Thaha received the BSc degree in physics from Institut Teknologi Bandung (ITB), Bandung, Indonesia, in 2005. He is currently pursuing the MSc degree in electrical engineering at the University of Petronas, Malaysia. His research interests include electronic instrumentation, telemetry, and sensors.
Maman Budiman received the BSc degree in physics from Institut Teknologi Bandung (ITB), Bandung, Indonesia, in 1989 and the MEng and PhD degrees in physical electronics from Tokyo Institute of Technology, Tokyo, Japan, in 1995 and 1998, respectively. He joined the Faculty of Mathematics and Natural Sciences, ITB, in 1991 and is currently an assistant professor. He performs research on optoelectronic materials and devices as well as electronics and instrumentation.