100% found this document useful (3 votes)
2K views53 pages

ET3491 Final - Merged Full Manual

This document provides instructions for experiments in embedded systems lab using hardware kits like Vi-STM32SB board and VPTB-07 starter kit. It lists the required hardware, software tools like IAR workbench, flash loader demonstrator and flash magic for programming microcontrollers. The experiments cover programming of 8051 and ARM microcontrollers for applications like serial communication, timers, ADC etc.

Uploaded by

manoj yohan
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
100% found this document useful (3 votes)
2K views53 pages

ET3491 Final - Merged Full Manual

This document provides instructions for experiments in embedded systems lab using hardware kits like Vi-STM32SB board and VPTB-07 starter kit. It lists the required hardware, software tools like IAR workbench, flash loader demonstrator and flash magic for programming microcontrollers. The experiments cover programming of 8051 and ARM microcontrollers for applications like serial communication, timers, ADC etc.

Uploaded by

manoj yohan
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/ 53

SARANATHAN COLLEGE OF ENGINEERING

PANJAPPUR, TIRUCHIRAPALLI - 620 012


(AFFILIATED TO THE ANNA UNIVERSITY)

Name

Reg. No..
Sem./Branch..

Sub. Code/Subject...

Bonalids record of the work done


in the Laboratory dwring the period,
to

Lecturer - in - charge
Head of the Department

Date

Submitted for the Practical Examination held at SARANATHAN

cOLLEGE OF ENGINEERING, TIRUCHIRAPALLI on.

2
EXAMINERS
CONTENTS
Exercise No. Date Name of the Exercise Page No. Remarks
CONTENTS
Exercise No. Date Name of the Exercise Page No. Remarks
LAB MANUAL
EMBEDDED SYSTEMS AND IoT
VI SEMESTER- III YEAR- ECE
REGULATION: 2021
SUBJECT CODE: ET3491
ANNA UNIVERSITY CHENNAI

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING
SARANATHAN COLLEGE OF ENGINEERING
TRICHY-620012
Vision of the Department
 To become a leading department of Higher Learning and a Research Center of
Excellence in Electronics and Communication Engineering.

Mission of the Department


 To enable budding engineers to obtain technical exposure in various areas of Electronics
and Communication Engineering.
 To nurture career improvement.
 To initiate and sustain research activities in the department in cutting edge areas of
Electronics and Communication Engineering.
 To develop professional and ethical attitude in the students.

Program Educational Objectives


The Graduates of Electronics and Communication Engineering will
 Have a strong foundation in the required sciences in order to pursue studies in Electronics
and Communication Engineering.
 Have a broad exposure in various topics related to Electronics and Communication
Engineering fields, to enable them to excel in their professional career / higher studies.
 Possess innovative skills in order to solve the technical problems which will arise in their
professional life.
 Have professional and ethical attitude and an ability to visualize the engineering issues in
a broader social context.

Program specific outcomes


 Graduates of Electronics and Communication Engineering will be able to:
 Comprehend and demonstrate the principles and concepts of Semiconductor theory,
Signal Processing & Embedded systems in the fields of Consumer Electronics, Medical
Electronics and Defense Electronics.
 Apply emerging Information and Communication Engineering Techniques to solve real
time problems.
Program Outcomes
Engineering Graduates will be able to:
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change.
SYLLABUS

ET3491 EMBEDDED SYSTEMS AND IoT DESIGN

List of Experiments

Experiments using 8051

1. Programming Arithmetic and Logical Operations in 8051.

2. Generation of Square waveform using 8051.

3. Programming using On – Chip ports in 8051.

4. Programming using Serial Ports in 8051.

5. Design of a Digital Clock using Timers/Counters in 8051.

Experiments using ARM

6. Interfacing ADC and DAC

7. Blinking of LEDs and LCD

8. Interfacing keyboard and Stepper Motor.

Miniprojects for IoT

1. Garbage Segregator and Bin Level Indicator

2. Colour based Product Sorting

3. Image Processing based Fire Detection

4. Vehicle Number Plate Detection

5. Smart Lock System


Experiment No: 01
Date:
Programming Arithmetic and Logical Operations in 8051.

AIM

To perform arithmetic & Logical operations using 8051 microcontroller

APPARATUS REQUIRED

8051 kit

FLOWCHART

ADDITION/ SUBTRACTION
MULTIPLICATION / DIVISION

