视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
Integrating hardware and software for the developm
2025-09-27 23:36:49 责编:小OO
文档
Integrating hardware and software for the development of

microcontroller-based systems

A.H.G.Al-Dhaher *

Faculty of Engineering,School of Information Technology and Engineering,University of Ottawa,150Louis Pasteur,McDonald Hall,

Ottawa,Canada K1N 6N5

Received 2April 2001;revised 30July 2001;accepted 6August 2001

Abstract

The importance of microcontrollers as programmable devices to the education of electrical and computer engineering students is realized.The experience of developing a microcontroller course and its associated laboratory is reported.Emphasis is directed towards understanding the importance of such devices in microcontroller-based systems.Laboratory facilities for hardware interfacing and programming techniques are described.Projects based on students'designs,implementations and successful results are reported.q 2001Elsevier Science B.V.All rights reserved.

Keywords :Microcontroller;Instrumentation;Programmable

1.Introduction

The presence of microprocessors/microcontrollers in electronic products is becoming undoubtedly noticeable.Their use is no longer limited to their implementation in home and of®ce appliances,instruments and machinery but has extended into one's daily life.People are likely to carry devices such as a digital watch,electronic organizer,cellular phone and pager.Microprocessors/microcontrollers are even used in certain smart running shoes [1].Implement-ing these devices into hardware design increases design capabilities and simpli®es implementation.Due to this fact,it is important that electrical and computer engineering students have undergraduate experience with microproces-sors/microcontrollers [2±5].Other engineering disciplines such as mechanical engineering are addressing microcon-trollers because the power of microcontrollers in problems solving [6,7]is more recognized.In many instances a university ®nds dif®culty in providing experience in the ®eld of programmable devices due to insuf®cient allocation in the curriculum,shortage of lab space or budget constraints.However,as microprocessor/microcontroller-based systems become more wide spread,there is a growing necessity for present and future engineers to view hardware and software as an integrated unit.In order to satisfy this

necessity,the University of Ottawa developed a lecture course complemented with a teaching laboratory and a senior level project laboratory on microcontroller-based systems.The main feature of this course and the two labora-tories is the integration of hardware and software.

The purpose of the course and the two laboratories is to show the importance of implementing programmable devices in instrumentation.Programmable devices nowa-days vary in their speeds,capabilities,complexities and costs.The decision regarding the type of programmable device to be implemented in the course is a critical one.In the past,emphasis was placed on microprocessor-based equipment.For that reason,teaching revolved around microprocessor-based equipment [8].The advancement of microcontrollers and what they offer combined with their speed,made them more suitable for instrumentation.The basic functional characteristics of microprocessors and microcontrollers are very similar.Their operation is very similar in that they both process a series of instructions that constitute a program.The main difference is that while microprocessors are oriented towards higher Million Instruction Per Second (MIPS),microcontrollers are designed with interface circuitry on the chip that provides I/O ports,timing capability,A/D converter,synchronous/asynchronous interface and various memory types.The availability of these peripherals on the chip is an attractive feature as new designs will require fewer chips outside the microcontroller and hence result in compact,less costly

Microprocessors and Microsystems 25(2001)317±328

0141-9331/01/$-see front matter q 2001Elsevier Science B.V.All rights reserved.PII:S0141-9331(01)00124-7

www.elsevier.com/locate/micpro

*Tel.:11-613-562-5888;fax:11-613-562-5187.

E-mail address:dhaher@site.uottawa.ca (A.H.G.Al-Dhaher).

The lecture course and the two laboratories offered to electrical and computer-engineering students are designed to cover concepts and topics on the use of these devices in instrumentation.Emphasis is placed on what is expected from microcontrollers in an instrumentation domain.Thus, interfacing and/or illustration of interfacing and real-time programming are emphasized.The students enrolled in the course and laboratories are expected to have suf®cient back-ground in courses related to,or requiring programmable instrumentation.By the completion of these courses students would have taken the following:

²electronic circuit course(two courses with circuit labora-tory);

²an introductory course in logic design(with a digital lab);²microcontroller course covering programming and inter-facing(with a microcontroller lab);

²senior laboratory project emphasizing interfacing.

The senior laboratory project entails intensive laboratory work and lasts the entire semester.The projects are geared towards designing,programming and interfacing the micro-controller.The advantages of offering such course options to electrical and computer-engineering students are summarized:

²aids students in understanding the fundamentals of programmable devices in particular microcontrollers;²shows students how the software and hardware compo-nents of microcontroller-based systems work together to implement system design and teaches numerous hard-ware/software aspects;

²offers hands-on experience in interfacing digital devices (e.g.memory,I/O devices)into microcontroller-based systems;

²shows students how microcontrollers can be used in embedded systems and demonstrates the freedom and versatility of the equipment built around these devices;²helps students understand important concepts covered in the class,particularly,real time programming;

²students are able to apply digital logic design knowledge combined with assembly language programming.

