task 2 briefing
DESCRIPTION
Task 2 Briefing. T he Design of a C omputer Controlled S top Watch. The Technology Used. Based on the Microcontroller card you have built Controlled by a C program compiled on PC to run on the Microcontroller card. ASCII characters are used to transfer data between PC and microcontroller - PowerPoint PPT PresentationTRANSCRIPT
slide 1
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Task 2 Briefing
The Design of a
Computer Controlled
Stop Watch
slide 2
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
The Technology Used
Based on the Microcontroller card you have built
Controlled by a C program compiled on PC to run on the Microcontroller card.
ASCII characters are used to transfer data between PC and microcontroller
You can use a terminal emulator on the PC, there is no special program for the PC
slide 3
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Sample Program
The project worksheet contains a sample program
This is the same program used to test the serial port of your microcontroller card in the lab
Action - every second, the microcontroller sends the time to the PC as a text string over the serial interface .
The time can be displayed on a PC using any terminal program (9600bps, 8 bit, no parity)
slide 4
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
First Task
You first job is to understand the program and produce documentation for it.
To do this you should:
o Compile and run the program
o Add comments to the program
o Produce Pseudocode for the program
Copies of the commented program and Pseudocode must be submitted to your Supervisor
slide 5
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Compiling the Program
The C program on the worksheet is to run on the microcontroller.
This processor uses different machine instructions to the PC
Visual C++ produces machine instructions for the PC - it won’t run on the microcontroller.
CC51 is a C compiler which produces machine instructions which run on the microcontroller
slide 6
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
The Process of Compiling
To compile a program for the microcontroller:Produce the text C code using any text editorUse CC51 to compile the program
o Make sure there are no errors
Transfer the file produced into the microcontroller (use EPROM programmer)o Compiler produces a HEX format file
Insert the microcontroller in your card and test.
slide 7
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Documenting the Program
Before starting to write a new program, you will gain some practice at documenting programs
You should :
1. Understand what the program does(run it if necessary)
2. Add comments to the program
3. Write a Pseudocode description of the program(this should be done before writing a program)
slide 8
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Sample Documentation
Consider the program on the microcontroller used with the dice as an example.
Problem :
Send a ‘Y’ when the button is pressed and send a ‘N’ when the button is released. At the same time, display any received character on the LEDs.
The following shows 3 ways to describe the problem.
slide 9
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
State Diagram
Key Released Key Pressed
Press
Releasechar
received
charreceived
DisplayPattern
DisplayPattern
action trigger
slide 10
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Flow ChartStart
Is keypressed
Is charreceived
Get char
Display Pattern
Send 'Y'
Is keyreleased
Is charreceived
Get char
Display Pattern
Yes Yes
No No
Yes
Yes
slide 11
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Pseudo CodeDo forever [while ( true is true )]{ while ( key not pressed )
{ if (character received){ get character
display pattern }}
send ‘Y’while ( key pressed )
{if (character received){ get character
display pattern }}
send ‘N’}
slide 12
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Comments on TechniquesState Diagram – good graphical technique for
describing a process. Doesn’t help much in writing program. Can be used to clarify design before writing pseudocode
Flow Chart – good at describing sequential processes. Doesn’t help much in writing high level programs, but good for machine level coding.
Pseudocode – good at describing complex processes. Helps to write high level code.
slide 13
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Creating a Stop Watch Function
You now understand the program ! ! !You must modify the program to make it work
as a stop watch.Stop watch control is via the serial interfaceCharacters entered on the PC keyboard will
control the Stop watch<space> hitting the space bar will toggle
the Stop watch on and offR resets the display to zero
slide 14
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
System Diagram
Type <space> to turn on
Type <space> to turn off
Send ASCII characters of time to display
00:01:45
slide 15
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
What You Must DoFirstly, make sure you understand what the
Stop watch does – ask if you don’t understand
Modify the Pseudocode for the clock program to make it act as a stop watch
Code this in CProduce a text file of the programCompile using CC51Load the code into the microcontrollerTest the functionality and debug if necessary
slide 16
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Creating a Clock Function
Create a new Pseudocode for a Clock which responds to the following commands :
A sets the clock to adjust mode. In adjust mode the clock stops until it receives <CR>
Digit in adjust mode, the digits are entered into
1021 the current time
<BS> in adjust mode, go back to last entered digit
<CR> in adjust mode, returns to clock mode
slide 17
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
What You Must Do
Again, you must first understand the problem.In this example, the functionality isn’t so well
defined – you have some options, e.g.o What is displayed on the PC in adjust mode
o What is displayed on PC when a <BS> is received
When you have decided, write Pseudocodeo A State Diagram may help planning
Produce the C program, compile, test and debug
slide 18
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Integrating the Functions
When both Stop watch and Clock are working :Try to combine both Stop watch and Clock into 1
program.The combined program should respond to the
extra commands :
C if in Stop watch mode, switch to Clock mode
S if in Clock mode, switch to Stop watch mode
slide 19
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
The Combined Clock
The Clock must keep the right time, even if it is in Stop watch mode.
Hence, clock must keep running in both modesThe program will need a separate variables for
the Clock and Stop watch.The Stop Watch can keep running in Clock modeThe Clock will stop in adjust mode – you can
decide what the Stop watch does.
slide 20
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
Working with the Push Button
So far, all control has been using the PC keyboard sending ASCII characters to the microcontroller.
Here, go back to the Stop watch to make it controlled by the button on the card
Control is :
Push buttontoggles the stop watch on and off
Hold button if pushed >1sec, time resets to zero
slide 21
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
What you must submit
For all 4 programs, you must submit a short report on your program containing:
o The Pseudocode
o The C program (including comments)
o A description of the operation of the program
Submit report when all 4 programs are done.
Your supervisor will check to see your program working before moving to the next stage.
slide 22
Project 1 Task 2
T&N3311 PJ1
Information & Communications TechnologyInformation & Communications TechnologyHD in Telecommunications and NetworkingHD in Telecommunications and Networking
For the Brighter Students
It is possible that some groups will finish the three programs within 4 weeks.
We do not expect all groups to finish that quickly. However, you must finish all three programs.
The faster groups can then move on the next project task – implementing a network.
This task has scope for groups to make their own design.