Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
The University of Western Australia
Electrical & Electronics Engineering
A/Prof. Thomas Bräunl
Computer Systems and Communications
CSC 163
Lab Assignment 1 week 2+3
EQUIPMENT:
PC with Java web browser
EXPERIMENT 1
Design an ALU (arithmetic logic unit) with the following functions
• central 8bit accumulator
• add a value
• subtract a value
• compare if accumulator equals zero
EXPERIMENT 2
Design a CU (control unit) with the following op-codes
• 01 vv add value vv to accumulator
• 02 vv subtract value vv from accumulator
• 03 dd branch cond. if accumulator is equal to zero by dd distance (pos. or neg.)
• 04 aaaa branch uncond. to specified address
• 05 aaaa load value from memory address aaaa in accumulator
• 06 aaaa store accumulator value to memory address aaaa
EXPERIMENT 3
Write a program to multiply two numbers in memory
Demonstrator:
_______________________
The University of Western Australia
Electrical & Electronics Engineering
A/Prof. Thomas Bräunl
Computer Systems and Communications
CSC 163
Lab Assignment 2 week 4+5
EQUIPMENT:
1. EyeBot platform
2. PC 
3. Cables 
4. Background Debugger
The things that you can do with the EyeBot kit are:
(1) download programs from a PC;
(2) read input from buttons and print output to screen, like on a PC;
(3) connect digital or analog external devices (input from sensors or output to actuators);
(4) single-step through program, one instruction at a time;
(5) set break points;
(6) examine microcontroller registers or memory;
(7) modify the contents of memory or registers.
EXPERIMENT 1 Run a Program
For details of the EyeBot read the blue pages of the lab notes (yellow book) or look up the 
following Web address:   http://www.ee.uwa.edu.au/~braunl/eyebot/doc
(a) Make sure the EyeBot is correctly connected to your PC.
(1)Black and red power plugs are connected to the power supply.
(2)Background debugger: right slot of the EyeBot to the parallel port of the PC.
(3)Serial interface: left slot of the EyeBot to the serial port of the PC (COM2).
(b) Login into the PC: 
type login
LOGIN: csc?? (examples: csc2 = group 2 or csc11 = group 11).
PASSWORD: secret
Password should be changed:typ  passwd
For printing text files:type lpr filename
(c) Modify and run the sample program
(1)Copy the demo program into your home area
copy  K:\robios\demo\demoasm.s  H:myprog.s
(2)Examine the program with the DOS editor
edit filename.s (example: edit myprog.s)
In the program, change the output string o include you group number.
(3)Assemble the demo program:
gas68 filename (example: gas68 myprog)
Here, do not use the extension (.s). The name gas68 stands for “gnu assembler for 68000”.
(4)Check to ensure that the download-file “hex.hex” has been generated.
This file contains a text representation of the machine code in s-record format.
(5)Download the program:
(i) On the EyeBot: press the button labeled ‘Usr’;
then select button ‘Ld’ - the EyeBot is now waiting for input from the PC;
(ii) On the PC: type transmit - this transmits file “hex.hex” from the PC
to the EyeBot.
(6)Run the program on the EyeBot by pressing button ‘Run’.
(7)Check with your lab demonstrator to ensure that you are on the right track.
Demonstrator:
_______________________
EXPERIMENT 2 Debug a Program
Consider the following example program, it comprises three parts.
Part 1 contains a loop which prints out 16 “*” characters, one character at a time.
Part 2 prints a string.
Part 3 waits for a key press.
.include “labmac.i”
.section .text
.globl main
main: MOVE.L #15, D6 | print 16 characters, loop 15..0
loop: MOVE.L #’*’, D1 | load char to be printed
CALLEXEC LCD_PutChar | call LCD print routine
DBRA D6, loop | decrement and branch until -1
MOVE.L #string, A0 | load string start address
CALLEXEC LCD_PutString | call LCD print routine
MOVE.L #ANYKEY, D1 | load code to wait for key press
CALLEXEC KEY_Wait | call KEY routine
RTS | return to operating system
string: .asciz “Hello, group xx”
(a)Start the background debugger on the PC
Since this is Motorola software, note that all hexadecimal number have prefix ‘$’ and not 
‘0x’.
bd32
stop
If the EyeBot does not stop immediately, press the ‘reset’ button on the EyeBot,
thenk type goand stop again.
Switch to window display
window on
(b) You should be able to see the following,
Top window - contents of all registers
Middle window - memory contents
Bottom window - type in commands
(c) Examine the machine code of the previously downloaded program,
dasm $20080
(d) Learn how to insert break points in your program
(1)Identify the start of the program loop (using dasm);
(2)Alternatively, you can single-step through the program by typing
s (single step, does not display subroutines) or
t (traces each command, even in subroutines)
(3)Place a break point at the loop start position by typing br $address 
(4) Continue execution by typing go
(5)Start the program by pressing the ‘Run’ button on the EyeBot 
(6)Execution should stop at the break point
(7)To continue program execution, type go 
The program should output one “*” at a time
if the break point is set at the correct position.
(8)Check with your lab demonstrator to show your results.
Demonstrator:
_______________________
EXPERIMENT 3 Design a Program
Write an assembly program to print out the colors of  button pressed. Whenever the user presses a 
button, a string denoting the color of the button should be display on the LCD. If the user presses 
the ‘GREEN’ button the program should terminate.
Please note
(a) The first lines of your program should be
.include “labmac.i” 
.section .text
.globl main 
main: ... | this is where the program starts
(b) Program termination is done by the command RTS (return from subroutine).
(c) To wait for the user to push a button use the command CALLEXEC KEY_Get
The result of KEY_Get will be in register D0.
The result values are:
YELLOW = $01
RED    = $04
BLUE   = $10
GREEN  = $40
(d) To print a string load the start address of the string in register A0, then use the
 command LCD_PutString , e.g.:
