Lab 1. A Digital Lock Preparation: Figure 1.1. Texas Io Window Showing The Door Is Unlocked
Lab 1. A Digital Lock Preparation: Figure 1.1. Texas Io Window Showing The Door Is Unlocked
System Requirements
The specific device you will create is a digital lock with two binary switch inputs and one LED output. The LED
output represents the lock, and the operator will toggle the switches in order to unlock the door. Let T be the Boolean
variable representing the lock (0 means LED is off and door is locked, 1 means LED is on and door is unlocked). Let H and
P be Boolean variables representing the state of the two switches (0 means the switch is not pressed, and 1 means the switch
is pressed). The specific function you will implement is
T=P&H
This means the LED will be on if and only if the P switch is pressed and the H switch is not pressed, as shown in Figure 1.1.
Procedure
The basic approach to this lab will be to first develop and debug your system using the simulator.
Part a) Use the TExaS simulator to create three files. Lab1.rtf will contain the assembly source code. Lab1.uc will
contain the microcomputer configuration. Lab1.io will define the external connections, which should be the two switches
and one LED as shown in Figure 1.1. In this class, we will use the 9S12DP512 microcomputer, which you can specify using
the Mode->Processor command. You should connect switches to PP1 (means Port P bit 1) and to PH1 (means Port H bit 1).
You should connect an LED to PT1 (means Port T bit 1). The switches should be labeled H and P, and the LED should be
labeled T. When H switch is “off” or open position, the signal at PH1 will be 0V, which is a logic “0”. For this situation,
your software will consider H to be false. When the H switch is “on” or closed position, the signal at PH1 will be +5V, which
is a logic “1”. In this case, your software will consider H to be true. The P switch, which is connected to PP1, will operate in
a similar fashion. When your software writes a “1” to PT1, the LED will turn on. Figure 1.1 shows the condition with the
LED is on because P is pressed and H is not pressed.
void main(void){
DDRH = 0x00; // make Port H an input, PH1 is H
DDRP = 0x00; // make Port P an input, PP1 is P
DDRT = 0xFF; // make Port T an output, PT1 is T
while(1){
PTT = (~PTH)&PTP; // LED on iff PH1=0 and PP1=1
}
}
Program 1.1. This C program specifies the operations your assembly program should perform in Lab 1.
[email protected] 3/9/2010
Page 6 Introduction to Embedded Systems: Interfacing to the Freescale 9S12
Part b) You will write assembly code that inputs from PH1 and PP1, and outputs to PT1. Program 1.1 describes the software
algorithm in C. Notice that this algorithm affects all bits in a port, although only one bit is used. In general, this will be
unacceptable, and we will learn later how to write code that affects one bit at a time. You can copy and paste the address
definitions for ports H, P, and T from the port12.rtf file. In particular, you will need to define DDRH DDRP DDRT PTH
PTP and PTT. The structure of assembly programs in this class is shown as Program 1.2. The opening comments include:
file name, overall objectives, hardware connections, specific functions, author name, TA, and date. The equ pseudo-op is
used to define port addresses. Global variables are declared in RAM, and the main program is placed in EEPROM. The 16-
bit contents at $FFFE and $FFFF define where the computer will begin execution after a power is turned on or after the reset
button is pressed. This template, shown in Program 1.2, can be found in most example programs for the 9S12DP512.
Demonstration
During the demonstration, you will be asked to run your program to verify proper operation. You should be able to
single step your program and explain what your program is doing and why. You need to know how to set and clear
breakpoints. You will be asked to look up the meaning of commands like Mode->FollowPC using the on-line help. Be
prepared to make changes to Lab1.io, such as changing the names and colors of the switches and LEDs.
Deliverables
1) Assembly listing of your final program
2) One screen shot of the UC and IO windows, showing PTT PTP and PTH in the lab1.uc window and showing
the case with the LED on.
03/09/10