LOGICAL AND /OR / EX-OR


INPUT OUTPUT
Register /address Data Register /address Data

8 bit Addition

8 bit subtraction

8 bit
Multiplication

8 bit Division

16 bit Addition

16 bit subtraction

Logical AND

Logical OR

Logical EX-OR
LABEL ADDRESS OPCODE MNEMONICS COMMENTS
Experiment No: 02
Date:
Generation of Square waveform using 8051
.

AIM

To generate a square wave using 8051 microcontroller

APPARATUS REQUIRED

Keil vision software

Algorithm:

1. Set port1 as output port.

2. Move the value 0H to Port 1 and then call the delay.

3. Move the value 0FFH to Port 1 and then call the delay.

4. Repeat the steps 2 and 3.

5. Delay is given using Register R1, R2.

6. Using logic analyser square waveform output is viewed in Keil platform.


PROGRAM

MOV P1, #00H

AGAIN: MOV P1, #00H

ACALL DELAY

MOV P1, #0FFH

ACALL DELAY

SJMP AGAIN

DELAY: MOV R1, #0FFH

MOV R2, #0FFH

L1: DJNZ R2, L1

L2: DJNZ R1, L2

RET

END

RESULT:
OUTPUT
Experiment No: 03
Date:
Programming using On – Chip ports in 8051

AIM

To perform programming using On – Chip ports in 8051

APPARATUS REQUIRED

8051 kit

Algorithm:

1. Move the value 081H to the Interrupt Enable pin to enable it.

2. Press INT0 interrupt is enabled. LED’s are off.

3. End the Program.


PROGRAM

ORG 0000h

MOV IE, #081H

JB TCON.1, LOOP1

MOV P1, #00H

LOOP1: JNB TCON.1,LOOP2

MOV P1, #0FFH

LOOP2: RETI

l3 : SJMP l3

END
OUTPUT

RESULT
Experiment No: 04
Date:
Programming using Serial Ports in 8051

AIM

To perform programming using Serial Ports in 8051

APPARATUS REQUIRED

Keil vision software

ALGORITHM:

1. Initialize TMOD with 20H

2. Set the values for TCON and SCON

3. Start the timer.

4. Based on the bit value on SCON store the data in SBUF and move the data to register ‘A’.

5. Based on the bit value on SCON store the data in register ‘A’ and is moved to SBUF register.

6. The process gets repeated until ‘$’ sign is found.


PROGRAM

MOV TMOD,#20H

MOV TH1, #0FDH

MOV SCON,#50H

SETB TCON.6

REPEAT: JNB RI, REPEAT

MOV A, SBUF

CLR RI

MOV SBUF,A

HERE: JNB TI, HERE

CLR TI

CJNE A, #'$',REPEAT

END
OUTPUT

RESULT:
INSTRUCTION TO DO EMBEDDED LAB

Hardware and software Requirements


1. Vi – STM32SB Development board

2. VPTB – 07 starter kit with VLEDD – 02

3. Altera's Cyclone V

4. Zigbee modules (battery + RF board)

5. IAR Embedded workbench version 6.50 or above

6. Flash Loader Demonstrator

7. Flash Magic

8. Win X-Talk

9. PC/Laptop

Instruction:
Follow the given steps for getting started with the syllabus experiments:
1. Install IAR Embedded Workbench IDE software and Win X-Talk software
2. After successful installation of IAR and Win X- Talk, Install Flash Loader
Demonstrator.

3. Connect the RS232 cable/USB cable provided to the PC and the STM32 Syllabus
Board, and Power on the Development Board.
4. If you are using USB cable, then install the required USB to Serial driver (FTDI
for on beard converter).
5. Search/Set the COM Port no here:
Start >> My Computer >> Manage (on right click) >> Device Manager >> Ports
(COM & LPT)
6. Now, Identify the Mode-Select-Switch(SW9) provided on the Vi-STM32 Board
marked with the text +3.3V & GND
a. +3.3V: Programming Mode used for downloading the code/program into the flash
memory.
b. GND: Execution Mode used for executing program after downloading.
7. After selecting any position (+3.3V / GND) press the reset switch provided on the board.
8. After setting the proper COM port number & selecting the Mode-Select-Switch
position properly, Extract the “Vi – STM32 SB SOURCE CODES V 1.0” (Win RAR
archive) file.
9. Open the project and follow the instructions given in each experiment.
ABOUT VI-STM32 SB DEVELOPMENT BOARD

