Aes Lab Manual
Aes Lab Manual
SWITC
HING
LED(s)
2016-17
AES Lab(HCS12)
Learning Objectives:
This module will help in understanding how to Blink LED’s of MC9S12HY64
microcontroller board along with writing a delay program
Success Criteria:
When you complete this module, you will be able to write a code to blink LED’s of
MC9S12HY64 microcontroller board
Requirements:
Code warrior installed basic knowledge of C and MC9S12HY64 board.
LED 1 PTR_PTR0
LED 2 PTR_PTR1
LED 3 PTR_PTR2
LED 4 PTR_PTR3
2016-17
AES Lab(HCS12)
Experiment 1
Aim: Switching the LED ON and OFF One Time
Program:
#include <hidef.h>
#include "derivative.h"
void main(void)
{
int x,y;
PTR=0X00; // Port R is ON
for(x=0;x<1000;x++)
for(y=0;y<1000;y++); // Delay
for(x=0;x<1000;x++)
for(y=0;y<1000;y++); // Delay
PTR=0X00; // Port R is ON
}
2016-17
AES Lab(HCS12)
Experiment 2
Aim: Switching the LED ON and OFF Infinitely
Program:
#include <hidef.h>
#include "derivative.h"
void main(void)
int x,y;
PTR=0X00; // Port R is ON
while(1)
for(x=0;x<1000;x++)
for(y=0;y<1000;y++); // Delay
for(x=0;x<1000;x++)
for(y=0;y<1000;y++); // Delay
PTR=0X00; // Port R is ON
Experiment 3
2016-17
AES Lab(HCS12)
Program:
#include <hidef.h>
#include "derivative.h"
void main(void)
int i,x,y;
for(x=0;x<1000;x++)
for(y=0;y<1000;y++); // Delay
for(x=0;x<1000;x++)
for(y=0;y<1000;y++); // Delay
PTR=0X00; // Port R is ON
2016-17
AES Lab(HCS12)
SWITCH
INTERFACING
Overview:
2016-17
AES Lab(HCS12)
Learning Objectives:
This module will help in understanding how to turn ON the digital LED’s using analog
switches by configuring ports for switches and LED’s along with enabling the pull-up
registers and enabling Analog to Digital Input register
Success Criteria:
When you complete this module, you will be able to write a code to control LED’s of
MC9S12HY64 microcontroller board with the switches present on it
Requirements:
Code warrior installed basic knowledge of C and MC9S12HY64 board.
SWITCH 1 PT1AD_PT1AD4
SWITCH 2 PT1AD_PT1AD5
SWITCH 3 PT1AD_PT1AD6
SWITCH 4 PT1AD_PT1AD7
Experiment 1
2016-17
AES Lab(HCS12)
Program:
}
}
Experiment 2
Aim: Switching the LED using input from Switches Using Macros
Program:
if(sw3==0)
{
LED=0x0B;
}
if(sw4==0)
{
LED=0x07;
}
}
}
Experiment 3
2016-17
AES Lab(HCS12)
Program:
2016-17
AES Lab(HCS12)
Experiment 4
Aim: Switching the LED to make a Pattern using SWITCH
Program:
2016-17
AES Lab(HCS12)
for(y=0;y<1000;y++);
LED=0x0B;
for(x=0;x<1000;x++)
for(y=0;y<1000;y++);
LED=0x07;
for(x=0;x<1000;x++)
for(y=0;y<1000;y++);
}
else
LED=0xFF;
}
}
2016-17
AES Lab(HCS12)
ANALOG TO
DIGITAL
CONVERSION
Overview:
2016-17
AES Lab(HCS12)
Learning Objectives:
This module will help in understanding how to implement Analog to Digital Conversion by
taking POT as analog input and converting it to digital data using ADC module of HCS12
and seeing the digital output on LEDs by initializing the registers of ADC module
Success Criteria:
When you complete this module, you will be able to write a code to convert analog data to
digital using MC9S12HY64 microcontroller board
Requirements:
Code warrior installed basic knowledge of C and MC9S12HY64board.
Experiment 1
2016-17
AES Lab(HCS12)
Aim: Switching the LED Depending on the Analog Input from POT
Program:
Experiment 2
Program:
2016-17
AES Lab(HCS12)
LED=0x0B;
for(x=0;x<1000;x++)
for(y=0;y<1000;y++);
LED=0x07;
for(x=0;x<1000;x++)
for(y=0;y<1000;y++); // Next two LED’s ON for this range
}
}
}
2016-17
AES Lab(HCS12)
SERIAL
COMMUNICATION
INTERFACE
Overview
The need to exchange data between the MCU and peripheral devices can be satisfied by using
parallel data transfer (multiple bits in one transfer operation). However, there are a few
drawbacks. The serial communication interface (SCI) was designed to transfer data in an
asynchronous mode
2016-17
AES Lab(HCS12)
Learning Objectives
This module will help in understanding how to communicate between two or more
microcontrollers or between a microcontroller and desktop using SCI protocol
Success Criteria
When you complete this module, you will be able to use the SCI port of HCS12 to connect to
another microcontroller or to a desktop PC with a COM port.
Requirements
Code warrior installed basic knowledge of C and MC9S12HY64 board.
Theory of operation:
Experiment 1
Aim: Sending a String from HCS 12 to PC and Display in the Terminal
Program:
2016-17
AES Lab(HCS12)
Experiment 2
2016-17
AES Lab(HCS12)
Program:
Experiment 3
Aim: Sending ‘HI’ from HCS 12 to PC and Display ‘BYE’ in the Terminal
Program:
2016-17
AES Lab(HCS12)
2016-17
AES Lab(HCS12)
SCICR2=0X0C;
SCIBDH=0X00;
SCIBDL=0X34;
DDRR= 0x0F;
PTR = 0x0F;
}
char rec( )
{
char a;
while(SCISR1_RDRF == 0);
a= SCIDRL;
return (a);
}
void send(char c)
{
while(SCISR1_TDRE == 0);
SCIDRL = c;
}
Experiment 4
2016-17
AES Lab(HCS12)
2016-17
AES Lab(HCS12)
void init()
{
DDRS=0XFF;
DDR1AD=0xFF;
PER1AD=0xFF;
SCICR1=0X04;
SCICR2=0X0C;
SCIBDH=0X00;
SCIBDL=0X34;
DDRR= 0x0F;
PTR = 0x0F;
}
char rec( )
{
char a;
while(SCISR1_RDRF == 0);
a= SCIDRL;
return (a);
}
void send(char c)
{
while(SCISR1_TDRE == 0);
SCIDRL = c;
}
2016-17
AES Lab(HCS12)
TIMERS
Overview
At the heart of the HCS12 timer system is the 16-bit timer counter (TCNT). This counter can
be started or stopped, as you like. One of the timer functions is called input-capture. The
input-capture function copies the contents of the 16-bit timer to a latch when the specified
event arrives. Another timer function is called output-compare. The output-compare function
is often used to generate a time delay, trigger an action at some future time, and generate a
digital waveform. The third timer function is the pulse accumulator. This circuit is often used
to count the events arriving in a certain interval or measure the frequency of an unknown
signal.
2016-17
AES Lab(HCS12)
Learning Objectives
This module will help in understanding how to implement a timer by initializing the registers
of Timer Module
Success Criteria
When you complete this module, you will be able to initialize registers of timer module to
implement it
Requirements
Code warrior installed basic knowledge of C and MC9S12HY64 board.
Timer Module:
2016-17
AES Lab(HCS12)
Experiment 1
Program:
2016-17
AES Lab(HCS12)
2016-17
AES Lab(HCS12)
2016-17
AES Lab(HCS12)
PWM and
CONTROLLING the
SPEED of MOTOR
Overview:
There are many applications that require the generation of digital waveforms. The output-
compare function has been used to generate digital waveforms with any duty cycle. However,
the generation of waveforms using the output-compare function requires frequent attention
from the MCU. Most microcontrollers designed in the last few years have incorporated the
Pulse-Width Modulation (PWM) function to simplify the task of waveform generation
2016-17
AES Lab(HCS12)
Learning Objectives:
This module will help in understanding basic concepts of Period and Duty-Cycle so as to
generate PWM signals
Success Criteria:
When you complete this module, you will be able to write a code to generate PWM signals of
required period and duty-cycle from MC9S12HY64 microcontroller board
Requirements:
Code warrior installed basic knowledge of C and MC9S12HY64 board.
Block Diagram:
2016-17
AES Lab(HCS12)
Experiment 1
Aim: Control the Intensity of the LED/ Speed of MOTOR using FOR Loop
Delay
Program:
2016-17
AES Lab(HCS12)
#include <hidef.h>
#include <mc9s12hy64.h>
#include "derivative.h"
void delay(int);
void main(void)
{
int i;
PTPRRL=0x0F;
PWMCAE=0X01;
PWMPOL=0X00;
PWMCLK=0x01;
PWMSCLA=0x01;
PWMPRCLK=0x00;
PWMPER0=0xFA;
PWME=0x0F;
while(1)
{
for(i=0;i<=250;i++)
{
PWMDTY0=i;
delay(50);
}
for(i=250;i>=0;i--)
{
PWMDTY0=i;
delay(50);
}
}
}
void delay(int a)
2016-17
AES Lab(HCS12)
{
int i,j;
for(i=0;i<a;i++)
{
for(j=0;j<1000;j++);
}
}
Experiment 2
Program:
2016-17
AES Lab(HCS12)
#include <hidef.h>
#include <mc9s12hy64.h>
#include "derivative.h"
#define SW1 PT1AD_PT1AD4
#define SW2 PT1AD_PT1AD5
void delay(int);
void main(void)
{
int i;
PTPRRL=0x0F;
PWMCAE=0X01;
PWMPOL=0X00;
PWMCLK=0x01;
PWMSCLA=0x01;
PWMPRCLK=0x00;
PWMPER0=0xFA;
DDRR=0xFF;
DDR1AD=0x00;
ATDDIENL=0xF0;
PER1AD=0xF0;
PTR=0xFF;
PWME=0x0F;
while(1)
{
if(SW1==0 )
{
PTR_PTR1=1;
PWMDTY0=100;
delay(50);
}
2016-17
AES Lab(HCS12)
else if(SW2==0 )
{
PTR_PTR3=1;
PWMDTY0=150;
delay(50);
}
else
{
PTR_PTR2=0;
PWMDTY0=50;
delay(50);
}
}
}
void delay(int a)
{
int i,j;
for(i=0;i<a;i++)
{
for(j=0;j<1000;j++);
}
}
2016-17
AES Lab(HCS12)
SERIAL PERIPHERAL
INTERFACE
Overview
The serial peripheral interface (SPI) allows the HCS12 to communicate synchronously with
peripheral devices and other microcontrollers. The SPI system in the HCS12 can operate as a
master or as a slave. When the SPI module is configured as a master, it is responsible for
generating the clock signal (SCK) during an SPI data transfer. The SPI subsystem is mainly
used in interfacing with peripherals such as TTL shift registers, LED/LCD display drivers,
phase locked-loop (PLL) chips, memory components with serial interface, or A/D and D/A
converter chips that do not need a very high data rate
Learning Objectives
2016-17
AES Lab(HCS12)
This module will help in understanding how to send and receive characters using SPI
protocol
Success Criteria
When you complete this module, you will be able to write a code to communicate using SPI
protocol
Requirements
Code warrior installed basic knowledge of C and MC9S12HY64 board.
Block Diagram:
2016-17
AES Lab(HCS12)
Experiment 1
2016-17
AES Lab(HCS12)
Experiment 2
Aim: Receive a single character from Terminal and Display on LED(s).
Program:
#include <hidef.h>
#include "derivative.h"
2016-17
AES Lab(HCS12)
2016-17