MCO556 Practice Test 2

Similar documents
Asynchronous Data Transfer

A B C D E F 0480 FE B F5 3B FC F3 E 1A 1D 2A 2D 3A 3D 4A 4D 5A 5D 6A 6D 7A 7D

EE 308/MENG 483 Spring 2017

Review for Exam 3. Write 0x05 to ATD0CTL4 to set at fastest conversion speed and 10-bit conversions

Dallas Semiconductor DS1307 Real Time Clock. The DS 1307 is a real-time clock with 56 bytes of NV (nonvolatile)

EE345L Spring 2004 Final Version 3 Page 1 of 8

The modules in this lab room are 4 line by 16 character display modules. The data sheet/users manual for the module is posted on My.Seneca.

HCS12 Serial Communications Interface (SCI) Block Guide V02.06

Interrupt vectors for the 68HC912B32. The interrupt vectors for the MC9S12DP256 are located in memory from 0xFF80 to 0xFFFF.

EE Embedded Systems Design. Lessons Exceptions - Resets and Interrupts

EXCEPTIONS ON THE 9S12

Lecture 13 Serial Interfaces

CS/ECE 5780/6780: Embedded System Design

ECE/CS 5780/6780: Embedded System Design

The MC9S12 Input Capture Function

MICROCONTROLLER SYSTEM CONTROL DESIGN JON PRITCHARD SCOTT VON THUN

Interrupts. How can we synchronize with a peripheral? Polling

The MC9S12 Timer Output Compare Function Making an event happen at specific time on the HC12 The MC9S12 Output Compare Function

EE345L Fall 2008 Final Page 1 of 12

EE 308 Spring Exam 1 Feb. 27

Capturing the Time of an External Event Input Capture Subsystem

#include <hidef.h> /* common defines and macros */ #include <MC9S12XEP100.h> /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12xep100"

EE4390 Microprocessors

EE345L Spring 2006 May 10, 2006, 2-5pm Page 1 of 8

Introduction to the MC9S12 Hardware Subsystems

Objectives. Introduction

EE 308 Spring 2013 The MC9S12 A/D Converter

C Language Programming, Interrupts and Timer Hardware

The MC9S12 Timer Input Capture Function

SCI Serial Communication Interface

; export symbols XDEF Entry ; export 'Entry' symbol ABSENTRY Entry ; for assembly entry point

CS/ECE 5780/6780: Embedded System Design

EE 308 Spring A software delay

ECE/CS 5780/6780: Embedded System Design

General Features of Interrupts. ECE/CS 5780/6780: Embedded System Design. Stack Before and After an Interrupt. Sequence of Events During Interrupt

What happens when an HC12 gets in unmasked interrupt:

C Language Programming, Interrupts and Timer Hardware

; export symbols ; export 'Entry' symbol. ; include derivative specific macros PORTA EQU $0000 PORTB EQU $0001 DDRA EQU $0002 DDRB EQU $0003

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

Lab 7: Asynchronous Serial I/O

General Features of Interrupts. ECE/CS 5780/6780: Embedded System Design. Sequence of Events During Interrupt. Stack Before and After an Interrupt

Lab 8 RS232 October 22, 2015

What Happens When You Reset the MC9S12?

538 Lecture Notes Week 5

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

Using Input Capture on the 9S12

ECE3120: Computer Systems Chapter 8: Timer Module

CS/ECE 5780/6780: Embedded System Design

Introduction to Serial Communication. ECE/CS 5780/6780: Embedded System Design. A Serial Channel. Definitions. SCI versus SPI.

538 Lecture Notes Week 5

SECTION 5 RESETS AND INTERRUPTS

ECE/CS 5780/6780: Embedded System Design. Introduction to Serial Communication

Freescale Semiconductor, I

HC12 Built-In Hardware

EE 354 November 13, 2017 ARM UART Notes

Menu. XMEGA 16-bit Timer/Counter Type 0 and Type 1 EEL 3744 EEL 3744