The present paper describes Ottawa University's experi-ences in developing the lecture course and its associated laboratories.Experience and knowledge gained in this course is implemented in the senior project laboratory in which students take the responsibility of developing the prototype of a microcontroller-based system.The following sections outline the results of this experience by describing the course outline and its associated laboratory experiments that were carried out to implement the concepts covered in the lectures.Additionally,selected samples of the completed senior projects are presented.The entire process of developing these new courses,of course,starts with setting up the laboratory and selecting the right micro-controller.

2.Laboratory facilities

2.1.Hardware

In order to satisfy the course objective,widely used microcontrollers that are suitable for instrumentation must be considered.Presently,there is a wide variety of micro-controllers available in the market.Selecting the proper microcontroller is a critical decision because it may have an impact on the reaction of the students towards the course and the lab.There are several criteria one should consider when choosing a microcontroller[1,9,10]:

²Microcontroller performance.The selected microcon-troller should provide a certain level of performance. Bus speed and instruction cycle times are signi®cant contributors to performance.The best performance is obtained with a high bus speed and a low number of cycles per instructions.Interrupt latency and peripheral performance are also important.

²Microcontroller suitability.It is important to®nd a microcontroller with required peripherals.These include memory(type and size),number of timer channels, required number of I/O,and analog to digital(A/D) converter.

²Cost and availability.In selecting a microcontroller,the cost should not be an obstacle in the path of learning. Therefore,purchasing the microcontroller at a moderate cost is a sensible choice.Present and future availability of the microcontroller should also be considered.

²Development tools.These are essential elements.The tools should be of high quality,bug free and perform superiorly.The tools include assemblers,compilers and debugging tools such as evaluation modules,in-circuit emulator and Debug monitor.

²Architecture type(8,16or32bit).The microcontroller to be selected should match the size of the problem the student works on.Also,the chosen microcontroller preferably represents a modern device without too many complicated features that may distract students from learning the basic features.The8-bit microcontrol-lers have been on the market for a while.They have proved to be very ef®cient in handling tasks and have been implemented in many designs.Most applications for these processors were developed in assembly language.The new16-bit microcontrollers have a high

A.H.G.Al-Dhaher/Microprocessors and Microsystems25(2001)317±328 318

performance level and offer many on chip peripherals as well as sizeable memories (RAM,EEPROM and ¯ash memory).They are also suitable for high-level language programming and their prices are becoming more and more reasonable.These factors have made the 16-bit microcontrollers more attractive to the high tech indus-try.A 32-bit processor may be considered as a modern device that a graduate student should become familiar with [11].However,a 32-bit processor is felt to be too powerful to be understood in a short period of time.Undergraduate students have limited hours in the labora-tory compared to an industrial project involving many months of full time work.Moreover,the cost is high.Based on these criteria,the 16-bit microcontroller is believed to be a reasonable choice.

The popularity of the microcontroller was also consid-ered,insuring that our graduates gain knowledge in a known and modern microcontroller.Furthermore,the avail-ability of documentation such as textbooks and reference materials is taken into account,as they are important for the course work and the project.

Based on all the considerations the Motorola MC68HC12family was chosen.The Motorola MC68HC12family of microcontrollers is a highly integrated,general-purpose family with a 16-bit architecture.Motorola makes different versions of microcontrollers;the most popular ones are the MC68HC812A4and MC68HC912B32.These two versions are compatible in their instruction set but differ in other features such as the SCI and wakeup.

Among many of their attractive features is low-power consumption,low voltage operation at full bus speed,high level language optimization,¯ash EEPROM and byte erasa-ble EEPROM,¯exible I/O port functionality and a timer interrupt channel.Its instruction set contains fuzzy logic

instructions [12].The MC68HC12has a very powerful and versatile timer system.The capabilities of the time system made the MC68HC12very suitable for developing embedded systems.The timer system is based on 16-bit counter operating from the system clock.This counter provides several real-time functions with features such as:up to eight output compare functions that generate a variety of output waveform,eight input capture functions that can latch the value of 16bit counter on selected edges of eight timer input,programmable periodic interrupt generator,16bit pulse accumulator to count external events and a timer over ¯ow to extend the 16bit counter capability.The MC68HC912version has pulse-width modulation (PWM)module giving up to four pulse-width modulated waveform.This is an attractive feature for the control of certain devices such as a stepper motor.Once the PWM module has been initialized,pulse modulated wave forms are outputted auto-matically without the need for further action from the program.All these features make the microcontroller suita-ble for instrumentation purposes.Not only is the MC68HC12widely used in the industry,but many academic institutions are adopting it:Montana State University,University of Texas at Austin,John Hopkins University,Queen's University,Simon Fraser University,University of Guelph,University of Canterbury-New Zeland.Text-books [13±16]are available for teaching these microcon-trollers.

