You are on page 1of 18

BLINKING LEDs

AIM:
To switch ON and OFF the LEDs in the freescale MC9S12 application
module with delay.
SOFTWARE REQUIRED:
Freescale Code Warrior Development Studio Version 5.0
HARDWARE REQUIREMENTS:
 Personal Computer.
 MC9SXDT512 Freescale application module
 USB Interface cable
 PBMCUSLK Project board
DESCRIPTION:
This experiment is designed to familiarize the hardware and software
development environment and I/O interfacing. The freescale MS9SXDT512
module has four on board light emitting diodes which are interfaced on the basis of
memory mapped I/O to the address of Port B. The higher order nibble of Port B is
configured with these light emitting diodes. To turn ON a particular LED
connected to Port B, first the Port B is configured as output port using the data
direction register instruction. Then the particular LED is given a binary value of to
turn it ON or OFF. To turn all the LEDs, a hexadecimal value of 0xF0 to the
address of Port B using the PORTB instruction.
ALGORITHM:
1. Start
2. Port B is configured as output port by setting bits of its Data Direction
Register to 1.
3. To turn ON the LED, assign 0x00 to Port B.
4. To turn OFF the LED, assign 0xFF to Port B.
5. Call Delay function, between LED ON and OFF to make visible blinking of
LED.
PROGRAM CODE:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "math.h"
void delay_ms(int n)
{ int i,j;
for(i=0;i<n;i++)
{ for(j=0;j<400;j++)
{ }
}
}
void main(void)
{ DDRB = 0xFF;
PORTB = 0xFF;
for(;;)
{ PORTB = 0x00;
delay_ms(1);
PORTB = 0xFF;
delay_ms(1);
}
}
PROCEDURE:
1. The program code is typed in the main.c file of the code warrior studio.
2. Then the program code is saved.
3. The free scale MC9SXDT512 development board is connected to the PC by
means of USB to serial port converter cable.
4. The program code is compiled and debugged using the code warrior studio
debugger.
5. Then the run button is pressed in the code warrior studio for running the
code in the development board.
6. The output of the code is verified by means of the output in the development
board.

RESULT:
Thus, the LEDs were switched ON and OFF with delay using free scale
application module MC9S12.
DIGITAL VOLTMETER
AIM:
To implement digital voltmeter using using free scale development board
MC9SXDT512 with LCD display and A/D convertors.

SOFTWARE REQUIREMENTS:
Free scale code warrior development studio version 5.0

HARDWARE REQUIREMENTS:
1. Personal Computer
2. MC9SXDT512 Freescale application module
3. USB Interface cable
4. PBMCUSLK Project board

DESCRIPTION:
Voltmeter is an electrical measuring instrument which is used to
measure difference between two points. The voltage to be measured may be AC or
DC. Two voltmeters are available for the purpose of voltage measurement i.e.
analog and digital. Analog voltmeters generally contain a dial with a needle
moving over it according to the measure and hence displaying the value of the
same.
With the passage of time analog voltmeters are replaced by digital
voltmeters due to the same advantages associated with digital systems. Although
analog voltmeters are not fully replaced by digital voltmeters, still there are many
places where analog voltmeters are preferred over digital voltmeters. Digital
voltmeters display the value of AC or DC voltage being measured directly as
discrete numerical instead of a pointer deflection on a continuous scale as in analog
instruments.
Here, we use an A/D convertor to convert the analog values into digital
values and use appropriate multiplication factor (depends on the resolution) to
convert the analog value into digital value.
PROGRAM CODE:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "math.h"
void main(void) {
unsigned int voltage1 = 0,voltage2 = 0;
float digital=0, temp = 0;
SPI_Initialize();
LCD_Initialize();
ATD0CTL2 = 0x80;
ATD0CTL3 = 0x08;
ATD0CTL4 = 0xE3;
for(;;){
ATD0CTL5 = 0x82;
while(!(ATD0STAT0 & 0x80)){
digital = ATD0DR0L*0.0195;
voltage1 = (unsigned int)(digital);
Display_integer(1,0,voltage1);
LCD_CursorPos(1,2);
LCD_SendCharacter('.');
temp = (digital - voltage1)*100;
voltage2 = (unsigned int)temp;
Display_integer(1,3,voltage2);
LCD_CursorPos(1,6);
LCD_SendCharacter('V');
}
}
}
ALGORITHM:
1. Start.
2. Set the appropriate bits in the control registers for power up the A/D
connection and selecting the channel.
3. Read the status flag in ATD0STAT0 and obtain the digital value
corresponding to the analog value.
5
4. Multiply the number of 0.0195 (i.e 𝑉 ) to get the corresponding digital
28
Voltage value.
5. Display the voltage value in LCD.
6. Perform the above steps continuously for a smooth output.
PROCEDURE:
1. The program code is typed in the main.c file of the code warrior studio.
2. Then the program code is saved.
3. The free scale MC9SXDT512 development board is connected to the PC by
means of USB to serial port converter cable.
4. The program code is compiled and debugged using the code warrior studio
debugger.
5. Then the run button is pressed in the code warrior studio for running the
code in the development board.
6. The output of the code is verified by means of the output in the development
board.