Module 3.F. Serial Communications Interface (SCI) Tim Rogers 2017

ECE 4510/5530 Microcontroller Applications Week 9

melabs Serial LCD Firmware Version 1.1 3/5/07

ABSTRACT: Code Warrior IDE Background Debug Mode (BDM) P&E USB MULTILINK

The Freescale MC908JL16 Microcontroller

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

ECT_16B8C Block User Guide V01.06


CSE3215 Embedded Systems Laboratory

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

Lecture 15 February 20, 2012 Introduction to the MC9S12 Timer Subsystem What Happens when you Reset the MC9S12. Introduction to Interrupts

CN310 Microprocessor Systems Design

CAN Protocol Implementation

538 Lecture Notes Week 7

LCD03 - I2C/Serial LCD Technical Documentation


CMPEN 472 Sample EXAM II

Bachelor of Engineering in Computer and Electronic Engineering

School of Computer Science Faculty of Engineering and Computer Science Student ID Number. Lab Cover Page. Lab Date and Time:

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

CMS-8GP32. A Motorola MC68HC908GP32 Microcontroller Board. xiom anufacturing

EE445L Fall 2010 Final Version A Page 1 of 10

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

Comparison of C and Assembly How to compile a C program using CodeWarrior

LCD03 - I2C/Serial LCD Technical Documentation

Lab 5: EBI and ADC: Digital Voltmeter

Department of Electronics and Instrumentation Engineering Question Bank

CET360 S12 DEMO PROGRAM #1 (C)

MTRX3700 Mechatronics

Microcontroller and Embedded Systems:

LCD05 datasheet 1.0

Functional block diagram AD53x1 (Analog Devices)

How to use RFpro in Packet Mode

Lab Course Microcontroller Programming

RS 232 Interface. RS 232 is the Serial interface on the PC. Three major wires for the Serial interface: Transmit Pin 2 Receive Pin 3

EE319K Fall 2006 Final A Page 1

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1

Signature: 1. (10 points) Basic Microcontroller Concepts

Reprinted by permission of T&L Publications Inc. Copyright 2001 USB MICROCONTROLLERS FOR THE MASSES

melabs Serial LCD Firmware Version 1.0 2/7/07

Embedded programming, AVR intro

Features: Analog to Digital: 12 bit resolution TTL outputs, RS-232 tolerant inputs 4.096V reference (1mV/count) 115K max speed

Comparison of C and Assembly How to compile a C program using CodeWarrior

History of the Microprocessor. ECE/CS 5780/6780: Embedded System Design. Microcontrollers. First Microprocessors. MC9S12C32 Block Diagram

Transcription:

Question 1 : MCO556 For the program shell on the following page, fill in the blanks and add the code required to create a program which flashes LEDs. The LED flashing must be controlled from the keypad and a PC running Hyperterminal connected to the SCI. The hardware configuration is identical to the EVB board in lab A4070. The flash rate of LED2 must be approximately 1 Hz and is controlled by Timer Overflow interrupts. The flash rate of LED5 must be 0.5 Hz and is controlled by Timer Channel 1 operating in output compare mode. Timer configuration Prescale factor for clock to divide by 8 (required by keypad driver) Use Output Compare channel 1 (channel numbers start at 0) 50 Hz output square wave on Port T.1 Serial communications configuration: Use SCI0 2400 bps 8 data bits no parity 1 stop bit receive interrupts enabled LED operation The Timer Overflow interrupt will be used to create a time delay allowing the LED2 of PORTB to flash with a frequency of approximately 1 Hz (50% duty cycle). Flashing will be enabled or disabled from the keypad as described below: The Output Compare interrupt will be used to create a time delay allowing the LED5 of PORTB to flash with a frequency of 0.5 Hz (50% duty cycle). Flashing will be enabled or disabled from the Hyperterminal as described below: Start up operation On start up, LED 0, 5, and 7 must be ON and all other LEDs must be OFF. LED2 Control When a 0 is pressed on the keypad, PORTB LED2 will turn off. The remaining LEDs must not be modified. When a 1 is pressed on the keypad, PORTB LED2 will flash with a frequency of 1 Hz (50% duty cycle). The remaining LEDs must not be modified. When a 2 is pressed on the keypad, PORTB LED2 will turn on. The remaining LEDs must not be modified. LED5 Control When a 0 is pressed on the PC keyboard, PORTB LED5 will turn off. The remaining LEDs must not be modified. When a 1 is pressed on the PC keyboard, PORTB LED5 will flash with a frequency of 0.5 Hz (50% duty cycle). The remaining LEDs must not be modified. When a 2 is pressed on the PC keyboard, PORTB LED5 will turn on. The remaining LEDs must not be modified. Notes 1) Only the depression of the 0, 1 and 2 keys on the keypad and the PC keyboard must affect the operation of LED2 and LED5. All other inputs from the keypad and PC keyboard must have no effect on the operation of the program. 2) You will need separate task counters for the Output Compare and Timer Overflow interrupts. 3) Use volatile global variables to communicate between interrupts and main. 4) LEDs are numbered 0-7 with LED0 as the right-most. 5) Assume the keypad driver files have been added to the project. Remember the driver uses Timer channel 7 interupts. G VandeBelt 091-1 -

#include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> // register descriptions #include keypad.h #define PERIOD // time between output compare interrupts // with prescale = 8 void TOC1open(void); /* sets up timer 1 for output compare */ void SCIopen(void); /* sets up SCI */ // global variables as required #pragma CODE_SEG NEAR_SEG NON_BANKED /* interrupt function will cause LED5 to flash at 0.5 Hz rate */ interrupt void TOC1_isr(void) G VandeBelt 091-2 -

/* interrupt function will cause LED2 to flash at approximately 1 Hz rate */ interrupt void TOF_isr(void) /* SCI receive interrupt to control LED5 */ interrupt void SCIrx_isr(void) #pragma CODE_SEG DEFAULT G VandeBelt 091-3 -

G VandeBelt 091-4 - MCO556 void main(void) // local variables as required DDRB = ; TSCR1 = ; TSCR2 = ; // data direction register PORT B as output // enable timer // set prescale for divide by 8 with interrupt // more initialization while(1) // do forever loop

/* initialize Timer Channel 1 for Output Compare interrupt */ void TOC1open(void) TIOS = ; TCTL1 = ; TCTL2 = ; TIE = ; TFLG1 = ; TC1 = ; // sets counts to current + required delay/ /* initialize SCI for 2400 bps 8 bit, no parity, 1 stop bit and receive interrupts */ void SCIopen(void) SCI0BRL = ; SCI0BRH = ; SCI0CR2 = ; G VandeBelt 091-5 -

Question 2: MCO556 For the program in question 1, fill in the blanks for the linker file shell shown below. NAMES END SECTIONS MY_RAM = READ_WRITE 0x1000 TO 0x2FFF; MY_PSEUDO_ROM = READ_ONLY 0x3000 TO 0x3FFF; END PLACEMENT _PRESTART, STARTUP, ROM_VAR, STRINGS, NON_BANKED,DEFAULT_ROM, COPY INTO MY_PSEUDO_ROM; DEFAULT_RAM INTO MY_RAM; END STACKSIZE 0x100 // data RAM // code RAM VECTOR ADDRESS VECTOR ADDRESS VECTOR ADDRESS VECTOR ADDRESS KPisr VECTOR ADDRESS Startup // Timer Overflow vector // Timer channel 1 vector // SCI 0 vector // keypad vector // reset vector G VandeBelt 091-6 -

