0% found this document useful (0 votes)
20 views17 pages

ESL Expt. 2

The document outlines various experiments using the HCS12 Freescale Application module, including activating LEDs with push buttons and DIP switches, implementing a 4-bit counter, and counting leading ones. Each experiment includes aims, software and hardware requirements, program code, flowcharts, and results. The overall goal is to demonstrate the functionality of the application module through practical coding exercises.

Uploaded by

Nandhini P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views17 pages

ESL Expt. 2

The document outlines various experiments using the HCS12 Freescale Application module, including activating LEDs with push buttons and DIP switches, implementing a 4-bit counter, and counting leading ones. Each experiment includes aims, software and hardware requirements, program code, flowcharts, and results. The overall goal is to demonstrate the functionality of the application module through practical coding exercises.

Uploaded by

Nandhini P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Ex.No.

2a Date:
Activation of LEDs using Push Button Switches
Aim :
To glow LED1 and LED2 when Pushbutton Switch1 is pressed and to glow LED3 and
LED4 when Pushbutton Switch2 is pressed using HCS12 Freescale Application module.

Software Requirement:
i) Freescale code warrior development Studio version 5.0

Hardware Requirement:
i) Personal Computer
ii) MC9S12 Freescale Application Module
iii) Interface card
iv) Project Board PBMCUSLK

Program:

# include <hidef.h>
# include “derivative.h”
void delay(void);
void main(void){
DDRP = 0x00;
DDRB = 0xFF;
for(;;){
if(((PTP & 0x01) == 0) && ((PTP & 0x02)!=0)){
PORTB = 0xCF;
delay();
}
if(((PTP & 0x01) != 0) && ((PTP & 0x02) ==0)){
PORTB = 0x3F;
delay();
}
}
}
void delay(void){
int i,j;
for(i=1; i<100 ; i++){
for(j=1 ; j<100 ; j++){
}
}
}

2-1
FLOWCHART:

START

Infinite
for loop DELAY

Declare i
Declare and j
PORTB as
output

For i = 1
Declare
to100
PORTP as
input

if PTP&0x01==0 For j = 1
and to100
PTP&0x02 != 0

Make pin 4 and 5 of


PORTB as 0 END

if PTP&0x01!=0 Make pin 6 and 7 of


and PORTB as 0
PTP&0x02 == 0

END
2-2
RESULT:
Thus, the activation of LED’s using Push buttons was performed using freescale
application module.

2-3
FLOWCHART:

START

Infinite
for loop

Declare PORTB upper 4 pins as


output and lower 4 pins as input

if pin 0 of
PORTB is 0 and all other
pins are 1’s

PORTB = 0x7F

If pin 1 of
PORTB is 0 and all other
pins are 1’s

PORTB = 0xBF

2-4
Ex.No.2b Date:
Activation of LEDs using DIP Switches

Aim :
To glow LED1, LED2, LED3 and LED4 when DIP Switch1, DIPSwitch2, DIPSwitch3
and DIP Switch4 is pressed accordingly using HCS12 Freescale Application module.

Software Requirement:
i) Freescale code warrior development Studio version 5.0

Hardware Requirement:
i) Personal Computer
ii) MC9S12 Freescale Application Module
iii) Interface card
iv) Project Board PBMCUSLK

Program:

# include <hidef.h>
# include “derivative.h”

void main(void){
DDRB = 0xF0;
for(;;){
if(((PORTB & 0x01)= =0)&&(( PORTB & 0x02)!=0)&&(( PORTB & 0x04)!=0) &&(( PORTB
& 0x08)!=0)){PORTB = 0x7F;
}
if(((PORTB & 0x01)!=0)&&(( PORTB & 0x02)= =0)&&(( PORTB & 0x04)!=0) &&(( PORTB
& 0x08)!=0)){PORTB = 0xBF;
}
if(((PORTB & 0x01)!=0)&&(( PORTB & 0x02)!=0)&&(( PORTB & 0x04)= =0) &&( PORTB &
0x08)!=0)){PORTB = 0xDF;
}
if(((PORTB & 0x01)!=0)&&(( PORTB & 0x02)!=0)&&(( PORTB & 0x04)!=0) &&(( PORTB &
0x08)= =0)){PORTB = 0xEF;
}
}
}

