Et3491 Eiot Lab Manual
Et3491 Eiot Lab Manual
Et3491 Eiot Lab Manual
3 Flashing of LEDS.
AIM:
To develop a C-Language program for reading an on-chip ADC, convert into decimal and to
display it in PC and to generate a square wave depending on this ADC reading. The ADC input is
connected to any analog sensor/ on board potentiometer.
APPARATUS&SOFTWARE REQUIRED
1. VSK-SCM4 Development board.
2. IAR IDE software.
3. Flash Loader Demonstrator. .
4. CRO
THEORY
ADC: Three 12-bit analog-to-digital converters are embedded and each ADC shares up to 16
external channels, performing conversions in the single-shot or scan mode. In scan mode, automatic
conversion is performed on a selected group of analog inputs. Additional logic functions embedded in
the ADC interface allow:
Simultaneous sample and hold
Interleaved sample and hold
DAC: The two 12-bit buffered DAC channels can be used to convert two digital signals into
two analog voltage signal outputs.
This dual digital Interface supports the following features:
two DAC converters: one for each output channel
8-bit or 12-bit monotonic output
left or right data alignment in 12-bit mode
synchronized update capability
noise-wave generation
triangular-wave generation
dual DAC channel independent or simultaneous conversions
DMA capability for each channel
external triggers for conversion
input voltage reference VREF+
Eight DAC trigger inputs are used in the device. The DAC channels are triggered through the
timer update outputs that are also connected to different DMA streams.
PROCEDURE
1. Write the C program for the given task and execute using IAR
2. Follow the steps 1 of How to create a New project
3. Type the below code and save it with the name (anyname.c)
4. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and
build the program
5. Follow the procedures in How to Download a Code to Our Controller to download your
code.
PROGRAM
ADC:
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_adc.h"
int ConvertedValue = 0; //Converted value read from ADC1 void adc_configure()
{
//Clock configuration
RCC->APB2ENR |= 1<<10; //The ADC3 is connected the APB2 peripheral bus
thus we will use its clock source
RCC->AHB1ENR |= 1<<0; //Clock for the ADC port!! Do not forget about this
one ;)
/* ADC configuration */
ADC3->CR1 = 0x00000000; //scan mode disable,12-bit resolution.
ADC3->CR2 = 0x00000002; //data right alignment, continuous conversion
mode. ADC3->SQR1 = 0x00000000; //single mode conversion
ADC3->CR2 |= 0x00000001; //ADC enable
ADC3->SMPR2 = 0x00000030; //ADC3 channel-1 with 144 cycles
ADC3->SQR3 = 0x00000001 ;//rank1 to ADC3 channel-1
}
int adc_convert()
{
ADC_ SoftwareStartConv(ADC3); //Start the conversion
while(!ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC)); //Processing the conversion
return ADC_GetConversionValue(ADC3); //Return the converted data
}
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; //clock to portA
RCC->APB1ENR |= 1 <<17; //clock to USART2
}
}
int putchar(int data)
{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{}
return data;
}
DAC:
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"
#define sine_wave_gk
//#define triangular_wave_gk
//#define square_wave_gk
//#define sawtooth_wave_gk
unsigned
intsine_wave[200]={2048,2112,2176,2240,2304,2368,2431,2494,2557,2619,2680,2741,2801,2860,29
19,2977,3034,3090,3144,3198,3251,3302,3352,3401,3449,3495,3540,3583,3625,3665,3704,3741,377
6,3809,3841,3871,3900,3926,3951,3973,3994,4013,4030,4045,4058,4069,4078,4085,4090,4093,4095
,4093,4090,4085,4078,4069,4058,4045,4030,4013,3994,3973,3951,3926,3900,3871,3841,3809,3776,
3741,3704,3665,3625,3583,3540,3495,3449,3401,3352,3302,3251,3198,3144,3090,3034,2977,2919,2
860,2801,2741,2680,2619,2557,2494,2431,2368,2304,2240,2176,2112,2048,1984,1920,1856,1792,17
28,1665,1602,1539,1477,1416,1355,1295,1236,1177,1119,1062,1006,952,898,845,794,744,695,647,6
01,556,513,471,431,392,355,320,287,255,225,196,170,145,123,102,83,66,51,38,27,18,11,6,3,1,3,6,11
,18,27,38,51,66,83,102,123,145,170,196,225,255,287,320,355,392,431,471,513,556,601,647,695,744,
794,845,898,952,1006,1062,1119,1177,1236,1295,1355,1416,1477,1539,1602,1665,1728,1792,1856,
1920,1984};
int main(void)
{
static int i;
int j;
GPIO_InitTypeDef
GPIO_InitStructure;/* DMA1 clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
/* GPIOA clock enable (to be used with DAC) */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* DAC Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//TIM6_Config();
while (1)
{
j=0;
#if defined sine_wave_gk
for(i=0;i<200;i++)
{
DAC->DHR12R2 = sine_wave[i];
DAC_Cmd(DAC_Channel_2, ENABLE);
}
#else if defined triangular_wave_gk
for(i=0;i<=4095;i++)
{
DAC->DHR12R2 = i;
DAC_Cmd(DAC_Channel_2, ENABLE);
}
for(i=4095;i>=0;i--)
{
DAC->DHR12R2 = i;
DAC_Cmd(DAC_Channel_2, ENABLE);
}
RESULT:
Thus, the C program is written and executed by verifying the output using ARM processor.
Exp. No.: 2
INTERFACING KEYPAD AND LCD
AIM:
To develop a C-Language program for displaying the Key pressed in the Keypad in the LCD
module. The display should come in the desired line and column using ARM CORTEX M4 KIT
processor board using embedded C program
THEORY:
KEYPAD:
The Matrix keyboard is used to minimize the number of I/O lines. Normally it is possible to
connect only one key or switch with an I/O line. If the number of keys in the system exceeds the more
I/O lines are required. To reduce the number of I/O lines the keys are connected in the matrix circuit.
Keyboards use a matrix with the rows and columns made up of wires. Each key acts like a switch.
When a key is pressed a column wire makes contact with row wire and completes a circuit. For
example 16 keys arranged in a matrix circuit uses only 8 I/O lines
LCD:
Liquid crystals are a phase of matter whose order is intermediate between that of a liquid and
that of a crystal. The molecules are typically rod-shaped organic matters about 25 Angstroms in
length and their ordering is a function of temperature. The molecular orientation can be controlled
with applied electric fields.
PROCEDURE:
1. Write the c program for the given task and execute using IAR
2. Follow the steps 1 of How to create a New project
3. Type the below code and save it with the name (anyname.c)
4. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and
build the program
5. Follow the procedures in How to Download a Code to Our Controller to download your code.
PROGRAM:
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
unsigned char d1[] = {" WELCOME "};
unsigned char d2[] = {" Press any Key"};
unsigned char i;
/*ptototype functions */
void delay(int a);
void mx_pinout_config(void);
void busy_check();
void command_write(int comm);
void lcd_init();
void lcd_out(unsigned char a);
void lcd_stringout(unsigned char *gk);
void mx_pinout_config(void);
void Row1_check();
void Row2_check();
void Row3_check();
void Row4_check(); int val;
void main(void){
mx_pinout_config();
lcd_init(); //send initial commands command
write(0x80);
lcd_stringout(d1);
command_write(0xC0);
lcd_stringout(d2);
while (1)
{
Row1_check();
Row2_check();
Row3_check();
Row4_check();
}
void Row1_check(){
/*1 st row */
GPIOD->BSRRH = 0x0001; //high PD0
GPIOD->BSRRL = 0x000E; //low PD1 to PD3
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>C");
delay(100);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>D");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>E");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>F");
delay(100);
}
}
void Row2_check(){
/*2nd row */
GPIOD->BSRRH = 0x0002; //low PD0
GPIOD->BSRRL = 0x000D; //low PD0
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>8");
delay(100);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>9");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>A");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>B");
delay(100);
}
GPIOD->BSRRH = 0x000E; //low PD0
}
void Row3_check(){
/*3rd row */
GPIOD->BSRRH = 0x0004; //low PD0
GPIOD->BSRRL = 0x000B; //low PD0
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>4");
delay(100);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>5");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>6");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>7");
delay(100);
}
}
void Row4_check(){
/*4th row*/
GPIOD->BSRRH = 0x0008; //low PD0
GPIOD->BSRRL = 0x0007; //low PD0
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>0");
delay(100);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>1");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>2");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>3");
delay(100);
}
}
void delay(int a){
int i,j;
for(i=0;i<a;i++)
for(j=0;j<a;j++);
}
void busy_check(){
delay(200);
GPIOE->BSRRH = 0x0020; //low the RS pin
GPIOE->BSRRH = 0x0040; //low RW pin
}
void command_write(int comm){
busy_check();
GPIOE->BSRRH = 0x0020; //low RS pin
GPIOE->ODR = (comm<<8)|(0<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080; //enable pin high
delay(200);
GPIOE->BSRRH = 0x0080; //enable pin low
}
/*LCD initial commands */
void lcd_init(){
command_write(0x38);
command_write(0x01);
command_write(0x0f);
command_write(0xC0);
command_write(0x06);
}
void lcd_out(unsigned char a){
busy_check();
GPIOE->BSRRL = 0x0020; //high RS pin
GPIOE->ODR = (a<<8)|(1<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080; //enable pin high
delay(200);
GPIOE->BSRRH = 0x0080; //enable pin low
}
void lcd_stringout(unsigned char *gk){
int i;
busy_check();
GPIOE->BSRRL = 0x0020; //high RS pin
for(i=0;gk[i] !='\0';i++)
{
GPIOE->ODR =( gk[i]<<8)|(1<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080; //enable pin high
delay(200);
GPIOE->BSRRH = 0x0080; //enable pin low
}
}
void mx_pinout_config(void){
/*Enable or disable the AHB1 peripheral clock
*/ RCC->AHB1ENR |= 1<<3; // enable the clock to port F
RCC->AHB1ENR |= 1<<4; //enable clock to portB,C,G
GPIOD->MODER |=0x00000055;//set port D0-D3 as o/p mode, other pins are input
mode GPIOD->OTYPER =0x00000000;
GPIOD->PUPDR = 0x00000000;
GPIOD->OSPEEDR =0xAAAAAAAA;
/*Enable pin */
GPIOE->MODER = 0X55555555; // lcd_pins OUTPUT MODE SELECT
GPIOE->OTYPER = 0x00000000;
GPIOE->PUPDR = 0x00000000;
GPIOE->OSPEEDR = 0xAAAAAAAA;
GPIOE->ODR = 0x00000000;
}
OUTPUT:
RESULT:
The C-Language program for displaying the Key pressed in the Keyboard is displayed in the
LCD module and the output was verified on the LCD on the desires line and column/address.
Exp. No.: 3
FLASHING OF LEDS
AIM:
To develop LED blink(including delay routine) and upon changing the delay program the speed
of flashing is varied with help of ARM CORTEX M4 KIT processor board using embedded C program.
APPARATUS&SOFTWAREREQUIRED:
1. VSK-SCM4Developmentboard.
2. IARIDE software.
3. Flash Loader Demonstrator.
THEORY:
LEDs are based on the semiconductor diode. When the diode is forward biased (switched on),
electrons are able to recombine with holes and energy is released in the form of light. This effect is
called electroluminescence and the color of the light is determined by the energy gap of the
semiconductor
PROCEDURE:
1. Followthesteps1of How to create a New project
2. Typethebelowcodeandsaveit with the name(anyname.c)
3. Followthesteps2to6ofHowtocreateaNewProjecttoaddthenecessaryfile,compileand
build the program.
4. FollowtheproceduresinHowtoDownloadaCodetoOurControllertodownloadyourcode
PROGRAM:
#include"stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h" void LED_init();
/* delay function */
void delay(long int a)
{
long int b,c;
for(b=0;b<a;b++)
for(c=0;c<a;c++);
}
OUTPUT:
RESULT:
Thus, development of LED blink (including delay routine) and upon changing the delay
program the speed of flashing is varied with help of ARM CORTEX M4 KIT processor board using
embedded C program is executed and verified.
Exp. No.: 4
INTERFACING STEPPER MOTOR AND TEMPERATURE
AIM:
To implement and generate program for running stepper motor either in clock-wise or
counter- clockwise and the direction of the rotation of the stepper motor depends on
the variation in the temperature sensor using ARM CORTEX M4 KIT processor board using
embedded C program
THEORY:
STEPPER MOTOR
Stepper motors, effectively have multiple "toothed" electromagnets arranged around a central
metal gear. To make the motor shaft turn, first one electromagnet is given power, which makes the
gear's teeth magnetically attracted to the electromagnet's teeth. When the gear's teeth are thus aligned
to the first electromagnet, they are slightly offset from the next electromagnet. So when the next
electromagnet is turned on and the first will turn off, the gear rotates slightly to align with the next
one and from there the process is repeated. Each of those slight rotations is called a "step." In that
way, the motor can be turned to a precised angle. There are two basic arrangements for the
electromagnetic coils: bipolar and unipolar.
PROCEDURE:
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and
build the program.
4. Follow the procedures in How to Download a Code to Our Controller to download your code
PROGRAM:
STEPPER MOTOR:
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h" static int i=0;
/* private prototype functions*/
void anticlock_wise(); void clock_wise(); void delay()
{
for(int i=0;i<0xFF;i++)
for(int j=0;j<0xFF;j++);
}
void motor_PIN_config(void){
RCC->AHB1ENR |= 1<<1;
GPIOB->MODER = 0x55555555;
GPIOB->OTYPER =0x00000000;
GPIOB->PUPDR = 0x00000000;
GPIOB->OSPEEDR = 0xFFFFFFFF;
}
void main(void){
motor_PIN_config();
while(1)
{
anticlock_wise(); delay(); clock_wise(); delay();
}
}
void anticlock_wise(){
for(i=0;i<56;i++)
{
GPIOB->ODR = 0xA000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x6000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x5000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x9000;
delay(); delay(); delay();delay(); delay();
}
}
void clock_wise(){
for(i=0;i<56;i++)
{
GPIOB->ODR = 0x9000;
delay(); delay(); delay(); delay(); delay();
GPIOB->ODR = 0x5000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x6000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0xA000;
delay(); delay(); delay();delay(); delay();
}
}
PROCEDURE TO SEE OUTPUT:
1. Set your board to the execution mode and reset it.
2. The stepper motor will start rotating.
OUTPUT:
STEPPER MOTOR:
TEMPERATURE SENSOR:
The temperature sensor has to generate a voltage that varies linearly with temperature. The
conversion range is between 1.8 V and 3.6 V. The temperature sensor is internally connected to the
ADC1_IN16 input channel which is used to convert the sensor output voltage into a digital value. As
the offset of the temperature sensor varies from chip to chip due to process variation, the internal
temperature sensor is mainly suitable for applications that detect temperature changes instead of
absolute temperatures. If an accurate temperature reading is needed, then an external temperature
sensor part should be used.
PROCEDURE:
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile
and build the program
4. Follow the procedures in How to Download a Code to Our Controller to download your
code.
PROGRAM:
TEMPERATURE SENSOR:
#include "stm32f4xx.h"
#include <studio.h>
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_adc.h"
#include "stm32f4xx_gpio.h"
static int i=0;
/* private prototype functions*/
void anticlock_wise();
void clock_wise();
void USART2_config();
void adc_configure();
int adc_convert();
uint32_t temp;
static float gk;
void delay()
{
for(int i=0;i<0xFF;i++)
for(int j=0;j<0xFF;j++);
}
IO uint32_t uhADCxConvertedValue = 0;
void USART2_config()
{
RCC->AHB1ENR |= 0x01;
RCC->APB1ENR |= 0x20000;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
USART2->BRR = 0x16D;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
}
void adc_configure()
{
//Clock configuration
RCC->APB2ENR |= 1<<10; /*The ADC1 is connected the APB2 peripheral bus
thus we will use its clock source */
RCC->AHB1ENR |= 1<<0; /*Clock for the ADC port!! Do not forget about this one ;) */
//Analog pin configuration
GPIOA->MODER |=0x0000000F;
GPIOA->OSPEEDR = 0xFFFFFFFF;
GPIOA->PUPDR = 0x00000000;
/* ADC configuration */
ADC3->CR1 = 0x00000000; /*scan mode disable,12-bit resolution.*/
ADC3->CR2 = 0x00000002; /*data right alignment, continuous conversion mode. */
ADC3->SQR1 = 0x00000000; /* single mode conversion */
ADC3->CR2 |= 0x00000001; /*ADC enable */
ADC3->SMPR2 = 0x00000030; /*ADC3 channel-1 with 144 cycles */
ADC3->SQR3 = 0x00000001; /* rank1 to ADC3 channel-1 */
}
int adc_convert()
{
ADC_SoftwareStartConv(ADC3); /*Start the conversion */
while(!ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC));/* Processing the conversion */
return ADC_GetConversionValue(ADC3); /*Return the converted data */
}
int putchar(int data)
{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{ }
return data;
}
void motor_PIN_config(void)
{
RCC->AHB1ENR |= 1<<1;
GPIOB->MODER = 0x55555555;
GPIOB->OTYPER =0x00000000;
GPIOB->PUPDR = 0x00000000;
GPIOB->OSPEEDR = 0xFFFFFFFF;
}
void main(void)
{
static int ConvertedValue;
motor_PIN_config();
USART2_config(); /* ADC configuration */
while(1)
{
ConvertedValue = adc_convert(); /* Read the ADC converted value */
temp =ConvertedValue;
gk =temp*3.3;
gk /=4095;
gk *=100;
printf("\n Temperature = %3.2f°C",gk);
if(gk>40) /* if temperature > 40 */
{
anticlock_wise();
delay();
}
else if(gk<40) /* if temperature < 40 */
{
clock_wise();
delay();
}
}
}
void anticlock_wise()
{
for(i=0;i<52;i++)
{
GPIOB->ODR = 0xA000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x6000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x5000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x9000;
delay(); delay(); delay();delay(); delay();
}
}
void clock_wise()
{
for(i=0;i<52;i++)
{
GPIOB->ODR = 0x9000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x5000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x6000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0xA000;
delay(); delay(); delay();delay(); delay();
}
}
OUTPUT:
TEMPERATURE SENSOR
RESULT:
Thus, implementing and generation of stepper motor either in clock-wise or counter-
clockwise and the direction of the rotation of the stepper motor depends on the
variation in the temperature sensor using ARM CORTEX M4 KIT processor board using embedded C
program is executed and verified.
Exp. No.: 5 SIMPLE ARITHMETIC OPERATIONS WITH 8051:
MULTI PRECISION ADDITION / SUBTRACTION /
MULTIPLICATION/ DIVISION.
AIM:
To write a program to add / Subtraction / Multiply and divide two 8-bit numbers using
8051 microcontroller.
ALGORITHM: Addition
1. Clear Program Status Word.
2. Select Register bank by giving proper values to RS1 & RS0 of PSW.
3. Load accumulator A with any desired 8-bit data.
4. Load the register R 0 with the second 8- bit data.
5. Add these two 8-bit numbers.
6. Store the result.
7. Stop the program.
ALGORITHM:
1. Clear the carry flag.
2. Initialize the register for borrow.
3. Get the first operand into the accumulator.
4. Subtract the second operand from the accumulator.
5. If a borrow results increment the carry register.
6. Store the result in memory.
FLOW CHART:
PROGRAMS
4500 0B 4500 05
ALGORITHM: Multiplication
a. Get the multiplier in the accumulator.
b. Get the multiplicand in the B register.
c. Multiply A with B.
d. Store the product in memory.
ALGORITHM: Division
1. Get the Dividend in the accumulator.
2. Get the Divisor in the B register.
3. Divide A by B.
4. Store the Quotient and Remainder in memory.
FLOWCHART:
START START
STORE
STORE RESULT QUOTIENT &
IN MEMORY REMAINDER IN
MEMORY
STOP STOP
8 Bit Multiplication
MNEMONIC
ADDRESS LABEL HEX CODE COMMENTS
OPERAND
4100 MOV A ,#data1 74 06 Store data1 in accumulator
4102 MOV B, #data2 75 02 Store data2 in B reg
4105 MUL A,B A4 Multiply both
4106 MOV DPTR, # 4500H 90 45 00 Initialize memory location
4109 MOVX @ DPTR, A F0 Store lower order result
410A INC DPTR A3 Go to next memory location
410B MOV A,B F5 E0
Store higher order result
410D MOV @ DPTR, A F0
410E STOP SJMP STOP 80 FE Stop
8 Bit Division
MNEMONIC
ADDRESS LABEL HEX CODE COMMENTS
OPERAND
4100 MOV A, # data1 74 02 Store data1 in accumulator
4102 MOV B, # data2 75 04 Store data2 in B reg
4105 DIV A,B 84 Divide
4106 MOV DPTR, # 4500H 90 45 00 Initialize memory location
4109 MOVX @ DPTR, A 0F Store remainder
410A INC DPTR AC Go to next memory location
410B MOV A,B F5 E0
410D MOV @ DPTR, A F0 Store quotient
410E STOP SJMP STOP 80 FE Stop
INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
4500 06 4502 0C
4501 02 4503 00
INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
4500 (dividend) 02 4502 (remainder) 02
4501 (divisor) 04 4503 (quotient) 00
RESULT:
Thus the 8051 Assembly Language Program for addition / subtraction /
multiplication and division of two 8 bit numbers is executed and verified.
Exp. No.: 6 8 BIT Logical and Bit Manipulation using 8051
AIM:
To write an Assembly Language Program to perform logical and bit manipulation operations using 8051
microcontroller.
APPARATUS REQUIRED:
8051 microcontroller kit
ALGORITHM:
1. Initialize content of accumulator as FFH
2. Set carry flag (cy = 1).
3. AND bit 7 of accumulator with cy and store PSW format.
4. OR bit 6 of PSW and store the PSW format.
5. Set bit 5 of SCON.
6. Clear bit 1 of SCON.
7. Move SCON.1 to carry register.
8. Stop the execution of program.
FLOWCHART:
START
STOP
PROGRAM TABLE
4502H (SCON) SM0 SM1 SM2 REN TB8 RB8 TI RI 0FH 20H
RESULT:
Thus the bit manipulation operation is done and verified in 8051 microcontroller.
Exp. No.: 7 Programming using on chip ports in 8051
AIM
To write a program to interface 8051 with Analog to Digital and Digital to Analog
devices.
APPARATUS REQUIRED
8051 microcontroller trainer kit
8051 user manual
A to D and D to A manuals
Power cable
ANALOG TO DIGITAL
PROCEDURE
Place jumper J2 in C position.
Place jumper J5 in A position.
Enter and execute the program.
Vary the analog input and view the output.
PROGRAM
MEMORY
OPCODES LABELS MNEMONICS COMMENTS
ADDRESS
4100 90 FF C8 MOV DPTR,#FFC8
4103 74 10 MOV A,#10
4105 F0 MOVX @DPTR,A
4106 74 18 MOV A,#18
4108 F0 MOVX @DPTR,A
4109 74 18 MOV A,#10
410B F0 MOVX @DPTR,A
410C 80 FE HERE: SJMP HERE
DIGITAL TO ANALOG ( TRIANGULAR WAVE)
MEMORY
OPCODES LABELS MNEMONICS COMMENTS
ADDRESS
4100 90 FF C0 MOV DPTR,#FFC8
4103 74 00 START: MOV A,#00
4105 F0 LOOP1: MOV @DPTR,A
4106 04 INC A
4107 70 FC JNZ LOOP1
4109 74 FF MOV A,#FF
410B F0 LOOP2: MOVX @DPTR,A
410C 14 DEC A
410D 70 FC JNZ LOOP2
410F 02 41 03 LJMP START
RESULT: Thus a program to interface 8051 with ADC and DAC is written and
Executed successfully.
Exp. No.: 8 Design of Digital clock using Timers/Counters in 8051
AIM
To Design of Digital clock using Timers/Counters in 8051.
APPARATUS REQUIRED
8051 microcontroller trainer kit
8051 user manual
8253 User manual
Power cable
PROGRAM
MEMORY
OPCODES LABELS MNEMONICS COMMENTS
ADDRESS
4100 90 FF CE MOV DPTR,#FFCE
4103 74 30 MOV A,#30
4105 F0 MOVX @DPTR,A
4106 90 FF C8 MOV DPTR.#FFC8
4109 74 05 MOV A,#05
410B F0 MOVX @DPTR,A
410C 74 00 MOV A,#00
410E F0 MOVX @DPTR,A
410F 80 FE HERE: SJMP HERE
AIM
To design a Smart Lock system using IOT
Components Required
Node MCU ESP8266
Solenoid Lock
Relay Module
Buzzer
Solenoid Lock
In conventional door lock, there is key to pull or push the latch, and we have to operate it manually, but in
solenoid lock, the latch can be operated automatically by applying a voltage. Solenoid lock has a low-voltage
solenoid that pulls the latch back into the door when an interrupt (Pushbutton, Relay, etc.) is activated. The latch
will retain its position until the interrupt is enabled. The operating voltage for the solenoid lock is 12V. You can
also use 9V, but it results in slower operation. Solenoid door locks are mainly used in remote areas to automate
operations without involving any human effort.
Smart Door Lock Circuit Diagram
The circuit diagram for the Wi-Fi door lock is given below.
Connections for this IoT Smart Door Lock are very simple as we are only connecting a solenoid lock, relay
module, and a buzzer with NodeMCU ESP8266. The input pin of the relay is connected to the D5 pin of
NodeMCU while VCC and Ground pins are connected to Vin and GND pin of NodeMCU. The positive pin of
the buzzer is connected to the D6 pin of NodeMCU, and the GND pin is connected to the GND of NodeMCU.
I have soldered all the components on Perfboard as shown in the below pictures:
This is how the complete setup of wifi door lock will look after installing on the door:
Exp. No.: 10
IMPLEMENTING AUDIO SIGNALING
AIM:
To implement and control the audio signaling for agiven duration withARMCORTEX M4
KIT processor board using embedded C program.
PROCEDURE:
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and
build the program.
4. Follow the procedures in How to Download a Code to Our Controller to download your code
PROGRAM:
#include "stm32f4xx.h"
#define BUZZER_ON ((GPIOC->ODR = 0x01))
#define BUZZER_OFF ((GPIOC->ODR = 0x00))
void buzzer_init(){
RCC->AHB1ENR |= 1 << 2; //enable clock to PORT-C
GPIOC->MODER = 0x00000001; //PC0 as o/p mode
GPIOC->OTYPER = 0x00000000; //push-pull type
GPIOC->PUPDR = 0x00000000; //no pull-up,pull-down
GPIOC->OSPEEDR = 0xAAAAAAAA; //spedd is 50MHZ
}
void delay(long int delay){
long int d1,d2;
for(d1=delay;d1>0;d1--)
for(d2=delay;d2>0;d2--);
}
void main(){
buzzer_init();
while(1){
BUZZER_O;
delay(5000);
BUZZER_OFF;
delay(5000);
}
}
RESULT:
Thus, the implementation and controlling of audio signaling with ARM CORTEX M4 KIT
processor board using embedded C program has been done.
Exp. No.: 11
IMPLEMENTING SWITCHING SIGNALS USING RELAY
AIM:
To control switching of relay signal with ARM CORTEX M4 KIT processor board using
embedded C program.
APPARATUS&SOFTWAREREQUIRED
1. VSK-SCM4Developmentboard.
2. IARIDE software.
3. Flash Loader Demonstrator.
PROCEDURE
1. Followthesteps1ofHowtocreateaNewproject
2. Typethebelowcodeandsaveit with the name(anyname.c)
3. Followthesteps2to6of How to create a New Project to add the necessary file, compile
and build the program.
4. FollowtheproceduresinHowtoDownloadaCodetoOurControllertodownloadyour code
PROGRAM
#include "stm32f4xx.h"
#include <stdio.h>
#define RELAY_ON ((GPIOC->ODR = 0x0200))
#define RELAY_OFF ((GPIOC->ODR = 0x0000))
void buzzer_init(){
RCC->AHB1ENR |= 1 << 2; //enable clock to PORT-C
GPIOC->MODER = 0x00050000; //PC9 as o/p mode
GPIOC->OTYPER = 0x00000000; //push-pull type
GPIOC->PUPDR = 0xAAAAAAAA; //no pull-up,pull-down
GPIOC->OSPEEDR = 0xAAAAAAAA; //spedd is 50MHZ
}
void delay(long int delay){
long int d1,d2;
for(d1=delay;d1>0;d1--)
for(d2=delay;d2>0;d2--);
}
void main(){
buzzer_init();
while(1){
RELAY_ON;
delay(5000);
RELAY_OFF;
delay(5000);
}
}
RESULT:
Thus, controlling switching of relay signal with ARM CORTEX M4 KIT processor board
using embedded C program is executed and verified successfully.
Exp. No.: 12 IMPLEMENTING TRANSMISSION OF DATA USING I2C AND
UART
AIM:
To implement and control data transmission using I2C and UART with ARM CORTEX M4
KIT processor board using embedded C program.
APPARATUS&SOFTWAREREQUIRED:
1. VSK-SCM4Developmentboard.
2. IARIDE software.
3. Flash Loader Demonstrator.
PROCEDURE:
1. Followthesteps1ofHowtocreateaNewproject
2. Typethebelowcodeandsaveit with the name(anyname.c)
3. Followthesteps2to6of How to create a New Project to add the necessary file, compile
and build the program.
4. FollowtheproceduresinHowtoDownloadaCodetoOurControllertodownloadyour code
PROGRAM:
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"
unsigned char arr[12] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x6f,0x80,0x00};
#define SLAVE_ADDRESS1 0x72 // the slave address (example)
#define SLAVE_ADDRESS2 0x76 // the slave address (example)
#define SLAVE_ADDRESS2 0x42 // the slave address (example)
#define SLAVE_ADDRESS1 0x46 // the slave address (example)
#ifdef GNUC
// With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
// set to 'Yes') calls io_putchar() */
void Delay( IO uint32_t nCount)
{
while(nCount--)
{}
}
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1<<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
//USART3->BRR = 0x8A; //115200 baud rate
USART2->BRR = 0x16D;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
}
int putchar(int ch)
{
USART_SendData(USART2, (uint8_t) ch);
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
return ch;
}
void init_I2C1()
{
GPIO_InitType Def GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;
// enable APB1 peripheral clock for I2C1
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
// enable clock for SCL and SDA pins
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
/* setup SCL and SDA pins
* You can connect I2C1 to two different
* pairs of pins:
* 1. SCL on PB6 and SDA on PB9 */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9;
// we are going to use PB6 and PB7
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
// set pins to alternate function
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
// set GPIO speed
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
// set output to open drain --> the line has to be only pulled low, not driven high
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; // enable pull up resistors
GPIO_Init(GPIOB, &GPIO_InitStruct); // init GPIOB
// Connect I2C1 pins to AF
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1);// SCL
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_I2C1); // SDA
// configure I2C1
I2C_InitStruct.I2C_ClockSpeed = 100000; // 100kHz
I2C_InitStruct.I2C_ClockSpeed = 50000; // 50khz
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; // I2C mode
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;// 50% duty cycle --> standard
I2C_InitStruct.I2C_OwnAddress1 = 0x00;// own address, not relevant in master mode
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable;
// disable acknowledge when reading (canbe changed later on)
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
// set address length to 7 bit addresses
I2C_Init(I2C1, &I2C_InitStruct); // init I2C1
// enable I2C1
I2C_Cmd(I2C1, ENABLE);
}
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
{
// wait until I2C1 is not busy anymore
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
// Send I2C1 START condition
I2C_GenerateSTART(I2Cx, ENABLE);
// wait for I2C1 EV5 --> Slave has acknowledged start condition
printf("statu = %x",I2C_CheckEvent(I2Cx,I2C_EVENT_MASTER_MODE_SELECT));
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
// Send slave Address for write
I2C_Send7bitAddress(I2Cx, address, direction);
/* wait for I2C1 EV6, check if either Slave has acknowledged Master transmitter or
Master receiver mode, depending on the transmission direction*/
if(direction == I2C_Direction_Transmitter)
{
while(!I2C_CheckEvent(I2Cx,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
}
else if(direction == I2C_Direction_Receiver)
{
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
}
}
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data)
{
I2C_SendData(I2Cx, data); // wait for I2C1 EV8_2 --> byte has been transmitted
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
}
uint8_t I2C_read_ack(I2C_TypeDef* I2Cx)
{
// enable acknowledge of received data
I2C_AcknowledgeConfig(I2Cx, ENABLE);
// wait until one byte has been received
while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) );
// read data from I2C data register and return data byte
uint8_t data = I2C_ReceiveData(I2Cx);
return data;
}
uint8_t I2C_read_nack(I2C_TypeDef* I2Cx)
{
// disable acknowledge of received data
// nack also generates stop condition after last byte received
// see reference manual for more info
I2C_AcknowledgeConfig(I2Cx, DISABLE);
I2C_GenerateSTOP(I2Cx, ENABLE);
// wait until one byte has been received
while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) );
// read data from I2C data register and return data byte
uint8_t data = I2C_ReceiveData(I2Cx);
return data;
}
void I2C_stop(I2C_TypeDef* I2Cx)
{
// Send I2C1 STOP Condition
I2C_GenerateSTOP(I2Cx, ENABLE);
}
int main(void) {
USART2_config();
init_I2C1();
int i;
while (1)
{
//init_I2C1(); // initialize I2C peripheral
I2C_start(I2C1, SLAVE_ADDRESS1, I2C_Direction_Transmitter);
// start a transmission in Master transmitter mode
for(i=0;i<=11;i++){
I2C_write(I2C1, arr[i]); // write one byte to the slave
Delay(10000000);
}
I2C_stop(I2C1);
/* 2nd seven segment */
I2C_start(I2C1, SLAVE_ADDRESS2, I2C_Direction_Transmitter);
// start a transmission in Master receiver mode
for(i=0;i<=11;i++)
{
I2C_write(I2C1, arr[i]); // write one byte to the slave
Delay(10000000);
}
I2C_stop(I2C1); // stop the transmission*/
}
}
RESULT:
Thus, implementing and controlling of data transmission using I2C and UART with ARM
CORTEX M4 KIT processor board using embedded C program is executed and verified successfully.