RESULT:
Thus a digital Voltmeter using A/D convertors is implemented in the
MC9S12 board with LCD display.
AUTOMATIC LIGHT CONTROLLER

AIM:
To implement light controller using light sensor and LEDs using free scale
development board MC9SXDT512.

SOFTWARE REQUIREMENTS:
Free scale code warrior development studio version 5.0

HARDWARE REQUIREMENTS:
5. Personal Computer
6. MC9SXDT512 Freescale application module
7. USB Interface cable
8. PBMCUSLK Project board

DESCRIPTION:
In electronics, an analog-to-digital converter (ADC, A/D, or A-to-D) is a
system that converts an analog signal, such as a sound picked up by a microphone
or light entering a digital camera, into a digital signal. An ADC may also provide
an isolated measurement such as an electronic device that converts an input analog
voltage or current to a digital number proportional to the magnitude of the voltage
or current.
Before using ADC in MC9SXDT512, certain configurations must be made
for the selection of powering mechanism, triggering mechanism, sequence length,
conversion clock frequency, resolution of ADC, Sampling Time, Justification,
Modes (Continuous or Single), Channels, etc. These can be configured with the
help of ATDCTLx Register (ADC Control Registers).
PROGRAM CODE:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "math.h"
void delay_ms(int n)
{ int i,j;
for(i=0;i<n;i++)
{ for(j=0;j<400;j++)
{ }
}
}
void main(void)
{ int y;
SPI_Initialize();
LCD_Initialize();
DDRB = 0xFF;
PORTB = 0xFF;
ATD0CTL2 = 0x80;
ATD0CTL3 = 0x08;
ATD0CTL4 = 0xE3;
for(;;)
{ ATD0CTL5 = 0x84; //for light sensor
while(!(ATD0STAT0 & 0x80))
{ y = ATD0DR0L;
Display_integer(1,1,y);
if(y==255)
{ PORTB = 0xFF; }
else if(y>190 && y<255)
Registers and their Functions:
ATDCTL2
 ATD’s Conversation Completed Interrupt Enable and Flag
 External Trigger Level/Edge Control
 External Trigger Polarity
 External Trigger Mode Enable
 ATD Power Down
 ATD’S Power Down in Wait Mode
ATDCTL3
 ATD Conversion Sequence Length
 Result Register FIFO Mode
 Background Debug Freeze Enable
ATDCTL4
 Conversion Clock(by changing prescale value) and ATD Resolution
 Sampling Time
ATDCTL5
 Single or Contnous conversion Mode
 Data Justification
 Data Signed or Unsigned
 Channel Selection
 Multi-Channel Sample Mode
ATDSTAT0
 ATD Conversion Completed Flag
 FIFO Over Run Flag
 Conversion Counter
 External Trigger Overrun Flag
ATD0DR0H & ATD0DR0L
 Stores the value of the Converted Value
 No of bits valid depends on the resolution
{ PORTB = 0x00;
delay_ms(1);
PORTB = 0xFF;
delay_ms(2);
}
else
{ PORTB = 0x00; }
}
}
}
ALGORITHM:
1. Start.
2. Set Port B as output port.
3. Set the appropriate bits in the control registers for power up the A/D
connection and selecting the channel.
4. Read the status flag in ATD0STAT0 and obtain the digital value
corresponding to the light sensor output and display it in the LCD panel.
5. If the obtained value is 255 (maximum) turn OFF the LEDs.
6. If the value is between 190 and 255, turn on and off LED with appropriate
delay for dimming the intensity of light.
7. Else if the value is less than 190 (darker ambience), turn ON the LEDs.