Due to the time constraint imposed on developing the lab and the large number of student enrolment,readily available evaluation boards (EVB)were taken into consideration.The EVB board is a cost effective board for designing and debugging code for evaluating the operation of the MC68HC12.The EVB board provides all timing and I/O circuitry.The board operates on 3±5V and provides one or two (depending on the choice)RS232interfaces.The board provides connectors for access to the microcontroller I/O and bus lines.It comes with an IASM12assembly language development tool kit.Code can be generated externally and loaded into the board using ®le transfer capability.The two boards considered for developing the lab are the MC68HC12A4EVB and the MC68HC12B32EVB.Table 1shows comparison features of these two boards.Because a large number of these boards are needed and their accu-mulated cost was high,the MC68HC12B32board was not chosen.This board is affordable and only cost 20%of the MC68HC12A4EVB.This board is less ¯exible in the memory space but its cost effectiveness makes it more suita-ble for the University's needs.The main draw back of this board is its limited RAM.Half of the 1KB is used for the monitor program leaving only 0.5KB as user memory.This disadvantage sometimes places a restriction on the size of the program,which the students may write.For teaching laboratory experiments the RAM available was found suf®-cient.However,students trying to practice further program-ming by writing large programs have the choice of using 768byte EEPROM and for larger programs students can

A.H.G.Al-Dhaher /Microprocessors and Microsystems 25(2001)317±328

319

Table 1

Shows the MC68HC12A4EVB and MC68HC12B32EVB features MC68HC12A4EVB MC68HC12B32EVB Chip used:MC68HC812A4Chip used MC68HC912B32On chip memory On chip memory 1KRAM 1KRAM

4KEPROM 768EEPROM

32KB ¯ash memory

On board memory 16KSRAM 32KEPROM Two RS232

One RS232

16MHz crystal oscillator 16MHz for 8MHz bus operation Firmware

Firmware

D-Bug12monitor/debugger D-Bug12monitor/debugger Dumb terminal/host computer interface

Dumb terminal/host computer interface

Single line assembler/disassembler

Single line assembler/disassembler

File transfer capability

File transfer capability

erase the D-Bug 12and use the whole 32KB ¯ash memory.Such an approach was adopted in the senior projects.In a few boards students added 2KRAM externally to expand the RAM space.Such an expansion is considered for the whole set of boards.

The limited space of user RAM available for data,program and stack turned out to have an advantage for beginner programmers in assembly language.This fact forced the students to develop compact programs and struc-ture their codes,data and stack space.Furthermore,the students learn careful design methods for their program

before beginning to code.However,the board's reasonable cost made it possible to purchase many boards.It is shown that its facilities are suf®cient to apply all concepts covered in the course lectures.

The MC68HC912B32EVB comes in a 5in.£3.5in.PCB,which provides a platform for interface and power connections to the microcontroller.The board allows custom interfacing with the microcontroller I/O and bus lines.The board provides four different modes of operations that are jumper selectable.In order to protect the unit during transportation from any damage or misuse and to limit the jumper con®guration,the board was housed in a plastic box with a transparent cover and all the connectors were perfo-rated through the cover providing easy access to the connec-tors.An AC/DC converter powered the unit.This design made it easy for the board to be transported and allowed students to work on the board outside the lab.Students build their circuits on solderless breadboards and used hookup wires to connect it to the evaluation board.The evaluation board is connected to a PC using a RS232cable and the ports on the PC (COM1or COM2).The evaluation board,the solderless breadboard and the PC make one workstation as shown in Fig.1.The boards are not rigidly ®xed to the station;they can be disconnected and relocated.The Univer-sity provides the microcontroller boards,the breadboard and all the required components.In small classes,students can borrow the boards for work outside the lab.This arrange-ment was very ¯exible and saved students a considerable amount of time.The lab environment consisted of 35-networked workstations.All network users utilized the soft-ware installed on the network.The PCs operated on MS Windows 98and students had access to all the software on the University network and have Internet connections.This arrangement was found to be very useful in allowing students to backup their developed software to their accounts that could then be accessed from anywhere on campus.Also,networking all the stations helped students pass ®les between different stations,facilitating the software development process.2.2.Software

Software taught in the lecture course and used in the two laboratories was based on system architecture and was aimed at controlling and operating instrumentation.To understand system architecture,assembly language was used.In order to develop software for instrumentation,the basis for real-time programming,particularly interrupt handling,was given special importance.

To develop and debug microcontroller software,a stable operating environment was required.One of the most simple and economical development environments consists of a monitor/debugger program that resides in ROM and executes in the target environment.The monitor provided signi®cant advantages by facilitating access to internal utility routines and default exception handlers.Resident

A.H.G.Al-Dhaher /Microprocessors and Microsystems 25(2001)317±328

320Fig.1.A workstation consisting of a PC,evaluation board and solderless

breadboard.

Fig.2.D-Bug12display shows response to memory and register display commands.

A resident monitor program existed on the evaluation board.The D-Bug12,the EVB®rmware resident monitor program,provided a self-contained operating environment that allowed writing,evaluating,and debugging the user program.The D-Bug12,provided on the EVB,was installed on a32K