MOVE.L #mystring, %A0
CALLEXEC LCD_PutString
 Show your program to the lab demonstrator.
Demonstrator:
_______________________
The University of Western Australia
Electrical & Electronics Engineering
A/Prof. Thomas Bräunl
Computer Systems and Communications
CSC 163
Lab Assignment 3 week 6+7
EXPERIMENT 1 Temperature Control
Write an assembly program that reads a temperature sensor and switches a cooling motor on or 
off, according to the following flow chart. Possible applications are air conditioning, refridgerator 
and car radiator fan.
START
temp < desired – margin
NO
YES
read temperature
?
switch on heater
temp > desired + margin
NO
YES
?
switch off heater
Reading a temperature
Use the following routine to read an analog value from a port (assuming the sensor is connected to 
port no. 2):
MOVE.L #2, D0 | pass channel no. in D0
CALLEXEC OS_GetAD | return result in D0
The result is passed in D0 and is a value between 0 and 1023.
Switching the cooling motor off
MOVE.B #0, OutBase | switch motor off
Switching the cooling motor on
MOVE.B #1, OutBase | switch motor on
Parameters desired temperature500
margin 20
Show your program to the lab demonstrator.
Demonstrator:
_______________________
EXPERIMENT 2 Motor Control
Servos are DC motors with built-in logic. They are e.g. used in model cars, airplanes, ships. 
Servos assume a position (often in the range of 360 degrees) according to an input rectangle 
signal.
Write a program that reads an analog input value like in experiment 1 and then uses this value to 
generate a rectangle output on the digital output port. The servo should assume a position between 
its minimum and maximum position according to the analog input signal (potentiometer).
20 ms total
0.7 - 1.7ms
high
Example program part:
MOVE.B #1, OutBase | switch rectangle signal on
MOVE.L time, D0 | pass wait time in 0.1ms in D0
CALLEXEC OS_Wait01ms | wait time * 0.1 ms
MOVE.B #0, OutBase | switch rectangle signal off
Program structure:
Show your program to the lab demonstrator.
Demonstrator:
_______________________
START
read analog value
set rectangle signal
compute time from
 analog input value