Question 3 : MCO556 For the program shell on the following page, fill in the blanks and add the code required to create a program which converts an analog voltage on a selected ADC channel to an 8 bit digital value. Keyboard commands from a PC running Hyperterminal specified the ADC channel. The results of the conversion are displayed on the PC screen. Also messages are displayed on the LCD module. The hardware configuration is identical to the EVB board in lab A4070. Serial communications configuration: Use SCI0 2400 bps 8 data bits no parity 1 stop bit receive interrupts enabled A to D converter configuration: Use one of ADC channels 0, 1, 2 and 3 with 4 samples per conversion cycle 10 bit resolution, unsigned result, left justified Single conversion cycle minimum sample time maximum frequency clock On start up, the LCD module must be blank. ADC operation When a 0, 1, 2 or 3 is sent from Hyperterminal to the micro, a conversion for ADC channel 0, 1, 2 or 3 will be started. Also, the message Channel n must be displayed on the first line of the LCD module where n is the channel requested. The rest of the display must be blank. When the ADC conversion sequence is complete, the four conversions for the cycle must be average, converted to ASCII and sent to the PC for display on the screen. All other keyboard characters must be ignored by the program. Notes: 1) The ADC conversion function must be called from main. 2) Every message displayed on the PC screen must be on a separate line. The message must be sent only once when a key is pressed. The messages must be sent in main. 3) Assume the LCD driver files have been added to the project. Remember the LCD uses Timer channel 6 interrupts. Hints: Use the _itoa library function to convert the 8 bit value into an ASCII string. Calling procedure _itoa(value, buffer, 10); // where buffer contains storage for the string The ASCII code for carriage return is 0x0D and the code for line feed is 0x0A G VandeBelt 091-7 -

Question 3 : Answer MCO556 #include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> // register descriptions #include <stdlib.h> #include lcd.h void SCIopen(void); void SCIputch(unsigned char Data); void SCIputs(unsigned char Str[]); void ADCopen(void); unsigned char ADCgetSample(unsigned char chan); // global variables as required #pragma CODE_SEG NEAR_SEG NON_BANKED /*serial receive interrupt function */ interrupt void SCIrx_isr(void) #pragma CODE_SEG DEFAULT void main(void) unsigned char buffer[10]; DDRB = ; TSCR1 = ; TSCR2 = ; // software initialization G VandeBelt 091-8 - // message buffer // more local variables as required // data direction register PORT B as output // enable timer // set prescale for 1 MHz clock to timer

Question 3 : Continued while(1) // do forever loop G VandeBelt 091-9 -

Question 3 : Continued MCO556 // Initialize SCI void SCIopen(void) SCI0BDL=0xD0; /* 8000000/(16*2400)=>2400 bps 8MHz is Bus clock*/ SCI0BDH=0x00; /* 0x00,0x00D0 is divisor to produce 2400 bps */ SCI0CR2= ; /* enable SCI Rx interrupts */ // Output character to SCI void SCIputch(unsigned char Data) // Output a string to the SCI // Str[] is the string to be output void SCIputs(unsigned char Str[]) // Initialize ADC void ADCopen(void) ATD0CTL2 = ; // enable ADC ATD0CTL4 = 0x03; // Get a sample from the ADC unsigned char ADCgetSample(unsigned int chan) ATD0CTL5 = ; while( ); G VandeBelt 091-10 - // start sequence // wait for conversion complete // then take average of 4 conversions return (ATD0DR0H+ATD0DR1H+ATD0DR2H+ATD0DR3H)/4;

Question 4: MCO556 A DC level is applied to ADC channel 2 (channel numbers start at 0) via the level-shifting circuit in the lab. Note that full scale input range is -10V to +10V. a)the ADC converts this to an 8 bit value of hexadecimal 0xD5. What is the input voltage? b) The input voltage is changed to 4.0 Volts, what will be the hexadecimal value read from the ADC? Question 5: SCI 0 of a HCS12 microcontroller is connected a PC running Hyperterminal. The serial communications parameters are: Serial communications configuration: Use SCI0 9600 bps 8 data bits no parity 1 stop bit receive interrupts enabled a) What hex values must be written to the Baud Rate registers and the control registers of the SCI to properly open the port? b) Using the values written to the baud rate registers, what is the actual baud rate of the communications link? (Show result to 4 digits of accuracy). G VandeBelt 091-11 -