B on-chip¯ash memory.It can be removed and replaced by the user program.This monitor program was very useful in the assembly language program development. Commands were typed on the terminal's D-Bug12prompt line and executed as the user pressed ENTER.D-Bug12 then displayed an appropriate response to the command.The D-Bug12offered the user the ability to see the register contents after each operation,to single step through the program and to execute instructions considerably more slowly than with the real hardware system.Figs.2and3 show a display of some of D-Bug12commands entered and the response obtained.D-Bug12allowed the user to interact with the EVB from a terminal.In addition,it had utility subroutines that could be used by the programmer.The monitor program communicates with the P

C using a serial port on the EVB.The HyperTerminal application provided with MS Windows98was used to communicate with the EVB.

Motorola suggests other communication programs such as ProComm and Kermit for DOS.HyperTerminal was found to be suf®cient and easy to use.

For small programs or subroutines,D-Bug12single line assembler was used to change object code directly into the EVB memory.For a large program,students used the ISAM12assembly language toolset,which provided an integrated development environment that included project manager,relocatable macro-assembler,linker,and S-record generator.This is a line command assembler.For a Windows environment,students used winIDE supplied by P&E Computers.In addition to its use as a debugging tool, the D-Bug12provided access to18different utility routines. Table2shows some of these utility routines.These routines can be expanded to a maximum ofindividual utility routines[17].The use of these subroutines helped the students signi®cantly in developing programs.Instead of developing these routines,students spent their time solving the tasks at hand.

Another alternative to software development,which is becoming popular lately,is the use of simulator software. With this technology,students can generate assembly code and execute it in a simulated environment.There are several simulators reported in the literature[14,18,19].Some simu-lators restrict students to programming that does not involve interfacing.In certain reported courses,a simulator is suggested for the beginning of the course[19].Some sophis-ticated simulators offer simulated interfacing in which students can observe simulated ports[14].Use of simulators can be misleading since some simulators do not consider timing issues.Even though simulators may demonstrate correct code,they are driving the I/O ports too fast.If this code is to run on an actual microcontroller,it will fail because the controller is communicating faster than the device could respond.

As a means of helping students understand the concepts covered in the lectures and to assist them in solving class assignments,student used the simulator,Test Execute and Simulate(TExaS).This simulator was provided with a free textbook recommended to the class[14].Student found the simulator powerful and easy to use.This simulator was designed for educational objectives in understanding how the computer functions.The simulator was used as a self-teaching tool to write and test software.The simulator

A.H.G.Al-Dhaher/Microprocessors and Microsystems25(2001)317±328

321

Fig.3.D-Bug12display shows response to memory and register modify commands.

Table2

Some of the D-Bug12subroutines

Subroutine Function

main()Start of D-Bug12

Character routines

getchar()Get a character from serial I/O

port

putchar()Send a character out to the serial

I/O port

Isalpha()Check of the character is

alphabetic

String routines

printf()Formatted string output

GetCmdLine()Get a line of input from the user

strlen()Returns the length of a null

terminated string

EEPROM routines

EraseEE()Erase all of the EEPROM

memory

WriteEEByte()Write a byte in the EEPROM

memoryshowed the activity within the chip such as the address/data bus,the instruction register and the effective address regis-ter.Also,the simulator had the ability to connect to simu-lated external hardware such as switches,keyboard,LED, logic probes,voltmeter and logic analyzer.The simulator supported many of the I/O ports functions such as interrupts, serial port,input capture,output compare and key wake up. The tutorial provided with the simulator clearly illustrated the simulator's capability and simpli®ed the learning process.Students found this simulator helpful in solving class assignments and preparing for lab experiments.

3.Course structure

The students enrolled in this course were a mixture of computer and electrical engineers.For the®rst category the course is a requirement and for the second category,it is an elective.Most electrical engineering students choose to take this course.The students were either in third or fourth year.All students completed at least one course in high-level language programming,mostly C/C11.Some students had taken several other computer science courses such as operating systems.All students had completed two courses on circuit theory and two courses in electronic circuits covering all basic concepts in devices and their use in circuits.All students before enrolling in this course must have completed a logic design course,which is intended to deal with the fundamental aspects of digital electronics.The course included number systems,logic gates,Boolean algebra,karanaugh map combinational and sequential circuits and state machine.The course consisted of3h of lecturing and3h of labs per week.By the comple-tion of this logic design course,students were well knowl-edgeable in the fundamentals of digital electronics and were very familiar with different components in lab experiments. Following the logic design course,students are admitted to the microcontroller course.The microcontroller course introduced the students to the application side of micro-controllers and where they may be used to substitute hard-ware logic.The course covered:

²microcontroller architecture;

²instruction set and addressing mode of the MC68HC12;²structured assembly language programming of the MC68HC12;

²parallel and serial I/O;

²interrupt and interrupt handling;

²timer systems and real-time control;

²bus and memory interfacing;

²analog input.

The logic design course and the microcontroller course are believed to suf®ciently cover all aspects of hardware and software.They de®nitely offer students a suf®cient back-ground in the use of a microcontroller.The above two courses and their complementary laboratories are practi-cally oriented and emphasize programming and interfacing of the microcontroller.Most of the concepts covered in the microcontroller lecture course are put into practice and students verify these concepts in the teaching laboratories.