call wait subroutine
set rectangle signal
high
low
The University of Western Australia
Electrical & Electronics Engineering
A/Prof. Thomas Bräunl
Computer Systems and Communications
CSC 163
Lab Assignment 4 week 8+9
EXPERIMENT 1 Reaction Test Game
START
STOP
use last hex-digit of OS count
wait for random time interval
is button pressed ? print “cheated!”
YES
NO
get current sys. timer (a)
wait for key press
get current sys.timer (b)
print message “press button”
print reaction time b–a
as random number
in hexadecimal form
Implement the given flow chart in assembly language.
To compute a random wait-time value, isolate the last hex-digit of the current OS_GetCount (0..F) 
and transform it into a value for OS_Wait to wait between 1 and 8 seconds.
For getting the system time in 1/100 s counts, use the routine:
OS_GetCount | returns number of clicks since
| system start in D0
For waiting multiples of 1/100 s, use the routine :
OS_Wait | Input: delay time in D1
| wait D1* 1/100 s
Show your program to the lab demonstrator.
Demonstrator:
_______________________
EXPERIMENT 2 Counting
Write a program that counts and prints the numbers from 1 to 5 and back again, according to the 
following rules. Print one number per second. You may use the system function
| put time t into D1, system waits t * 1/100 sec
CALLEXEC OS_Wait
EXPERIMENT 2a
(a) start with 1
(b)when the yellow button is pressed, count up to 5
(c) when the red button is pressed, count down to 1
(d) goto (b)
Show your program to the lab demonstrator.
Demonstrator:
_______________________
EXPERIMENT 2b
Like 2a, however, you have to remember, whether the red button has been pressed whil  count-
ing up (or the yellow one while counting down). In that case continue counting to the max (min) 
value and then do the second counting afterwards.
e.g.:  1 ¬ stays here until yellow key press
e.g.:  1, , 2, 3, 4, 5 ¬ stays here until red key press
e.g.:  1, , 2, 3, , 4, 5, 4, 3, 2, 1¬ stays here until yellow key press
e.g.:  1, , 2, 3, , 4, 5, 4, 3, , 2, 1¬ stays here until yellow key press
Show your program to the lab demonstrator.
Demonstrator:
_______________________
The University of Western Australia
Electrical & Electronics Engineering
A/Prof. Thomas Bräunl
Computer Systems and Communications
CSC 163
Lab Assignment 5 week 10+11
EXPERIMENT 1 Analog Input and Graphics Output 
Write an assembly program to plot the amplitude of an analog signal. For this experiment, the 
analog source will be the microphone.
For input, use the following function:
MOVE.L #MICROPHONE, %D0 | set analog channel
CALLEXEC OS_GetAD | return value in D0 (0..511)
Plot the analog signal versus time on the graphics LCD. The dimension of the LCD is 64 rows by 
128 columns. For plotting use the functions:
| put row no. (0..63) into D0, column no. (0..127) into D1
| put pixel value (0=white,1=black, 2=invert) in D2
CALLEXEC LCD_SetPixel
Maintain an array of the most recent 128 data values and start plotting data values from the left-
most column (0). When the rightmost column is reached (127), continue at the leftmost column 
(0) – but be sure to remove the column’s old pixel before you plot the new value. This will result 
in an oscilloscope-like output.
Show your program to the lab demonstrator.
Demonstrator:
_______________________
0,0
64,127
current value
EXPERIMENT 2 Switch Bounce
When a mechanical switch opens or closes, the contacts may bounce. This means that they make 
and break contact several times before they settle. Although this happens very quickly (in a few 
milliseconds), it is a long time for the microcontroller. Therefore, a bounce may cause the micro-
controller to detect that the switch has been pressed and released more times than it actually had.
For this exercise, do not use the standard key input routine, for this already performs a debounce. 
Instead, write your own routine to detect a key press.
Use the following routine to detect a key press for the yellow button. It returns 1 if the button is 
pressed and 0 if it is not pressed:
key: movem.l d1-d7,-(sp) | push registers
move.b  portf, d0 | load port
                not.b   d0 | invert, keys are low-act.