2-5
If pin 2 of
PORTB is 0 and all other
pins are 1’s

PORTB = 0xDF

If pin 3 of
PORTB is 0 and all other
pins are 1’s

PORTB = 0xEF

END

2-6
RESULT:
Thus, the activation of LED’s using DIP Switches was performed using freescale
application module.

2-7
2-8
Ex.No.2c Date:
Realization of 4-bit Counter

Aim :
To implement a 4-bit counter and to display the count value on LEDs using HCS12
Freescale Application module.

Software Requirement:
i) Freescale code warrior development Studio version 5.0

Hardware Requirement:
i) Personal Computer
ii) MC9S12 Freescale Application Module
iii) Interface card
iv) Project Board PBMCUSLK

Program:
# include <hidef.h>
# include “derivative.h”

void delay(void);
unsigned char count = 0xFF;
void main(void){
for(;;){
int x;
DDRB = 0xFF;
for(x = 0 ; x <= 15; x++){
count = count – 0x01;
PORTB = count;
delay();
}
}
}

void delay(void){
int i,j;
for(i=1; i<100 ; i++){
for(j=1; j<1000 ; j++){
}
}
}

2-9
FLOWCHART:

START

Infinite
for loop DELAY

Declare i
Declare and j
variable x and
count

Declare upper 4 bits of For i = 1


PORTB as output to100

For
x = 0 to 15
For j = 1
to 100

count = count – 0x01

END
PORTB = count

END

2-10
RESULT:
Thus, the 4 bit counter was implemented and it displayed the count value on
LED’s using HCS12 freescale application module.

2-11
FLOWCHART:

START

Infinite
for loop

Declare PORTB as output

and x = 0x25

if pin 7 of
x is 1

PORTB = 0xFF

DELAY

If pin 6 of
x is 1

PORTB = 0xEF

DELAY

2-12
Ex.No.2d Date:
Leading Ones Detector

Aim :

To count the leading number of 1’s (Indicates the position of first 1 from MSB) and to
display the position value on LEDs using HCS12 Freescale Application Module.

Software Requirement:
i) Freescale code warrior development Studio version 5.0

Hardware Requirement:
ii) Personal Computer
iii) MC9S12 Freescale Application Module
iv) Interface card
v) Project Board PBMCUSLK

Program:
# include <hidef.h>
# include “derivative.h”
char x;
void delay(void);
void main(void){
x = 0x25;
DDRB = 0xFF;
for(;;){
if ((x & 0x80) != 0){
PORTB = 0xFF;
delay();
}
if ((x& 0x40) != 0){
PORTB = 0xEF;
delay();
}
if ((x & 0x20) != 0){
PORTB = 0xDF;
delay();
}
if ((x & 0x10) != 0){
PORTB = 0xCF;
delay();
}

2-13
If pin 5 of
x is 1

PORTB = 0xDF

DELAY

If pin 4 of
x is 1

PORTB = 0xCF

DELAY

If pin 3 of
x is 1

PORTB = 0xBF

DELAY

If pin 2 of
x is 1

PORTB = 0xBF

DELAY

2-14
if ((x & 0x08) != 0){
PORTB = 0xBF;
delay();
}
if ((x & 0x04) != 0){
PORTB = 0xAF;
delay();
}
if ((x & 0x02) != 0){
PORTB = 0x9F;
delay();
}
if ((x & 0x01) != 0){
PORTB = 0x8F;
delay();
}
else{
PORTB = 0x00;
delay();
}
}
}
void delay(void){
int i,j;
for(i=1; i<100 ; i++){
for(j=1 ; j<100 ; j++){
}
}
}

2-15
If pin 1 of DELAY
x is 1

PORTB = 0x9F Declare i and j

If pin 0 of
x is 1
For i = 1
to 100

PORTB = 0x8F

else
For j = 1
to 100

PORTB = 0x00

END
END

2-16
RESULT:
Thus, the leading number of ones was counted and it displayed the position value
on LED’s using freescale application module.

2-17

You might also like