The Vi – STM32 syllabus board is a demonstration and development platform for the
STM32F4 series and includes an embedded STM32F407ZT6 high-performance ARM Cortex-
M4 32-bit microcontroller. The full range of hardware features on the board is provided to help
you evaluate all peripherals (Ethernet, motor control, CAN, USART etc.) and develop your own
applications. Extension headers make it possible to easily connect a daughterboard or wrapping
board for your specific application.

STM32F407ZG Features:
• Core: ARM 32-bit Cortex™-M4 CPU with FPU, Adaptive real-time accelerator (ART
Accelerator™) allowing 0-wait state execution from Flash memory, frequency up to 168
MHz, memory protection unit, 210 DMIPS/ 1.25 DMIPS/MHz (Dhrystone 2.1), and DSP
Instructions
• Memories
– Up to 1 Mbyte of Flash memory
– Up to 192+4 Kbytes of SRAM including 64-Kbyte of CCM (core coupled memory)
data RAM
– Flexible static memory controller supporting Compact Flash, SRAM, PSRAM,
NOR and NAND memories
• LCD parallel interface, 8080/6800 modes
• Clock, reset and supply management
– 1.8 V to 3.6 V application supply and I/Os
– POR, PDR, PVD and BOR
– 4-to-26 MHz crystal oscillator
– Internal 16 MHz factory-trimmed RC (1% accuracy)
– 32 kHz oscillator for RTC with calibration
– Internal 32 kHz RC with calibration
• Low power
– Sleep, Stop and Standby modes
– VBAT supply for RTC, 20×32 bit backup registers + optional 4 KB backup SRAM
• 3×12-bit, 2.4 MSPS A/D converters: up to 24 channels and 7.2 MSPS in triple interleaved
mode
• 2×12-bit D/A converters
• General-purpose DMA: 16-stream DMA controller with FIFOs and burst support
• Up to 17 timers: up to twelve 16-bit and two 32-bit timers up to 168 MHz, each with up to
4 IC/OC/PWM or pulse counter and quadrature (incremental) encoder input
• Debug mode
– Serial wire debug (SWD) & JTAG interfaces
– Cortex-M4 Embedded Trace Macrocell™
• Up to 140 I/O ports with interrupt capability
– Up to 136 fast I/Os up to 84 MHz
– Up to 138 5 V-tolerant I/Os
• Up to 15 communication interfaces
– Up to 3 × I2C interfaces (SMBus/PMBus)
– Up to 4 USARTs/2 UARTs (10.5 Mbit/s, ISO 7816 interface, LIN, IrDA, modem
control)
– Up to 3 SPIs (42 Mbits/s), 2 with muxed full-duplex I2S to achieve audio
class accuracy via internal audio PLL or external clock

–2 × CAN interfaces (2.0B Active)

– SDIO interface
• Advanced connectivity
– USB 2.0 full-speed device/host/OTG controller with on-chip PHY
– USB 2.0 high-speed/full-speed device/host/OTG controller with dedicated DMA, on-
chip full-speed PHY and ULPI
– 10/100 Ethernet MAC with dedicated DMA: supports IEEE 1588v2 hardware,
MII/RMII
• 8- to 14-bit parallel camera interface up to 54 Mbytes/s
• True random number generator
• CRC calculation unit
• 96-bit unique ID
• RTC: sub second accuracy, hardware calendar
Experiment : 6 (a)
Date :
INTERFACING ADC
Aim
To develop an embedded C program for reading an on-chip ADC, convert into decimal
and to display it in PC. The ADC input is connected to any analog sensor/ on board
potentiometer
Apparatus & Software Required
1. Vi – STM32 development board
2. IAR workbench
3. Flash Loader Demonstrator
4. USB cable
Theory
STM32F407ZG –cortex M4 controller has three 12-bit ADC channels. In vi-stm32
syllabus board includes two potentiometers for the analog voltage variations. The potentiometer
POT1 is connected to ADC3_IN8 (i.e.) PF10 of the controller. The potentiometer POT2 is
connected to ADC3_IN7 (i.e.) PF9 of the controller. The ADC varying between 0 to 4095.the
ADC outputs are displayed through the serial communication (P10 or P3 connector).
Procedure:

1. Create a new project.


