0% found this document useful (0 votes)
39 views

Lecture 2

This document discusses a lecture for an embedded systems course that covers number systems, converting between binary, decimal, and hexadecimal representations, and an introduction to the first lab. The lab involves running a simple "Hello World" C program to test the microcontroller setup, using ports to turn on individual LEDs, using a port to read from a keypad, and sequentially turning on LEDs in response to keypad presses. Hardware details about the MC9S12C128 microcontroller including pin assignments and logic levels are also provided. Code snippets are given as examples for connecting an LED to a port, reading a keypress, and polling a port to detect input.

Uploaded by

cecilio barría
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Lecture 2

This document discusses a lecture for an embedded systems course that covers number systems, converting between binary, decimal, and hexadecimal representations, and an introduction to the first lab. The lab involves running a simple "Hello World" C program to test the microcontroller setup, using ports to turn on individual LEDs, using a port to read from a keypad, and sequentially turning on LEDs in response to keypad presses. Hardware details about the MC9S12C128 microcontroller including pin assignments and logic levels are also provided. Code snippets are given as examples for connecting an LED to a port, reading a keypress, and polling a port to detect input.

Uploaded by

cecilio barría
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

ESE 350

Embedded Systems/Microcontroller
Laboratory

Lecture 2
Number Systems & 1st Lab

Professor Rahul Mangharam


Electrical and Systems Engineering
University of Pennsylvania
Number Systems
Decimal digits {0,1,2,3,4,5,6,7,8,9} with each digit position a power of 10:

5310=5x101+3x100

Binary digits (bits) {0,1} with each digit position a power of 2:

11012=1x23+1x22+0x21+1x20

Hexadecimal digits {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} with each digit


position a power of 16:

1FEC16=1x163+Fx162+Ex161+Cx160

Where hex digits A=1010, B=11 10, C=1210, D=1310, E=1410, F=1510 2
Bits to Decimal & Hex Digits
Binary to Decimal:
11012=1x23+1x22+0x21+1x20=8+4+0+1=1310
Binary to Hexadecimal: group every four bits for each hex digit
11011001

D 9

A group of 8 bits is 1 byte. With 8-bit data and 16-bit address in the
MC9S12C128 microcontroller, we have 1 byte data and 2 byte
address. Data and address are normally given in hexadecimal digits.

Examples: $D9 (Assembly), 0xD9 (C Language)


3
Bits to
Decimal &
Hex Digits
Table

4
Lab 1 Introduction
There are 4 parts.
1. Download & run a simple C program (hello.c) to check
setup & communication with microcontroller board.
2. Use PORTB to turn on a specific LED.
3. Use PORTA to recognize a keypad input.
4. Use PORTA and PORTB to turn on/off sequentially 4 LEDs
in response to presses from a keypad input.

5
HELLO.C
//This is a comment. Comments start with two forward slashes
//and are not interpreted as code
#include <hidef.h> //These are preprocessors
#include <MC9S12C128.h> //They contain global definitions
#include "termio.h“ //that connect our code to the
#include "stdio.h“ //microcontroller

void main(void) //a function called main with no arguments


{ //all main code is contained in {}
TERMIO_Init(); //Initialize the board for input/output
EnableInterrupts; //Enable all interrupts.

printf("Hello,World!\n"); //displays text


for(;;) {} //an infinite loop, program lasts forever
} //end of main function

6
HELLO.C and the MC9S12C128
Follow the online tutorials to take your code and turn it into a working
project.

7
Pin Assignments
•Insert pin assignment diagram here

8
Logic Levels
•Insert pin assignment diagram here

9
Hardware Overview
•MC9S12C128 uses a single power supply with VDD = 5V and
VSS = GND (0V)
•Threshold between levels is set by noise margins

State Logic Level Signal (V) Threshold


(V)
0 LOW 0 <2
1 HIGH 5 >3

10
PORTB LED Connection

VR=IR & ID=ISe(Vd/Vt)

Increasing current through


resistor R increases its voltage
drop which reduces the
available voltage drop across
the diode D and therefore
reduces its current
What happens to an LED connected to PORTB and
GND without a resistor?
11
Keypad Input

Pressing Key “1” down


connects (shorts) pins 3 and 8
together…

12
Output Using PORTB
/* Include preprocessors here */
/* This is also a comment bookended by the observed characters */

main()
{
PORTB=0x08; /*0x08=B3 */
}

13
Polling to Detect Input
/* Include preprocessors here */
/* This is also a comment bookended by the observed characters */

main()
{
while(1)
{
if(PORTA & 0x04)
/* Insert detection code here */
}
}

14

You might also like