PROCEDURE:
1. The program code is typed in the main.c file of the code warrior studio.
2. Then the program code is saved.
3. The free scale MC9SXDT512 development board is connected to the PC by
means of USB to serial port converter cable.
4. The program code is compiled and debugged using the code warrior studio
debugger.
5. Then the run button is pressed in the code warrior studio for running the
code in the development board.
6. The output of the code is verified by means of the output in the development
board.

RESULT:
Thus the automatic light controller with light sensor and LEDs is
implemented in the MC9S12 board with LCD display.
PROGRAM CODING:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
void main(void)
{
unsigned int count = 0, sec=0, min = 0, hour = 0;
DDRB = 0xFF;
PORTB = 0xFF;
TSCR1 = 0x80;
TSCR2 = 0x00;
TFLG2 = 0x80;
SPI_Initialize();
LCD_Initialize();
for(;;) {
while( TFLG2&0x80 ) {
count++;
TFLG2 = 0x80;
}
if (count==30){
sec++;
count = 0;
PORTB = ~PORTB;
}
if (sec==60){
min++;
DIGITAL CLOCK

AIM:
To implement Digital Clock using MC9S12 Free scale Development Board
using Timer/Counter module and LCD display.

SOFTARE REQUIREMENT:
Free scale Code Warrior Development Studio Warrior 5.

HARDWARE REQUIREMENTS:
1. Personal Computer.
2. MC9SXDT512 Freescale application module
3. USB Interface cable
4. PBMCUSLK Project board
DESCRIPTION:
Timer/Counter is one of the vital modules for various embedded
applications. The MSC9S12 board has two 16 bit timers namely TIMER0 and
TIMER1. The timer can be operated in four different modes namely wait mode,
freeze mode, stop mode and normal mode. These modes can be selected on the
basis of sending appropriate control word to the Timer control Register 1. The
timer control register 2 has 16 bits among this the last 13 bits can be used for
selecting the necessary and required Baud Rate. The timer Flag Generator is also a
16 bit register which generates necessary flag signals. The Baud Rate can be 9600,
15100,112500, etc. The Timer can be used to count the pulses in counter mode.
The timer increments on the basis of interrupt generated.
sec = 0;
}
if (min==60){
hour++;
min = 0;
}

Display_integer(1, 0, hour);
LCD_CursorPos(1,2);
LCD_SendCharacter(':');
Display_integer(1, 3, min);
LCD_CursorPos(1,5);
LCD_SendCharacter(':');
Display_integer(1, 6, sec);
}
}
ALGORITHM:
1. Start.
2. Declare Port B as output port.
3. Assign 0x50 to TSCR1 to enable timer.
4. Assign 0x00 to TSCR2 to make the clock frequency equal to the bus
frequency.
5. Assign 0x08 to TFTG2 to enable timer overflow flag.
6. When the flag becomes zero, increment count value.
7. When count is equal to 30 increment number of seconds, sec.
8. When number of seconds becomes 60, increment number of minutes, min
and reset sec to zero.
9. When number of minutes becomes 60, increment hour and reset min to
zero.
10.Display hour, min and sec in LCD panel in appropriate format.

PROCEDURE:
1. The program code is typed in the main.c file of the code warrior studio.
2. Then the program code is saved.
3. The free scale MC9SXDT512 development board is connected to the PC by
means of USB to serial port converter cable.
4. The program code is compiled and debugged using the code warrior studio
debugger.
5. Then the run button is pressed in the code warrior studio for running the
code in the development board.
6. The output of the code is verified by means of the output in the development
board.

RESULT:
Thus the digital clock is implemented using MC9S12 board with
Timer/Counter module and LCD display.

You might also like