4.Teaching laboratory

A laboratory runs concurrently with the lecture course. However,it was found that students were spending more than this allotted time in the lab.The lab was aimed at giving students the opportunity to apply the concepts learned in the class.This arrangement allowed the students to be more involved in the design of an experiment and to develop experience in laboratory investigations with limited supervision.Students were required to complete®ve labora-tories involving hardware and software.The complexity of the experiments increased as the lab progressed.In addition to applying concepts learned in lectures,the teaching lab was also intended to give students a starting direction in the design and implementation process.This arrangement prepared the students for the tasks they would encounter as they proceeded to their senior project laboratory.Experi-ments covered basic understanding of the architecture of the microcontroller,data manipulation,and bits and bytes operation.Table3summarizes the labs and their purposes. Since the course was aimed for utilizing the microcontroller for instrumentation and on-line data processing,the experi-ments emphasized software control and I/O devices.They involved limited numerical computation.The experiments were intentionally designed to show the students how soft-ware and hardware can be integrated.In designing the lab experiment,a balance was made between maintaining a level of complexity and allowing the students to achieve the challenging tasks.As less time was given for the lab sessions,the lab experiments did not cover advanced topics such as timing and pulse width modulation.These topics were dealt with extensively in the senior projects(discussed

A.H.G.Al-Dhaher/Microprocessors and Microsystems25(2001)317±328 322

Table3

Teaching laboratories and their purpose

Laboratory Purpose

1Familiarize students with the work environment;learn the

functionality of the assembler,loading program,debugging

techniques and writing a simple assembly language

program

2Learning to write more complicated programs using

structured assembly language programming

3Interfacing principles of basic devices to microcontroller.

Replacing hardware decoder by using the lookup table

stored in RAM

4Interfacing keypad and switches using parallel I/O ports of

the microcontroller

5Learning principles of interrupt handling using foreground

and background jobs

later).The teaching laboratory included the following experiments.

4.1.LAB1:introduction to the development environment This lab introduced the students to the development environment(hardware and software).This lab showed the students how to establish communication between the EVB and PC using HyperTerminal.Students learned how to use the D-Bug12commands and some of the D-Bug12 routines to display text on the terminal.Students also learned and practiced data manipulation in the memory locations.They learned applications of basic principles of debugging and basic assembly language programming. Students wrote assembly language programs to perform arithmetic and logical operation using buffers.

4.2.LAB2:structured assembly language programming This lab was set towards teaching assembly language programming.Students were gradually taught how to achieve this goal.In the®rst part,mathematical and logical operations were applied on content of two buffers.The results were displayed in binary,decimal and hexadecimal format.A message of over¯ow was to be printed if an unsigned over¯ow or two's complement over¯ow occurred. In the second part students acquired experience in structured assembly language programming.Students were given designs in the form of pseudo code.They were required to implement the designs and write structured programs using DO±WHILE loop to add and XOR bytes in two buffers and store the result in different buffers.The program was required to output a certain number of bytes in hexadecimal and binary format using a counter and DO±WHILE loop. To output the buffer content in binary format the program was required to perform DO±WHILE loop to go through all the bits by shifting the data left.This was a good opportunity for the students to practice nested loops.In the third part students were required to produce a fully structured design using structured programming and pseudo code implement-ing principles of top±down design.The designs required students to include at least one WHILE DO or DO WHILE and at least one IF THEN ELSE loop structures. The students were required to carry the design to a level where it could easily be converted to a program.The given task was to prompt the user to enter a character from the keyboard.The program would then print out the entered character,its ASCII code,its hexadecimal and binary repre-sentation.The program was to continue until the user types ESC character.At that point,the user would be informed that the program was returning to its regular program(the D-Bug12monitor).Students were required to use subroutines to print out the binary code.

4.3.LAB3:hardware interfacing input and output devices(switches and LED)on the expan-sion board to the MC68HC12I/O ports.The students wrote software to read the4-bit switches and output to a TTL7447 seven-segment decoder.In the second part of the experi-ment,students removed the hardware decoder and created a lookup table in the MCU RAM internal memory.They constructed the lookup table and supporting assembly program such that the seven-segment LED unit displayed the proper®gures from4-bit DIP switches inputs.When choosing the ports in this experiment,some ports were partially available while some did not facilitate built in pull-up or pull-down resistors.In these cases students were to build these pull-ups/pull-downs.Also,students learned to insert buffers between the external device and the MCU to protect the MCU from high current.

4.4.LAB4:parallel I/O

In this lab,students studied the parallel I/O and interfaced a hex-keyboard controller with LED.In the®rst part, students constructed an I/O circuit and attached it to the EVB board.The circuit was required to have a set of8 switches attached to one port and eight LEDs attached to another port.The program was to read switches attached to an input port and display their values to the output port.In the second part,students interfaced a12-key keyboard to the MC68HC12.The MCU displayed its keyboard input on a seven-segment LED.Students were required to write a program to instruct the microcontroller to detect keyboard activity.Accessing the seven keyboard wires through a single I/O port monitored the keyboard.Each pin could have been declared as input or output.Students also took into account the bouncing effect of the switches.