MC9S12DP256B Timer System Registers TSCR1 TEN 0 0 0 0 0 0 0 TEN = 1 : Timer enabled TSCR2 TOI 0 0 0 0 PR2 PR1 PR0 TOI = 1 : Overflow interrupt enabled PR2-0 : Pre-scale value TCTL1 OM7 OL7 OM6 OL6 OM5 OL5 OM4 OL4 TCTL2 OM3 OL3 OM2 OL2 OM1 OL1 OM4 OL0 OMn OLn Action 0 0 No output 0 1 Toggle 1 0 Output 0 1 1 Output 1 TIOS IOS7 IOS6 IOS5 IOS4 IOS3 IOS2 IOS1 IOS0 IOSn = 1 : Output compare IOSn = 0 : Input Capture TIE C7I C6I C5I C4I C3I C2I C1I C0I CnI = 1 : Channel n interrupt enabled TFLG1 C7F C6F C5F C4F C3I C2F C1F C0F CnF = 1 : Channel n event Write a 1 to clear TCn Channel n 16 bit capture/compare register G VandeBelt 091-12 -

MC9S12DP256B ADC Registers ATD0CTL2 ADPU 0 0 0 0 0 0 0 ADPU : 0 = power down 1 = normal ATD0CTL5 ATDCTL5 DJM DSGN SCAN MULT 0 CC CB CC ADPU 0 0 0 0 0 0 0 DJM : 0 = left justified DSGN: 0 = unsigned SCAN: 0 = single sequence MULT: 0 = single channel CC CB CA: channel ATD0STAT0 SCF 0 0 0 0 0 0 0 SCF : 1 = conversion complete Cleared on write to ATD0CTL5 ATD0DRnH high byte of result data for Sample n MC9S12DP256B RTI Registers RTICTL 0 RTR6 RTR5 RTR4 RTR3 RTR2 RTR1 RTR0 RTR6-4 : RTI Pre-scale RTR3-0 : modulus (1-16) CRGINT RTIE 0 0 LOCKIE 0 0 SCMIE 0 RTIE : 1 = RTI interrupt enabled CRGFLG RTIF PORF 0 LOCKIF LOCK TRACK SCMIF SCM RTIF : 1 = RTI event G VandeBelt 091-13 -

MC9S12DP256B SCI Registers SCI0BDH 0 0 0 SBR12 SBR11 SBR10 SBR9 SBR8 SBR12 0 = CLK/(16 * BR) SCI0BDL SBR7 SBR6 SBR5 SBR4 SBR3 SBR2 SBR1 SBR0 SCI0CR2 TIE TCIE RIE ILIE TE RE RWU SBK SCI0SR1 TDRE TC RDRF IDLE OR NF FE PF TE = 1 : Transmitter enabled RE = 1 : Receiver enabled RIE = 1 : Receive interrupt enabled TDRE = 1 : Transmitter empty RDRF = 1 : Receiver full SCI0DRL Transmit and receive data register Function prototypes for LCD driver void LCDopen(void); // initialize LCD driver void LCDputs(const char *s); // output a string void LCDputch(char data); // output a character void LCDclear(void); // clear display void LCDhome(void); // move cursor to home position void LCDline1(void); // move cursor to start of line 1 void LCDline2(void); // move cursor to start of line 2 void LCDline3(void); // move cursor to start of line 3 void LCDline4(void); // move cursor to start of line 4 Function prototypes for keypad driver void KPopen(void); char KPhit(void); char KPgetch(void); void KPflush(void); // initialize keypad driver // has a new key been pressed? // wait for and get a key press // discard possible keypress G VandeBelt 091-14 -

MC9S12DP256B Interrupt Vectors G VandeBelt 091-15 -