2. Type the code and save the file with extension .C in the project.
3. Add the necessary files to the project.
4. Create the output file in the format .hex for downloading the code into the processor.
5. Build the project and compile it.
6. Download the hex file into the processor with the help of flash loader.
7. After downloading the program change the board to execution mode and reset it.
8. Vary the pot in the board and view the corresponding converted digital value in winxtalk
window or HyperTerminal for ADC.
Program:
#include "stm32f4xx.h"
#include
"stdio.h" int
cvalue = 0;
void adc_configure()
{
RCC->APB2ENR |=1<<10; //ADC3 enable
RCC->AHB1ENR = 1<<5; // port F enable
GPIOF->MODER = 0x000C0000; // analog mode
GPIOF->OSPEEDR = 0xFFFFFFFF; // 100 MHz SPEED
GPIOF->PUPDR = 0x00000000; // NO PULL UP PULL DOWN
ADC3->CR1=0x00000000; // SCAN MODE DISABLE, 12 BIT RESOLUION
ADC3->CR2=0x00000003; // CONTINUOUS CONVERSION MODE RIGHT
ALIGNMENT ADC3->SQR1=0x00000000; // sINGLE MODE CONVERSION
ADC3->SMPR2=0xc00000; // ADC3 CHANNEL 1-7 WITH 144 CYCLES
}
int adc_convert()
{
ADC3->CR2|=(1<<30); // START CONVERSION OF REGULAR CHANNEL
while ((ADC3->SR & 2)==0){}
return(ADC3->DR);
}
void USART3_config()
{
RCC->AHB1ENR|=1<<2; // PORT C
ENABLE RCC->APB1ENR|=1<<18; //
USART3 ENABLE
GPIOC->MODER=0x00A00000; // ALTERNATE FUNCTION MODE
GPIOC->AFR[1]=0x00007700;
USART3->BRR =0x16D; //115200 BAUD
RATE USART3->CR3=0x0000;
USART3-
>CR2=0x0000;
USART3-
>CR1=0x200c;
}
int main()
{
USART3_config();
adc_configure(); // start
conversion while(1)
{
cvalue=adc_convert(); // read the ADC
value printf("ADCvalue|=%d", cvalue);
}
}
int putchar(int data)
{
USART3->DR=(data & 0x01FF);
while ((USART3->SR &
0x40)==0){} return data;
}

Result:
Experiment : 6(b)
Date :
INTERFACING DAC
Aim
To develop an embedded C program for converting given digital value into analog
Apparatus & Software Required
1. Vi – STM32 development board
2. IAR workbench
3. Flash Loader Demonstrator
4. CRO
5. USB cable
Theory
Digital to Analog Converters (DAC) is a device for converting a digital (usually binary)to
an analog signal (current, voltage or electric charge).STM32F407ZG controller has two 12-bit
D/A converters.DAC output pins are PA4 and PA5.for DAC channel one output is produced in
PA4 and DAC channel two output is produced in PA5.PA4 pin is available in 31st pin of P9
connector.PA5 is available in 28th pin of P9 connector.
Procedure
1. Create a new project.
2. Type the code and save the file with extension .C in the project.
3. Add the necessary files to the project.
4. Create the output file in the format .hex for downloading the code into the processor.
5. Build the project and compile it.
6. Download the hex file into the processor with the help of flash loader.
7. After downloading the program change the board to execution mode and reset it.
8. For DAC, the digital value given in the program is converted and the corresponding analog
signal is viewed with the help of CRO.
9. Make use of a CRO or DSO to view the DAC output by connecting the positive terminal to
PA5 pin of P9 connector (28th pin) and the negative terminal to GND.