andi.b  #0x01, d0 | mask leftmost key
                movem.l (sp)+,d1-d7 | pop registers
rts | return 1 if key pressed
EXPERIMENT 2a
Use the following C program to detect key bounces:
main()
{ while(1) /* endless loop */
  { while (key() == 0) {} /* wait until button is pressed */
    while (key() == 1) {} /* wait until button is released */
    printf(“key \n”);
  }
}
In order to link several source files (a combination of C and ASM files), proceed as follows:
• compile each C-file individually,  e.g. gcc68o myc
• assemble each ASM-file individually,  e.g.gas68o myasm
• link all source files together,  e.g. gld68o myc.o myasm.o
(here you have to specify suffix “.o”)
Show your program to the lab demonstrator.
Demonstrator:
_______________________
Off Off
On On
~ 10 ms ~ 10 ms
EXPERIMENT 2b
Write a subroutine “keydebounce”, which can be called from C to detect a key press without the 
switch bounce effect. To eliminate a switch bounce effect, it is necessary to wait for a short time 
(e.g. 20 milliseconds) after the switch has been pressed before testing to see whether it has been 
released. By that time the bounce should have finished. The same procedure has to be applied for 
releasing a key. Write an empty loop, which always tests the condition (“busy wait loop”). You 
may have to experiment to find the right timing; e.g. a single DBRA loop iteration takes ~0.35µs. 
to delay execution for about 10ms. Use this new routine “keydebounce” together with the C pro-
gram shown above.
Show your program to the lab demonstrator.
Demonstrator:
_______________________
The University of Western Australia
Electrical & Electronics Engineering
A/Prof. Thomas Bräunl
Computer Systems and Communications
CSC 163
Lab Assignment 6 week 12+13
Please note:For this experiment you have the choice to program either in a combination of 
C+assembly or in assembly language only!
EXPERIMENT 1 Simple Lift
Write a program which drives the lift continuously up and down (“pater noster”).
Upon arrival at a floor, the lift should
• ring the bell
• wait 2 sec.
• ring the bell agin (as a safety measure)
before continuing to travel in the opposite direction.
Show your program to the lab demonstrator.
Demonstrator:
_______________________
Lift Interface Output: OutBase 
Lift Interface Input: InBase 
7 6 5 4 3 2 1 0
X X X ring bell top light bottom lightmotor down motor up
7 6 5 4 3 2 1 0
X X X X top positionbottom pos. top button bott. button
EXPERIMENT 2 Lift
Write the complete lift program according to the following specification.
Please note:Our lift model has only buttons on the floors outside the car. Pressing a button 
inside the lift is considerend to be equivalent to pressing the appropriate button 
outside !
(0)Initialization
• switch off all lights and bell
• drive lift to ground floor
• assume the cabin door is closed
(1)When a person presses an outside button:
• reuse the key-debounce routine from the previous lab experiment,
adapted for the lift buttons
• turn the appropriate light on
• if the lift is standing: drive the lift to the appropriate floor (if not already there)
• if the lift is moving: register the request for later (if not travelling in that direction anyway)
[reuse routine from previous up/down counting lab experiment]
• execute arrival routine (2)
(2)Upon arrival at a floor:
• ring the bell for 0.5 sec.
• turn the appropriate light off
• print message “opening door”
• wait 2 sec.
• print message “closing door”
(3)Assuming a person has entered the lift and presses an inside button:
® this is equivalent to pressing an “outside” button as in (1)
® make sure the person can also leave the lift at the same floor he/she entered
by pressing the same floor button
(this should follow automatically from rules 1 and 2)
Remarks: • a good way to start is using the up/down counter of the previous lab
• the basic program structure should a loop, constantly checking for events 
(e.g. buttons pressed or end positions reached)
• be sure not to overlook the pressing of a button while the lift is moving or 
while waiting during opening/closing of the door
• you may want to add more fancy features, e.g. using the EyeBots’ display, 
especially when programming in C
Show your program to the lab demonstrator.
Demonstrator:
_______________________