Lecture 2
Lecture 2
Embedded Systems/Microcontroller
Laboratory
Lecture 2
Number Systems & 1st Lab
5310=5x101+3x100
11012=1x23+1x22+0x21+1x20
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.
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
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
10
PORTB LED Connection
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