Program:
DAC.C
Triangular wave
#include generation
"stm32f4xx.h"
#include
"stdio.h" int
main()
{
RCC->APB1ENR|=0x20000000; // DAC CLOCK
ENABLE DAC->CR|=0x00000000; // DAC
CHANNEL 1 ENABLE GPIOA-
>MODER|=0x00000300; //PA4 ANALOG MODE int i
= 0;
while(1)
{
for(i=0; i<4096;
i++) DAC-
>DHR12R1=i;
for(i=4096; i>=0 ; i-
-) DAC-
>DHR12R1=i;
};
}
SINE WAVE GENERATION
#include
"stm32f4xx.h"
#include
"stdio.h" int
main()
{
RCC->APB1ENR|=0x20000000; // DAC CLOCK
ENABLE DAC->CR|=0x00000000; // DAC
CHANNEL 1 ENABLE GPIOA-
>MODER|=0x00000300; //PA4 ANALOG MODE int i
= 0;
int
x[]={2048,2177,2305,2432,2557,2681,2802,2920,3035,3145,3252,3353,3450,3541,3626,3705,
3777,3843,3901,3952,3996,4032,4060,4080,4092,4096,4092,4080,4060,4032,3996,3952,3901,38
43,3777
,
3705,3626,3541,3450,3353,3252,3145,3035,2920,2802,2681,2557,2432,2305,2177,2048,1919,17
91,1664
,
1539,1415,1294,1176,1061,951,844,743,646,555,470,391,319,253,195,144,100,64,36,16,4,0,4,16,
36,64,
100,144,195,253,319,391,470,555,646,743,844,951,1061,1176,1294,1415,1539,1664,1791,1919,2
048};
while(1)
{
for(i=0; i<100 ; i++)
DAC->DHR12R1=x[i];
};
}
Square wave generation
#include
"stm32f4xx.h"
#include
"stdio.h" int
main()
{
RCC->APB1ENR|=0x20000000; // DAC CLOCK
ENABLE DAC->CR|=0x00000000; // DAC
CHANNEL 1 ENABLE GPIOA-
>MODER|=0x00000300; //PA4 ANALOG MODE int i
= 0;
while(1)
{
for(i=0; i<4096;
i++); DAC-
>DHR12R1=i;
for(i=4096; i>=0 ; i--
); DAC-
>DHR12R1=i;
};
}

Result:
Experiment : 7(a)
Date :
FLASHING OF LEDS
Aim
To develop an embedded ‘C’ program for flashing the LED with various time delay.

Apparatus & Software Required


1. Vi – STM32 development board
2. IAR workbench
3. Flash Loader Demonstrator
4. USB cable
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. Create a new project.


2. Type the code and save the file with extension .C in the project.
3. Add the necessary files to the project.
4. Create the output file in the format .hex for downloading the code into the processor.
5. Build the project and compile it.
6. Download the hex file into the processor with the help of flash loader.
7. After downloading the program change the board to execution mode and reset it.
8. View the LED blinking with given delay.
Program:

#include "stm32f4xx.h"
#include "stdio.h" void
delay(long int a)
{
long int b,c;
for (b=0 ; b<a; b++)
for (c=0 ; c<a; c++);
}
void LED_init()
{
RCC->AHB1ENR = 1<<5;
GPIOF->MODER = 0x55555555;
GPIOF->OTYPER = 0x00000000;
GPIOF->OSPEEDR = 0xAAAAAAAA;
GPIOF->PUPDR = 0x00000000;
}
void main()
{
LED_init();
while(1)
{
GPIOF->ODR = 0x0000000F;
delay(3000);
GPIOF->ODR = 0x00000000;
delay(3000);
}
}

Result:
Experiment : 7(b)
Date :
INTERFACING LCD
Aim

To develop a embedded 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.

Apparatus & Software Required


1. VI – STM32 syllabus board.
2. IAR Workbench.
3. Flash Loader Demonstrator.

Theory:

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.

CHARACTER BASED LCD


A standard character LCD is probably the most widely used data Visualization component.
Character LCDs are available in various kinds of models.
 No. Of characters x Lines: 8x1, 16x1, 16x2, 16x4, 20x4, 40x4…
 Color: Yellow, Green, Gray, Blue…

The Character LCD communicates with the microcontroller via 8 bit data bus. The pin
description for character LCD is given below.
VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively; V0 is used
for controlling LCD contrast

RS (Register Select) - If RS = 0, the instruction command code register is selected, allowing the
user to send a command such as clear display, cursor at home, etc.
If RS = 1, the data register is selected, allowing the user to send data to be displayed on the LCD.

RW (Read/Write) - RW allows the user to write information to the LCD or read information
from it. RW=1 when reading; RW=0 when writing.

EN (Enable) - The LCD to latch information presented to its data pins uses the enable pin. When
data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD
to latch in the data present at the data pins.

D0 – D7 - The 8-bit data pins, are used to send information to the LCD or read the contents of
the LCD’s internal registers. To display letters and numbers, we send ASCII codes for the letters
A-Z, a-z, and numbers 0-9 to these pins while making RS = 1.
LCD CONNECTION

Procedure:

1. Create a new project.


