Write an assembly language code segment to insert into the main.asm file that takes an input controlled by a potentionmeter, converts that input to a digital value, and displays that value on the LEDs according to the following:

profileangelzukin
assignment_2-fall_2014.docx

Microcomputers-I

Fall 2014

Assignment

Assignment Due: December 3, 2014

ASSIGNMENT DESCRIPTION

PART 1

Write an assembly language code segment to insert into the main.asm file that takes an input controlled by a potentionmeter, converts that input to a digital value, and displays that value on the LEDs according to the following:

TABLE 8-1: LED Conditions

Value

LEDs Lit

$0000 - $3332

none

$3333 - $6665

1

$6666 - $9998

1,2

$9999 - $CCCB

1,2,3

$CCCC - $FFFF

1,2,3,4

PART 2

Modify your code by replacing “ATD0DR1” with “ATD0DR0.” Slowly move your hand over the CSM12D module to cast a shadow on the board. Observe the reaction of your display LEDs to different brightness levels.

Objectives:

(1) Study how to program in Assembly Language while using CodeWarrior and the PBMCUSLK and CSM12D modules.

(2) Practice controlling peripheral devices with a microcontroller.

BRIEF TUTORIAL ON THE DT256’S ANALOG TO DIGITAL CONVERTERS

The DT256 has a port labeled AD0 that contains 8 analog inputs. Each pin goes to its own 16-bit ADC and outputs the corresponding digital value in one of 8 registers. These registers are labeled in the format ATD0DR[X], each of which consumes two memory locations starting at $0090.

ADC 0 has six control registers to manipulate certain properties of the ADC and to add some additional flags for control. These registers are labeled ATD0CTL0 through ATD0CTL5. CTL0 and CTL1 are not used by the DT256. CTL3 and CTL4 control settings that are beyond the scope of this lab.

However, CTL2 and CTL5 contain some properties of interest. The 7th bit of CTL2 must be “1” to activate ADC0. Bit 6 of CTL5 must be “0” to operate in unsigned mode. Bit 5 of CTL5 must be 1 to make the ADC take readings constantly. Bit 4 must be “1” as well; otherwise it will only take readings from one port. Bits 2, 1 & 0 of CTL5 control how the converted values are organized to their output registers; simply set them to “1”, “0”, and “0” respectively.

Therefore, CTL2 should be set to 10000000 and CTL5 should be set to 00110100.

SUPPLEMENTAL INFORMATION

TABLE 8-2: Registers for LEDs and the Analog-to-Digital Converter

Memory Loc.

Designation

Notes

$0001

PORTB

Port B – LED Control ( 0 = ON, 1 = OFF )

b7 – LED4 b6 – LED3 b5 – LED2 b4 – LED1

$0003

DDRB

Data Direction for Port B ( 0 = input, 1 = output )

Set bits 4, 5, 6, & 7 to “1” for LED control.

$0082

ATD0CTL2

ATD 0, Control Register 2 (set to 10000000)

b7 – ADPU, ADC 0 Power-Up

$0085

ATD0CTL5

ATD 0, Control Register 5 (set to 00110100)

b6 – Signed/Unsigned Conversion Selection

b5 – SCAN, Activate Continuous Conversion

b4 – MULT, Multi-channel Sample Mode ON

b2 – CC, Input Channel Select Code C

$008F

PORTAD0

Port AD0 – 8 ADC Analog Inputs

The Pot. and Photodiode are connected to 2 of these ports.

$0090

ATD0DR0

ATD 0, Output Register 0 (16 bits)

Digital Equivalent of Photodiode Output

total darkness = FFFF

bright light = 0000

$0091

$0092

ATD0DR1

ATD 0, Output Register 1 (16 bits)

Digital Equivalent of Potentiometer Output

knob tuned clockwise = higher values

knob turned counter-clockwise = lower values

$0093

REQUIREMENTS

should include the results of the Assignment and a sufficient explanation of the coding and procedures used.

QUESTIONS FOR LAB REPORT

1. Carefully comment each line of your program (on your source codes) and explain clearly who it does.

2. What did you observe in part 2 of this lab?