4.5.LAB5:interrupt and interrupt handling

This lab demonstrated the concept of interrupt using fore-ground and background jobs.Students were required to write a main program that had a foreground job of continu-ously getting characters from the keyboard and displaying them on the screen.This was done until RESET was pressed.If an external IRQ interrupt was encountered at any time during the program,the Interrupt Service Routine (ISR)was entered and it printed,`SDB switch pressed'on the monitor(i.e.background job).Once the ISR exited,a message was printed on the screen informing the user that the interrupt handling routine was completed.The program then returned to obtain characters from the keyboard and display them onto the screen.

The experiments in the teaching lab covered numerous types of hands-on experience.After completing these experiments,students became familiar with the develop-ment environment and gained experience in programming and debugging techniques.Combining all these skills with previous knowledge gained from other courses gaveand implementation.Such an opportunity was offered in the project laboratory.

5.Project laboratories

After successfully completing their work in the teaching laboratory,students were admitted to a senior level labora-tory.In this laboratory,students selected more extensive projects to be completed in one semester.To teach students the importance of teamwork,a group of®ve students formed each team and worked on a single project.

This senior level course was considered to be the most important one in the series of courses in the digital stream. In selecting a project,the students were expected to practice and apply the knowledge they gained from previous courses. The projects selected were to simulate,to a certain extent, typical problems students are likely to face in their future employment or higher education.Students were given the freedom of selecting their projects and in many cases;start-ing points were given to the students.Many students showed great interest in performing their projects using their knowl-edge gained as a base for further development.The projects given were based on the most challenging topics of micro-controllers:handling interrupts,the use of timer system and the use of pulse width modulation.The®rst was meant to let students understand real time programming and the second and third,to handle timing and control tasks.In the teaching and no experiments were given on the timer or pulse width modulation.Therefore,learning and implementing these topics was believed to represent®ne challenges to the students.The projects conducted in one semester included a line tracking robot,infrared control,networking,real-time operating systems and stepper motor control.The following sections summarize some of these projects.

5.1.Line tracking robot

The objective of this project was to build a robot that followed a black line on the¯oor.When the robot moved in a straight line the software did nothing but power the wheels'motor.When the robot encountered a turn it adjusted its front wheel direction such that it followed the black line.On the bottom of the robot there were two sensors,left and right sensors.These were used to direct the robot to stay on the black line.The width of the black line was about2in.to insure that the sensors stayed within the line.The robot had a front switch that was used to stop the robot when it collided with an object.For this project a remote controlled car was used.Removing all the control circuits except for the direction sensors,wheels motor and direction motor modi®ed the car.

Due to the need of a wakeup key,the M68HC812micro-controller was used.This MCU and all the built circuitry were placed on a solderless breadboard,which in turn,was placed on top of the robot.The robot was powered from a battery to allow it to move freely.In interfacing the robot to the MCU,all inputs and outputs were buffered.This was done to avoid damage to the chip due to high voltage or current,short circuit output or draining too much current from the output port.CMOS invertors were used because their transfer functions are perfectly symmetrical.Fig.4 shows the circuit diagram and connection to the MC68HC12.The two sensors were connected to I/O port that was used as a key wakeup and they generated an inter-rupt when the robot deviated from the black line.Another I/ O port was used as an output port to control the direction motor.Bits of output port were connected to LEDs and used as indication for debugging purposes.Direction sensors gave information about the current wheel direction.They were connected to an input port.A timer port was con®g-ured as an input captures or output compare.The timer was used to generate interrupts and the pulse width modulation unit was used to generate a pulse width modulated signal to control the speed.

The software was developed in assembly language and consisted of several subroutines.Fig.5shows a¯ow chart representing the movement of the robot.At the start,the line-tracking robot wheels were straight.After initialization, the program entered an in®nite loop that waited for an inter-rupt.When a curve was encountered,one of the line track-ing robot sensors left the line and generates an interrupt. Program execution went to an interrupt service routine.In

Fig.4.Circuit diagram and connection to the MC68HC812.carried out to determine which sensor generated the inter-rupt.If the left sensor generated the interrupt,this meant that the sensor was no longer on the black line and the robot was drifting leftwards.To rectify this drift,the program entered the turn-right subroutine.This subroutine set the bit corre-sponding to the right direction motor.This made the wheels turn right.After this,the program tested the left sensor in order to determine whether or not it was back on the line. When this was con®rmed,the program entered the go straight subroutine.This subroutine®rst determined the direction of the wheels.If the wheels were centered,the execution returned from the interrupt service routine to the main program.If however,port B indicated that the wheels were not in a left,right or center position,port B was expected to indicate that the wheels were still turned to the right.This occurred because they were turned to the right to get the robot back on track.If this is the case,the execution would then make the wheels turn left.After several trials the software was improved and the car followed the line with great accuracy.hardware section,students gained immense experience in interfacing to outside devices.On the software side,students applied many concepts of interrupt and interrupt handling. The project used the key wakeup interrupts of the micro-controller.Detecting the occurrence of interrupt,recogniz-ing the source of interrupt and rectifying the cause gave the students good hands-on experience in real-time control. Furthermore,controlling the speed of the motor using pulse width modulation was a major achievement.At the start,students were faced with several dif®culties including the obstacle of how to control the direction of the wheels of the robot and the challenge of controlling the speed of the motor.All these dif®culties were overcome and the®nal results were beyond satisfaction.

5.2.Infrared communication project

The ultimate objective of this project was to build a bi-directional infrared(IR)communication system between two PCs,one being the transmitter and the other the recei-ver.The user would be able to enter a message at the trans-mitter end of the communication system and be able to view the message at the receiver end.Due to the limited time given,a unidirectional transfer was requested.Therefore, the suggested system would not acknowledge the received signals.Additionally,no error detection scheme was included.

Among the different coding schemes available,the project implemented a pulse code that used pulse length modulation.In this scheme the length of the space between the pulses was uniform and the varied width of the pulses represented the data.In addition to the data signal,headers were used to initialize transmission.Headers usually consisted of a long pulse sent before the train of data pulses. The transmitted code was divided into two parts:

²the address,which speci®ed the target device that was using the remote.This address was important because without the address another IR receiver may have processed the transmitted signal;

²the command which included instructions to be sent to the receiver.

The transmitter usually performed modulation by sending a30±40KHz square wave signal to one of several infrared LED for transmission.The high frequencies were used so that other light sources did not interfere with the receiver. The®nal output signal had a logic1represented by a burst of oscillation.Fig.6shows the modulated IR signal.

In order to have control over bit pattern going to the receiver,a special transmitter was built.Fig.7shows the circuit diagram of the built transmitter.The transmitter was built around the555timers that generated a square wave signal,which was set to oscillate at40KHz.The carrier frequency could be adjusted using R2.By connecting the

Fig.5.Flow chart of software routines that control the robot's movement.MCU,the MCU can turn the555ON or OFF.Therefore,the signal from the MCU modulates this oscillator and the resulting signal was applied to the IR LED to generate the output waveform.The MC68HC12was programmed to create a pulse with a speci®ed duty cycle utilizing timer port.The entire bit stream resembled a pulse-coded format with pulse width varied to represent the data.A long pulse represented logic1and a short pulse represented logic0. For the receiver,a commercial infrared detector was used. Fig.8shows a schematic of this detector.Fig.9shows the circuit diagram in which the detector is used.The Motorola 74LS14is an Schmitt-trigger inverter that provided the waveforms with sharp edges for the MC68HC12input. The implementation was based on the input capture feature provided by the MC68HC12.The input capture was used to measure the period or pulse width of the TTL level signal and to trigger interrupts on the falling edge of the signals.The communication began with messages entered from the keyboard on the transmitter end.Each character was represented by its ASCII code,which could be transmitted one bit at a time.The bits were sent through the encoder then modulated in preparation for IR transmis-sion.The signal was sent via the photodiode in the form of IR light.The wavelength received was turned into electrical energy and was then passed through to be demodulated.Once the signals were detected they passed through the decoder to return the received signal to the original data in bit format.They were then translated into corresponding ASCII characters and®nally displayed on the screen on the receiver side.

This project gave the students outstanding applied experi-ence in the design,implementation and debugging process. Students used the knowledge they acquired in other courses to this project.Students were able to de®ne advantages and disadvantages of various design alternatives such as coding schemes,error detection,error correction and electronic circuits.During the development,students faced with several dif®culties.Firstly,the transmitter photodiode used had many drawbacks.It operated at a low speed and was inef®cient.Also,noise interference from the surroundings resulted in poor reception.It was found that the receiver could sense more than just the transmitted wavelength. The receiver produced unexpected results at a certain level of ambient light.Fragmentation,which occurs when the transmitted voltage level cannot be sustained for a long bit pulse,was found to be a serious barrier.For the same transmitter the error in the received signal varied from5to 60%.Most of these challenges were overcome totally and the rest was reduced considerably.Students were con®dent in having a solution,if they had more time.

6.Student reactions and dif®culties

The general reaction towards the lecture course and the two laboratories was very favorable.Having studied the®rst digital electronic course,the students appreciated the new approach of digital design and the replacement of hardware by programmable microcontrollers.The projects were espe-cially selected so that students would understand program-ming principles and the methods of implementing them. This approach enhanced the students'capability in the design and implementation.

Students did not have dif®culties in the course and the two laboratories as much as their need for readjustment.The enrolled had suf®cient backgrounds in programming in high-level languages.They completed several computer science courses in high-level language programming,prior to this course.The students completed courses in C/C11 and some were familiar with Java.Programming the micro-controller-based systems with an adequate understanding of its architecture was a new concept for them.Once they understood this new approach,they appreciated the fact that they could produce more ef®cient and well-structured programs.The idea of integrating the software and hardware ®nally become a reality to the students.

7.Future expansion

Although this teaching program served its purpose of offering a good start in the microcontroller®eld,it was strongly felt that its expansion would receive a warm welcome by the students.University of Ottawa is in the planning process to program the microcontroller in high-level language C and assembly language together and link the two.The size of the code produced by a high-level language compiler is of concern.New compilers are designed to produce compact code.The architecture of the microcontroller can be a limiting factor.In general,the instruction set and addressing were determining factors in the ef®ciency of the compiler.The Motorola microcontrol-ler M68HC12has been optimized for high-level language implementation.The use of a high level language will allow more complicated tasks to be tackled and will allow real-time applications to be written by assembly language.A C language compiler from Image Craft has been installed and its implementation is promising.

The present development tool set consists of an evalua-tion board,assembler and D-Bug12debugger.These tools allowed students to write code and examine how the code operated on the microcontroller.Future plans include using in-circuit emulators(ICE)to simplify hardware develop-ment.The ICE is interfaced with a PC and is plugged into the target system to represent the microcontroller.Also,it is planned to introduce®eld programmable-gated arrays (FPGA)for interfacing external devices to the MCU.

8.Conclusion

The lecture course and the two laboratories were designed towards teaching the use of the microcontroller as a programmable device for instrumentation.Emphasis was placed on interfacing and programming microcontroller systems.The teaching laboratory was meant to complement the lecture and give students the chance to apply the concepts learned in the class.The teaching lab was also intended to introduce the students to designing and imple-menting the design in preparation for the senior lab project. The senior project emphasized comprehensive laboratory work.It involved planning,designing and implementing solutions to the project.The projects performed included a wide variety of options ranging from a simple control to a very sophisticated real-time application.Programming in assembly language offered the user the full advantage of microcontroller capability.As a follow up to the program it was found that many of the students who studied these courses found jobs in the high-tech industry working on microcontrollers for real-time applications.Students found the course bene®cial and their evaluation was exceptionally encouraging.

Fig.8.Schematic of the infrared

detector.

Acknowledgements

The author would like to thank Professor E.Petriu for his encouragement and support and Mr R.Montcalm,Mr A.Stewart and Mr A.LeHenaff for their assistance.The author thanks all the students who helped in the development of this work.References

[1]R.Bannatyne,G.Viot,Selecting a microcontroller,Embedded

Systems Programming July (1998)95also pages 97±103.

[2]M.Hedley,S.Barrie,An undergraduate microcontroller systems

laboratory,I

EEE Transactions on Education 41(4)(1998)CD ROM folder 05.

[3]T.Tuma,F.Bratkovic,I.Fajfar,J.Puhan,A microcontroller labora-tory for electrical engineering,International Journal on Education 14(4)(1998)2±293.

[4]D.D.Harter,New microcontroller systems course at the University of

Pittsburgh at Johnstown,Computers in Education Journal 10(1)(2000)13±16.

[5]R.S.Weiss,A.Hands-On,Microcontroller project using mobile

robots,Computers in Education Journal 9(2)(1999)41±44.

[6]T.K.Hamrita,R.W.McClendon,A.new,Approach for teaching

microcontroller courses,International Journal on Engineering Educa-tion 13(4)(1997)269±274.

[7]M.Rabiee,Design,construction and analysis of a microcontroller

system,Computers in Education Journal 6(2)(1996)63±68.

[8]A.H.G.Al-Dhaher,Microprocessor teaching,Microprocessor and

Microsystems 5(10)(1981)465±471.

[9]J.Beil,Choosing a microcontroller,Electronic Product Design 17(9)

(1996)61±66.

[10]Motorola Semiconductor Application Note,Document No.AN1057/

D,2000.

[11]S.K.Reinhardt,Integrating hardware and software concepts in a

microprocessor-based system design lab,IEEE Computer (2000)49±55.

[12]Motorola,68HC12,CP12Reference Manual CPU12RM/AD,1997.[13]F.M.Cady,J.M.Sibigtroth,Software and Hardware Engineering Ð

Motorola M68HC12,Oxford University Press,Oxford,2000.

[14]J.W.Valvano,Embedded Microcomputer Systems ÐReal Time

Interfacing,Brooks/Cole Thomson Learning 2000.

[15]G.Doughman,Programming the M68HC12Family,Annabooks,San

Diego,CA.USA,2000.

[16]R.E.Haskell,Design of Embedded Systems Using 68HC12/11Micro-controllers,Prentice Hall,Englewood Cliffs,NJ,2000.

[17]Motorola Semiconductor,Using and Extending D-Bug12Routines,

Document No.AN1280/D,1996.

[18]D.Edwards,Use of simulator in teaching introductory computer engi-neering,International Journal of Engineering Education 15(5)(1999)353±357.

[19]B.Martin-Del-Brio,C.B.Al-Ruiz,A software tool for teaching

microcontroller system principles,International Journal on Electrical Engineering Education 36(1999)279±286.下载本文

显示全文
专题