2. Type the code and save the file with extension .C in the project.
3. Add the necessary files to the project.
4. Create the output file in the format .hex for downloading the code into the processor.
5. Build the project and compile it.
6. Download the hex file into the processor with the help of flash loader.
7. After downloading the program change the board to execution mode and reset it.
8. The corresponding sentence will be displayed in LCD.

Program:

#include "stm32f4xx.h"

void delay() {
int i,j;
for(i=0;i<0xff;i++)
for(j=0;j<0xff;j++);
}

void busy_check() {
delay();
GPIOB->BSRRH = 0x0020;
}
void command_write(int comm) {
busy_check();
GPIOG->ODR = comm << 8;
GPIOC->BSRRL = 0x0040;
delay();
GPIOC->BSRRH = 0x0040;
}

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();
GPIOB->BSRRL = 0x0020;
GPIOG->ODR = a << 8;
GPIOC->BSRRL = 0x0040;
delay();
GPIOC->BSRRH = 0x0040;
}

void lcd_write(uint32_t line,unsigned char data[16]) {


command_write(line); // LINE
for(int i=0;data[i]!='\0';i++) {
lcd_out(data[i]);
delay();
delay();
}
}

void GPIO_Config(GPIO_TypeDef* GPIOx,uint32_t mode){


GPIOx->MODER |= mode;
GPIOx->OTYPER = 0x00000000;
GPIOx->PUPDR = 0x00000000;
GPIOx->OSPEEDR = 0xFFFFFFFF;
}

