Sie sind auf Seite 1von 5

Middle East Technical University

Computer Engineering Department

Ceng336
Spring 2016

(Individual) Take Home Exam-Warm-Up


Revision 1.0
Due: Friday, Mar 18, 2015, 23:55:50hrs
Submission: via COW
The purpose of this assignment is to familiarize you with basic input/output operations on
MPLAB X IDE simulation environment.
Any clarifications and revisions to the assignment will be posted to the metu.ceng.course.336
newsgroup.
This is not an group exam, you must solve individually.
Your mission is to implement the below scenario on the MCDEV boards by using the MPLAB X
IDE simulation environment. Detailed specifications of the task are as follows:
Scenario
You have 4 LEDs that shows numbers in binary form. When you press and release a button, your
program will start and count from '0' to '10' in decimal. Meanwhile, binary equivalents of these
numbers will be shown on the LEDs. Your program should have two states; State1 and State2. In
State1, your program should have an approximately 500 ms delay between displaying of two
numbers. However, in State2, the delay between two representations should be approximately 1200
ms. Changing of states from State1 to State2 or vice versa, depends on toggling of another button.
Specifications
You will use 3 ports in this assignment: PORTA, PORTC, and PORTD. To start the program, you
will use the push button that is connected to 4th bit of the PORTA (RA4). You will use RA4 pin as
a digital input, please look at the section Hints. PORTC will be used for the button that changes
the states (RC1). PORTD will be used for output; LEDs that are connected to RD0, RD1, RD2, and
RD3, are used for displaying the numbers. While RD0 represents the least significant bit of the
number, RD3 corresponds with the most significant bit.
The default state of the program is State1. When the program starts, the default value of counter
(decimal 0) will shown on the LEDs. Then with 500 ms intervals, the program will count up to
decimal 10. After displaying 10, the counter will be cleared. At this point, the program should wait
to push and release RC1. When you toggle the button, the state will change to State2 and numbers
will be displayed up to 10 with 1200 ms intervals. RC1 changes the states in this way. State changes
occur only when program listen the RC1 button. In other words, the state should not change when
the program displaying the numbers.
The naming of pins are generally "R"+"PORT NAME"+"BIT ORDER". R represents PORT. Here,
ports names are A, B, C, and D. And the range of the BIT ORDER is between 0 and 7.

Implementation
You are expected to simulate the above scenario in the MPLAB X IDE simulator. You can track
the status of the LEDs, by using RD0..RD3, RC1, and RA4 pins of the simulator. The output of the
pins can be seen by using the I/O pins menu which is available under the Window --> Simulator
menu. A screen shot from the I/O pins menu of the simulator is given in Figures 1,2 and 3. Here, the
states of the all pins that are representing the LEDs can be seen in different steps. You can simulate
the push button by using the Stimulus menu. This feature is available under the Window -->
Simulator menu. You can control with changing the state of the button as High or Low by clicking
the RA4 and RC1 pin button which is can be seen in Figure 4. You can add the pin corresponded
with push button by using the I/O pins menu to follow the changes on this pin.
Coding Rules:

You will code your program using PIC assembly language.

Your program should be written for PIC18F8722 working at 40 MHz.

When the push button is pressed, then RA4/RC1 pin goes high, and when we release the push
button, the RA4/RC1 pin goes low.

When you are writing your codes, please consider the input/output Lecture notes (Week 3) and
Recitation02 documents. In particular, you are expected to apply the round robin approach to
your code so your program will execute in an infinite loop, and there will be your own tasks
for your states in this loop at the main scope.

Time delay (intervals) will be coded by counting the number of instructions.

Hand In Instructions

You should submit your code as a single file named as the_warmup_##.asm through COW
where ## represents your student number. Do not forget replace ## with your student number.

Hints
You can use Stopwatch tool of the simulator in MPLAB X IDE to measure the time spent by a
code segment. You can reach this tool from Windows -> Debugging -> Stopwatch
menu. But, before starting simulator you have to configure your clock speed to 10 MHz from
Project properties -> Simulator -> Instruction Frequency (Since
40 MHz main clock frequency is divided by 4 inside microcontroller and one instruction cycle
is equal to 4 cycle of 40 MHz clock signal, you are setting Instruction Frequency to 10 MHz).
You can reach the project properties by right clicking to the project name in the left side
Projects panel and selecting properties. By putting breakpoints on the lines between which
you want to measure the amount of time spent by that code segment and running the code
between these two breakpoints, you can see the time spent in stopwatch window.

You will use RA4 pin as a digital input by configuring a special register, please check the data
sheet for this configuration.

You can also see the states of your ports, variables and pins by using the logical analyzer, SFR
and variables menu under the window menu.

Grading
Your codes will be evaluated on the MCDEV boards, and MPLAB X Simulation (if necessary).
However, If you obey the specified rules, your codes directly can be executed on the boards without
any problem.

Figure 1: The state of the RA4 after pressing.

Figure 2: The state of the LEDs when the number is zero.

Figure 3: The state of the LEDs when the number is ten.

Figure 4: The controlling of the push buttons by using the Stimulus Menu

Resources

PIC 18F8722 Datasheet

Course web page (recitation documents) and newsgroup

The MPLAB X IDE v.3.26 will be used. You can download by using the following link:

http://www.microchip.com/pagehandler/en-us/family/mplabx/home.html

Das könnte Ihnen auch gefallen