void pin_config(void){
// Enable the clock for PB,PC,PF,PG ports
RCC->AHB1ENR |= ( 1 << 1 ) | ( 1 << 2 ) | ( 1 << 5 ) | ( 1 << 6 );

GPIO_Config( GPIOB,0x00000400) ;
GPIO_Config( GPIOC,0x00001000) ;
GPIO_Config( GPIOG,0x55550000) ;

int main(void){
pin_config();
lcd_init();

unsigned char a[] = {" WELCOME TO LCD "};


unsigned char b[] = {" STM32f407ZG "};

lcd_write(0x80,a);
delay();
lcd_write(0xc0,b);

Result:
Experiment : 8(a)
Date :
INTERFACING KEYBOARD

Aim
To develop a embedded 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.

Apparatus & Software Required


1. VI – STM32 syllabus board.
2. IAR Workbench.
3. Flash Loader Demonstrator.

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.

KEYBOARD CONNECTION
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.

CHARACTER BASED LCD


A standard character LCD is probably the most widely used data Visualization component.
Character LCDs are available in various kinds of models.
 No. Of characters x Lines: 8x1, 16x1, 16x2, 16x4, 20x4, 40x4…
 Color: Yellow, Green, Gray, Blue…

The Character LCD communicates with the microcontroller via 8 bit data bus. The pin
description for character LCD is given below.
VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively; V0 is used
for controlling LCD contrast

RS (Register Select) - If RS = 0, the instruction command code register is selected, allowing the
user to send a command such as clear display, cursor at home, etc.
If RS = 1, the data register is selected, allowing the user to send data to be displayed on the LCD.

RW (Read/Write) - RW allows the user to write information to the LCD or read information
from it. RW=1 when reading; RW=0 when writing.

EN (Enable) - The LCD to latch information presented to its data pins uses the enable pin. When
data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD
to latch in the data present at the data pins.

D0 – D7 - The 8-bit data pins, are used to send information to the LCD or read the contents of
the LCD’s internal registers. To display letters and numbers, we send ASCII codes for the letters
A-Z, a-z, and numbers 0-9 to these pins while making RS = 1
LCD CONNECTION

Procedure:

1. Create a new project.


2. Type the code and save the file with extension .C in the project.
3. Add the necessary files to the project.
4. Create the output file in the format .hex for downloading the code into the processor.
5. Build the project and compile it.
6. Download the hex file into the processor with the help of flash loader.
7. After downloading the program change the board to execution mode and reset it.
8. When the switch is pressed the corresponding sentence will be displayed in LCD.

Program:

#include "stm32f4xx.h"

void delay() {
int i,j;
for(i=0;i<0xff;i++)
for(j=0;j<0xff;j++);
}

void busy_check() {
delay();
GPIOB->BSRRH = 0x0020;
}
void command_write(int comm) {
busy_check();
GPIOG->ODR = comm << 8;
GPIOC->BSRRL = 0x0040;
delay();
GPIOC->BSRRH = 0x0040;
}

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();
GPIOB->BSRRL = 0x0020;
GPIOG->ODR = a << 8;
GPIOC->BSRRL = 0x0040;
delay();
GPIOC->BSRRH = 0x0040;
}

void lcd_write(uint32_t line,unsigned char data[16]) {


command_write(line); // LINE
for(int i=0;data[i]!='\0';i++) {
lcd_out(data[i]);
delay();
delay();
}
}

void GPIO_Config(GPIO_TypeDef* GPIOx,uint32_t mode){


GPIOx->MODER |= mode;
GPIOx->OTYPER = 0x00000000;
GPIOx->PUPDR = 0x00000000;
GPIOx->OSPEEDR = 0xFFFFFFFF;
}

void pin_config(void){
// Enable the clock for PB,PC,PF,PG ports
RCC->AHB1ENR |= ( 1 << 1 ) | ( 1 << 2 ) | ( 1 << 5 ) | ( 1 << 6 );

GPIO_Config( GPIOB,0x00000400) ;
GPIO_Config( GPIOC,0x00001000) ;
GPIO_Config( GPIOF,0x00000500) ;
GPIO_Config( GPIOG,0x55550000) ;

int main(void){
pin_config();
lcd_init();

unsigned char a[] = {" WELCOME TO LCD "};


unsigned char b[] = {" STM32f407ZG "};

lcd_write(0x80,a);
delay();
lcd_write(0xc0,b);

unsigned char sw2[] = { " switch 2 " };


unsigned char sw5[] = { " switch 5 " } ;
unsigned char sw3[] = { " switch 3 " };
unsigned char sw6[] = { " switch 6 " } ;

while(1){

/* Read First Column Keys */

GPIOF->BSRRL = 0x0010; //Low F4


GPIOF->BSRRH = 0x0020; //high F5

int val = (GPIOF->IDR)&0xC0; //status of sw5 &sw2

if(val == 0x40){
command_write(0x01);
lcd_write(0x80,sw5);
}
else if(val == 0x80){
command_write(0x01);
lcd_write(0x80,sw2);
}

/* Read Second Column Keys */

GPIOF->BSRRH = 0x0010; //high PF4


GPIOF->BSRRL = 0x0020; //low PF5

val = (GPIOF->IDR)& 0xC0;//status of sw3 &sw6

if(val == 0x40){
command_write(0x01);
lcd_write(0x80,sw6);
}
else if(val == 0x80){
command_write(0x01);
lcd_write(0x80,sw3);
}

}
}
Experiment : 8(b)
Date :
INTERFACING STEPPER MOTOR
Aim:
To write C Programs for running stepper motor either in clock-wise or counter-clockwise
direction.

Apparatus & Software Required:

1. VI – STM32 syllabus board.


2. IAR Workbench.
3. Flash Loader Demonstrator.
4. Stepper motor

Theory:

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 he 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 précised angle. There are two basic
arrangements for the electromagnetic coils they are bipolar and unipolar.

The four input pins are PF13, PF14, PF15 and PD11.the ULN2003 driver IC supplies 5v
output to stepper motor. If the input pulse sequence is 1001,0101,0110,1010 means
stepper motor rotates in forward direction. If the input pulse sequence is
1010,0110,0101,1001 means stepper motor rotates in forward direction
Procedure:

1. Create a new project.


2. Type the code and save the file with extension .C in the project.
3. Add the necessary files to the project.
4. Create the output file in the format .hex for downloading the code into the processor.
5. Build the project and compile it.
6. Download the hex file into the processor with the help of flash loader.
7. After downloading the program change the board to execution mode and reset it.
8. View the motor rotates in the direction according to the code given in the program.

Program:
STEPPER.C
#include "stm32f4xx.H"
#include "stdio.h"
void delay(long int a)
{
long int b,c;
for (b=0; b<a; b++)
{
for (c=0; c<a; c++)
{
{}
}
}
}
void stepper_init()
{
RCC->AHB1ENR|=1<<5; //ENABLE PORT F
GPIOF->MODER = 0x55555555; //PORTF AS OUTPUT MODE
GPIOF->OTYPER = 0x00000000; // PUSH PULL TYPE - PORT F
GPIOF->OSPEEDR = 0xAAAAAAAA; // PORT F 50 MHz SPEED
GPIOF->PUPDR =0x00000000; // PORT F NO PULL NO PUSH
RCC->AHB1ENR|=1<<3; //ENABLE PORT D
GPIOD->MODER = 0x55555555; // PORT D OUTPUT MODE
GPIOD->OTYPER = 0x00000000; // PUSH PULL TYPE - PORT D
GPIOD->OSPEEDR = 0xAAAAAAAA; // PORT D 50 MHz SPEED
GPIOD->PUPDR =0x00000000; // PORT D NO PULL NO PUSH
}
void main()
{
stepper_init();
while(1)
{
GPIOF->ODR = 0x00002000; // SETTING PF13
GPIOD->ODR = 0x00000800; // SETTING PD11
delay (3000);
GPIOF->ODR = 0x00004000; // SETTING PF14
GPIOD->ODR = 0x00000800; // SETTING PD11
delay (3000);
GPIOF->ODR = 0x0000C000; // SETTING PF14 AND PF15
GPIOD->ODR = 0x00000000; // SETTING -PORT D AS 0
delay (3000);
GPIOF->ODR = 0x0000A000; // SETTING PF13 AND PF15
GPIOD->ODR = 0x00000000; // SETTING -PORT D AS 0
delay (3000);
}
}

Result:
Experiment No:9 (a)
Date:
Interfacing sensors with Raspberry PI
AIM

To write an python programming to interface DHT11 Sensor with Raspberry Pi

APPARATUS REQUIRED

 Raspberry Pi-4
 Micropython- Thonny
 DHT11 sensor

PROCEDURE
1. Make the connections as per the instructions.
2. Connect the Raspberry Pi board to a monitor.

3. Click the terminal icon .


4. Type sudo nano exp8_dht11.py and click Enter. A new file will open.
5. Type the given program and save it by pressing Ctrl+O, then press Enter then press
Ctrl+X.
6. Type sudo python exp8_dht11.py and click Enter.
7. You will observe that Raspberry Pi displays the DHT11 temperature and Humidity data
on the screen.
PROGRAM
DHT 11 Sensor (Temperature and Humidity Sensor)
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 4
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))

CONNECTION :
OUTPUT

RESULT
Experiment No:9 (b)
Date:
Interfacing sensors with Raspberry PI

AIM

To write an python programming to interface LDR Sensor with Raspberry Pi

APPARATUS REQUIRED

 Raspberry Pi-4
 Micropython- Thonny
 LDR sensor

PROCEDURE

1. Make the connections as per the instructions.


2. Connect the Raspberry Pi board to a monitor.

3. Click the terminal icon .


4. We are using PCF8591T ADC chip which has an inbuilt LDR sensor whose address is
0x42.
5. Type sudo nano exp8_ldr.py and click Enter. A new file will open.
6. Type the given program and save it by pressing Ctrl+O, then press Enter then press
Ctrl+X.
7. Type sudo python exp8_ldr.py and click Enter.
8. You will observe that Raspberry Pi displays 1 whenever light is low and 0 whenever
light more is.
PROGRAM:
importsmbus
import time
address = 0x48
bus = smbus.SMBus(1)
address = 0x48
ldr_add = 0x42
while True:
bus.write_byte(address,ldr_add)
value = bus.read_byte(address)
print(value)
time.sleep(0.1)

CONNECTION
OUTPUT

RESULT
Experiment No:10
Date:
Interfacing Pi camera with Raspberry PI

AIM

To write an python programming to interface LM35 Sensor with Raspberry Pi

APPARATUS REQUIRED

 Raspberry Pi-4
 Micropython- Thonny
 Pi camera

PROCEDURE

1. Make the connections as given above in the instructions.


2. Connect the Raspberry Pi board to a monitor.

3. Click the terminal icon .


4. Type sudo nano cam.py and click Enter. A new file will open.
5. Type the given program and save it by pressing Ctrl+O, then press Enter then press
Ctrl+X.
6. Type sudo python cam.pyand click Enter.
7. Raspberry Pi saves the captured images in the drive.
PROGRAM
from picamera import PiCamera
import time

camera = PiCamera()
camera.resolution = (1280, 720)
camera.vflip = True
camera.contrast = 10
camera.image_effect = "watercolor"
time.sleep(2)

camera.capture("/home/pi/Pictures/img.jpg")
print("Done.")

CONNECTION:

OUTPUT:

RESULT:

You might also like