MBES - Lab 10-12 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

Student Workbook EE-07310: Microprocessor based Embedded Systems

LABORATORY SESSION # 10
10 Interfacing of 16x2 LCD with STM32F100xx

10.1 EQUIPMENT & MATERIAL REQUIRED

- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________

10.2 PRE-LAB PREPARATIONS

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

10.3 PROCEDURE
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

1
Student Workbook EE-07310: Microprocessor based Embedded Systems

10.4 OBSERVATION & RESULTS

- Complete code of ‘main()’ function in ‘main.c’ file

#include "main.h"
#include "LED.h"
#include "LCD.h"

void Cyclic_Start(const uint16_t PERIOD)


{
RCC_APB1ENR |= 0x00000001;
TIM2_CR1 = 0;
TIM2_CNT = 0;
TIM2_PSC = 7999;
if(PERIOD > 1)
{
TIM2_ARR = (PERIOD-1);
}
else
{
TIM2_ARR = 1;
}
TIM2_CR1 = 0x0001;
}

void Cyclic_Wait(void)
{
while((TIM2_SR & 0x00000001)==0)
{
}
TIM2_SR = 0; //
}

int main(void)
{
uint16_t Count = 0;
LED_Init();
LCD_Init();
Cyclic_Start(10);
while(1)
{
if(++Count >= 50)

2
Student Workbook EE-07310: Microprocessor based Embedded Systems

{
Count = 0;
LED_Toggle(); //Task A
LCD_Write_Str_To_Buff("ANIQUE AHMED ", 16, 0);
LCD_Write_Str_To_Buff("BSEE-01153157 ", 16, 16);
}
LCD_Update(); //Task B

Cyclic_Wait();
}
return(1);
}

void SystemInit(void)
{
}

Figure 10.1:Complete main.c code in Keil µVision 4

- Hardware pictures of LCD displaying your Reg #

Figure 10.2:Hardware setup with Reg # displaying on LCD

3
Student Workbook EE-07310: Microprocessor based Embedded Systems

10.5 LEARNING OUTCOMES

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

10.6 EXERCISE QUESTIONS

- Differentiate the following two functions in LCD library


1. LCD_Write_Char_To_Buff()
2. LCD_Write_Str_To_Buff()

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

- Modify the code to display a message of 16 characters in line 2 only

if(++Count >= 50)


{
Count = 0;
LED_Toggle(); //Task A
LCD_Write_Str_To_Buff(" ", 16, 0);
LCD_Write_Str_To_Buff("Whats up mate ", 16, 16);
}

Figure 10.3:Modified code section

4
Student Workbook EE-07310: Microprocessor based Embedded Systems

Figure 10.4:LCD picture displaying the message in line 2

- Outline the changes in the code to scroll a message of 20 characters on Line 1


or Line 2 only.

if(++Count >= 2)
{
Count = 0;
LCD_Update();
}
if(++Count_1> 100)
{
LED_Toggle();
Count_1 = 0;
LCD_Write_Str_To_Buff("DuckDuckGO NOT GOOD! ", 21, Count_2);
LCD_Write_Str_To_Buff(" ", 16,16 );
--Count_2;
if(Count_2 < -31)
{
Count_2 = 0;
}

Figure 10.5:‘main.c’ code

5
Student Workbook EE-07310: Microprocessor based Embedded Systems

Figure 10.6:Message displaying on the LCD

- Conclude the function of ‘LED.c’ file and ‘LED_Toggle()’ function.

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

6
Student Workbook EE-07310: Microprocessor based Embedded Systems

GENERALIZED LAB RUBRICS


Component Above Meeting Approaching Below Weight / Score
Domain with Expectation Expectation Expectation Expectation Used 100
(1–4)
Taxonomy (4) (3) (2) (1) (Optional)

Is able to build a given


setup neatly and timely Is able to assemble Is not able to
Psychomotor

Is only able to copy


Building using correct hardware a given setup using assemble a given
(Hardware) components and / or correct hardware
a given setup using
setup using 
correct hardware
P4 can reorganize / adapt components after correct hardware
components
to new / special minor revisions components
requirements
Recording
Is able to record Is only able to
Measurements Is able to record Is unable to
(Hardware / accurate measurements
accurate record accurate
record accurate ☐
measurements most measurements on
Software) all the time measurements
of the time some occasions
C3
Is able to formulate
Is partially able to
/develop theories in Is able to evaluate
Investigation evaluate /conclude Is unable to
addition to evaluating /conclude correctly
(Hardware /
/concluding correctly about investigation
correctly about comprehend 
Software) investigation investigation
about investigation parameters by
C5 parameters by parameters
parameters by assessing assessing data
assessing data
data
Design /
Is unable to
Development Is able to design / Is able to partially
Is able to design / partially design /
Cognitive

of Solution develop the solution of design / develop the ☐


develop the solution develop the
(Hardware / a given problem and solution of a given
of a given problem solution of a
Software) add features to it problem
given problem
C6
Is able to use the
Software Is adept in the use of Is able to use the
software tool
Usage software tool and can
effectively by
software tool but Is unable to use 
(Software) access advanced cannot access all the the software tool
accessing all the
C3 features required features
required features
Is able to efficiently
Is able to complete
complete a given task
a given task using
Programming using advanced Is unable to
required Is able to partially
Language programming language
programming complete a given
partially 
(Software) constructs / methods / complete a given
language constructs task
C3–C6 commands and/or add task
/ methods /
features to the original
commands
task

7
Student Workbook EE-07310: Microprocessor based Embedded Systems

GENERALIZED LAB RUBRICS

Component Above Approaching Below


Meeting Expectation Use Weight Score
Domain with Expectation Expectation Expectation / 100
(3) d (1–4)
Taxonomy (4) (2) (1) (Optional)

Safety Assesses and Assesses and complies Assesses and complies Assesses and
Instructions complies with all with most EHS with some EHS complies with ☐
(PLO6) EHS instructions instructions while in instructions while in few EHS
A4 while in lab lab lab instructions in lab
Does not exhibit
Exhibits exemplary Makes an effort to professional
Professional Exhibits professional
professional ethics exhibit professional ethics while
Ethics ethics while dealing
while dealing with
with fellow students,
ethics while dealing dealing with ☐
(PLO8) fellow students, lab with fellow students, fellow students,
A3 lab staff and instructor
staff and instructor lab staff and instructor lab staff and
all the time
all the time all the time instructor all the
time
Consistently shows
Shows some
full preparation by
Consistently shows full preparation which is Shows very little
Contribution completing all
preparation by mostly at superficial or no preparation
(PLO9) agreed tasks and
completing all agreed level in completing a in completing a 
A5 provides additional
tasks and work requires task and work requires task and work
resources for the
Affective

little or no revisions much revisions and quality is poor


group and work
editing
quality is excellent
Internalized positive
Attitude Consistent positive Neither helpful nor Discouraging
behavior and
(PLO9) encourages and
behavior most of the damaging and shows behavior towards ☐
A5 time towards other disinterest in the other team
helps other team
team members performance of others members
members
Report on all Report on all relevant Report on all relevant
relevant sections sections related to the sections related to the
Report related to the lab lab tasks is completed lab tasks is completed Report on all
Writing tasks is completed but few deficiencies but many deficiencies relevant sections
accurately, meeting are present in terms of are present in terms of related to the lab ☐
(PLO10)
A2 the requirements, in accuracy / meeting the accuracy / meeting the tasks is not
prescribed time and requirements / requirements / completed
with good language prescribed time / good prescribed time / good
skills language skills language skills
Lab Task Does not manage
Management Manages tasks well
within given
Manages tasks within Manages tasks in an tasks even in ☐
(PLO11) given timeframe extended timeframe extended
A3 timeframe
timeframes

8
Student Workbook EE-07310: Microprocessor based Embedded Systems

LABORATORY SESSION # 11
11 Interfacing of 4x4 Matrix Keypad with STM32F100xx
11.1 EQUIPMENT & MATERIAL REQUIRED

- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________

11.2 PRE-LAB PREPARATIONS

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

11.3 PROCEDURE
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

9
Student Workbook EE-07310: Microprocessor based Embedded Systems

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Algorithm:

Figure 11.1:Algorithm for 4x4 matrix keypad

10
Student Workbook EE-07310: Microprocessor based Embedded Systems

Keypad pin # STM32F100xx pins


1 (row) PA0
2 (row) PA1
3 (row) PA2
4 (row) PA3
5 (column) PA4
6 (column) PA5
7 (column) PA6
8 (column) PA7
Table 11.1:STM32F100xx pins connection with 4x4 matrix keypad

11.4 OBSERVATION & RESULTS

- Complete code from all C and H files

main.c

#include "main.h"
#include "delay.h"
#include "keypad4x4.h"
#include "LCD.h"

void SystemInit(void)
{
}

int main(void)
{
LCD_Init();
Keypad4x4_Init();
LED_Init();

while(1)
{
Scan4x4();
}
}

2
Student Workbook EE-07310: Microprocessor based Embedded Systems

delay.c
#include "main.h"
#include "delay.h"

void Cyclic_Wait(const unsigned short PERIOD)


{
RCC_APB2ENR |= 0x00010000; // Enabling clock to TIM15
TIM15_CR1 = 0;
TIM15_CNT = 0;
TIM15_PSC = 7999; // Resolution of 1ms
if(PERIOD > 1)
{
TIM15_ARR = (PERIOD-1);
}
else
{
TIM15_ARR = 1;
}
TIM15_CR1 |= 0x0001;
while((TIM15_SR & 0x00000001)==0);
TIM15_SR = 0;
TIM15_CR1 = 0;
}

void LED_PC8_Toggle(void)
{
static int LED = 0;
if(LED)
{
GPIOC_ODR |= 0x0100;
LED = 0;
}
else
{
GPIOC_ODR &= 0xFEFF;
LED = 1;
}
}

void LED_Init(void)
{
RCC_APB2ENR |= 0x00000010;
GPIOC_CRH &= 0xFFFFFF00;
GPIOC_CRH |= 0x00000011;
GPIOC_ODR = 0;
}

void LED_PC9_On(void)
{

3
Student Workbook EE-07310: Microprocessor based Embedded Systems

GPIOC_ODR |= 0x0200;
}

void LED_PC9_Off(void)
{
GPIOC_ODR &= 0xFDFF;
}

delay.h

#ifndef _DELAY_H
#define _DELAY_H

void Cyclic_Wait(const unsigned short PERIOD);


void LED_PC8_Toggle(void);
void LED_Init(void);
void LED_PC9_On(void);
void LED_PC9_Off(void);

#endif

4
Student Workbook EE-07310: Microprocessor based Embedded Systems

keypad4x4.c
#include "main.h"
#include "LCD.h"
#include "delay.h"
#include "keypad4x4.h"

#define column1_set 0x00000010


#define column1_reset 0x00100000
#define column2_set 0x00000020
#define column2_reset 0x00200000
#define column3_set 0x00000040
#define column3_reset 0x00400000
#define column4_set 0x00000080
#define column4_reset 0x00800000

#define Period 400

unsigned short count = 15;

void Keypad4x4_Init(void)
{
RCC_APB2ENR |= 0x00000004; // Enabling Clock To Port A
GPIOA_CRL &= 0x00000000;
GPIOA_CRL |= 0x11118888; //PA0_PA3 General Purpose Input pull
down input (ROWS 1-4) and PA4-PA7 pushpull output (COLUMNS 1-4)
LCD_Write_Str_To_Buff("Push Any Button:",16,0);
LCD_Update();
LCD_Write_Str_To_Buff(" ",16,16);
LCD_Update();
LCD_Update();
}

void Scan4x4(void)
{
if(count==31)
{
LCD_Write_Str_To_Buff(" ",16,16);
count = 15;
}
/*----Column ONE is ON and remainig columns OFF----*/
GPIOA_BSRR =
column1_set|column2_reset|column3_reset|column4_reset;
if((GPIOA_IDR & 0x00000001) != 0) //read only row one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('1',++count);

5
Student Workbook EE-07310: Microprocessor based Embedded Systems

if((GPIOA_IDR & 0x00000002) != 0) //read row number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('4',++count);
}
if((GPIOA_IDR & 0x00000004) != 0) //read row number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('7',++count);
}
if((GPIOA_IDR & 0x00000008) != 0) //read row number 4
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('*',++count);
}

/*----Column TWO is ON and remainig columns OFF----*/


GPIOA_BSRR =
column1_reset|column2_set|column3_reset|column4_reset;
if((GPIOA_IDR & 0x00000001) != 0) //read only row one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('2',++count);
}

if((GPIOA_IDR & 0x00000002) != 0) //read row number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('5',++count);
}
if((GPIOA_IDR & 0x00000004) != 0) //read row number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('8',++count);
}
if((GPIOA_IDR & 0x00000008) != 0) //read row number 4
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('0',++count);
}

/*----Column THREE is ON and remainig columns OFF----*/


GPIOA_BSRR =
column1_reset|column2_reset|column3_set|column4_reset;
if((GPIOA_IDR & 0x00000001) != 0) //read only row one
{
Cyclic_Wait(Period);

6
Student Workbook EE-07310: Microprocessor based Embedded Systems

LCD_Write_Char_To_Buff('3',++count);
}

if((GPIOA_IDR & 0x00000002) != 0) //read row number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('6',++count);
}
if((GPIOA_IDR & 0x00000004) != 0) //read row number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('9',++count);
}
if((GPIOA_IDR & 0x00000008) != 0) //read row number 4
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('#',++count);
}

/*----Column FOUR is ON and remainig columns OFF----*/


GPIOA_BSRR =
column1_reset|column2_reset|column3_reset|column4_set;
if((GPIOA_IDR & 0x00000001) != 0) //read only row one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('A',++count);
}

if((GPIOA_IDR & 0x00000002) != 0) //read row number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('B',++count);
}
if((GPIOA_IDR & 0x00000004) != 0) //read row number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('C',++count);
}
if((GPIOA_IDR & 0x00000008) != 0) //read row number 4
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('D',++count);
}
LCD_Update();
}

keypad.h

7
Student Workbook EE-07310: Microprocessor based Embedded Systems

#ifndef _KEYPAD_H
#define _KEYPAD_H

void Keypad_Init(void);
void Keypad_Scan(void);
void Keypad_Scan_After_Off(void);
void Keypad(void);

#endif

Figure 11.2:Complete code in Keil µVision 4


- Successful creation of HEX file

Figure 11.3:0 Errors, 0 Warnings

8
Student Workbook EE-07310: Microprocessor based Embedded Systems

- Hardware pictures for both keypad and LCD

Figure 11.4:Hardware setup

11.5 LEARNING OUTCOMES

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

9
Student Workbook EE-07310: Microprocessor based Embedded Systems

11.6 EXERCISE QUESTIONS

- Assess the changes in the code if the rows are the output and columns are the
input group.

#define row1_set 0x00000001


#define row1_reset 0x00010000
#define row2_set 0x00000002
#define row2_reset 0x00020000
#define row3_set 0x00000004
#define row3_reset 0x00040000
#define row4_set 0x00000008
#define row4_reset 0x00080000

#define Period 400

unsigned short count = 15;

void Keypad4x4_Init(void)
{
RCC_APB2ENR |= 0x00000004; // Enabling Clock To Port A
GPIOA_CRL &= 0x00000000;
GPIOA_CRL |= 0x88881111; /*PA4-PA7 General Purpose Input pull
down input (COLUMNS 1-4)
and PA0_PA3 pushpull output (ROWS 1-4) */
LCD_Write_Str_To_Buff("Push Any Button:",16,0);
LCD_Update();
LCD_Write_Str_To_Buff(" ",16,16);
LCD_Update();
LCD_Update();
}

void Scan4x4(void)
{
if(count==31)
{
LCD_Write_Str_To_Buff(" ",16,16);
count = 15;
}
/*----row ONE is ON and remainig rows OFF----*/
GPIOA_BSRR = row1_set|row2_reset|row3_reset|row4_reset;
if((GPIOA_IDR & 0x00000010) != 0) //read only column one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('1',++count);

10
Student Workbook EE-07310: Microprocessor based Embedded Systems

if((GPIOA_IDR & 0x00000020) != 0) //read column number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('2',++count);
}
if((GPIOA_IDR & 0x00000040) != 0) //read column number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('3',++count);
}
if((GPIOA_IDR & 0x00000080) != 0) //read column number 4
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('A',++count);
}

/*----row TWO is ON and remainig rows OFF----*/


GPIOA_BSRR = row1_reset|row2_set|row3_reset|row4_reset;
if((GPIOA_IDR & 0x00000010) != 0) //read only column one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('4',++count);

if((GPIOA_IDR & 0x00000020) != 0) //read column number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('5',++count);
}
if((GPIOA_IDR & 0x00000040) != 0) //read column number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('6',++count);
}
if((GPIOA_IDR & 0x00000080) != 0) //read column number 4
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('B',++count);
}

/*----row THREE is ON and remainig rows OFF----*/


GPIOA_BSRR = row1_reset|row2_reset|row3_set|row4_reset;
if((GPIOA_IDR & 0x00000010) != 0) //read only column one
{
Cyclic_Wait(Period);

11
Student Workbook EE-07310: Microprocessor based Embedded Systems

LCD_Write_Char_To_Buff('7',++count);

if((GPIOA_IDR & 0x00000020) != 0) //read column number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('8',++count);
}
if((GPIOA_IDR & 0x00000040) != 0) //read column number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('9',++count);
}
if((GPIOA_IDR & 0x00000080) != 0) //read column number 4
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('C',++count);
}

/*----row FOUR is ON and remainig rows OFF----*/


GPIOA_BSRR = row1_reset|row2_reset|row3_reset|row4_set;
if((GPIOA_IDR & 0x00000010) != 0) //read only column one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('*',++count);

if((GPIOA_IDR & 0x00000020) != 0) //read column number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('0',++count);
}
if((GPIOA_IDR & 0x00000040) != 0) //read column number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('#',++count);
}
if((GPIOA_IDR & 0x00000080) != 0) //read column number 4
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('D',++count);
}
LCD_Update();
}
Figure 11.5:Changes in the code

12
Student Workbook EE-07310: Microprocessor based Embedded Systems

- Modify the program such that if there is a 4x3 matrix keypad instead of 4x4.

#include "main.h"
#include "LCD.h"
#include "delay.h"
#include "keypad4x3.h"

#define row1_set 0x00000001


#define row1_reset 0x00010000
#define row2_set 0x00000002
#define row2_reset 0x00020000
#define row3_set 0x00000004
#define row3_reset 0x00040000
#define row4_set 0x00000008
#define row4_reset 0x00080000

#define Period 400

unsigned short count = 15;

void Keypad4x3_Init(void)
{
RCC_APB2ENR |= 0x00000004; // Enabling Clock To Port A
GPIOA_CRL &= 0xF0000000;
GPIOA_CRL |= 0x08881111; /*PA4-PA6 General Purpose Input pull
down input (COLUMNS 1-4)
and PA0_PA3 pushpull output (ROWS 1-4) */
LCD_Write_Str_To_Buff("Push Any Button:",16,0);
LCD_Update();
LCD_Write_Str_To_Buff(" ",16,16);
LCD_Update();
LCD_Update();
}

void Scan4x3(void)
{
if(count==31)
{
LCD_Write_Str_To_Buff(" ",16,16);
count = 15;
}
/*----row ONE is ON and remainig rows OFF----*/
GPIOA_BSRR = row1_set|row2_reset|row3_reset|row4_reset;
if((GPIOA_IDR & 0x00000010) != 0) //read only column one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('1',++count);

13
Student Workbook EE-07310: Microprocessor based Embedded Systems

if((GPIOA_IDR & 0x00000020) != 0) //read column number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('2',++count);
}
if((GPIOA_IDR & 0x00000040) != 0) //read column number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('3',++count);
}

/*----row TWO is ON and remainig rows OFF----*/


GPIOA_BSRR = row1_reset|row2_set|row3_reset|row4_reset;
if((GPIOA_IDR & 0x00000010) != 0) //read only column one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('4',++count);

if((GPIOA_IDR & 0x00000020) != 0) //read column number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('5',++count);
}
if((GPIOA_IDR & 0x00000040) != 0) //read column number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('6',++count);
}

/*----row THREE is ON and remainig rows OFF----*/


GPIOA_BSRR = row1_reset|row2_reset|row3_set|row4_reset;
if((GPIOA_IDR & 0x00000010) != 0) //read only column one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('7',++count);

if((GPIOA_IDR & 0x00000020) != 0) //read column number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('8',++count);

14
Student Workbook EE-07310: Microprocessor based Embedded Systems

}
if((GPIOA_IDR & 0x00000040) != 0) //read column number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('9',++count);
}

/*----row FOUR is ON and remainig rows OFF----*/


GPIOA_BSRR = row1_reset|row2_reset|row3_reset|row4_set;
if((GPIOA_IDR & 0x00000010) != 0) //read only column one
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('*',++count);

if((GPIOA_IDR & 0x00000020) != 0) //read column number 2


{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('0',++count);
}
if((GPIOA_IDR & 0x00000040) != 0) //read column number 3
{
Cyclic_Wait(Period);
LCD_Write_Char_To_Buff('#',++count);
}

LCD_Update();
}

Figure 11.6:Code for 4x3 matrix keypad

15
Student Workbook EE-07310: Microprocessor based Embedded Systems

GENERALIZED LAB RUBRICS


Component Above Meeting Approaching Below Weight / Score
Domain with Expectation Expectation Expectation Expectation Used 100
(1–4)
Taxonomy (4) (3) (2) (1) (Optional)

Is able to build a given


setup neatly and timely Is able to assemble Is not able to
Psychomotor

Is only able to copy


Building using correct hardware a given setup using assemble a given
(Hardware) components and / or correct hardware
a given setup using
setup using 
correct hardware
P4 can reorganize / adapt components after correct hardware
components
to new / special minor revisions components
requirements
Recording
Is able to record Is only able to
Measurements Is able to record Is unable to
(Hardware / accurate measurements
accurate record accurate
record accurate ☐
measurements most measurements on
Software) all the time measurements
of the time some occasions
C3
Is able to formulate
Is partially able to
/develop theories in Is able to evaluate
Investigation evaluate /conclude Is unable to
addition to evaluating /conclude correctly
(Hardware /
/concluding correctly about investigation
correctly about comprehend 
Software) investigation investigation
about investigation parameters by
C5 parameters by parameters
parameters by assessing assessing data
assessing data
data
Design /
Is unable to
Development Is able to design / Is able to partially
Is able to design / partially design /
Cognitive

of Solution develop the solution of design / develop the ☐


develop the solution develop the
(Hardware / a given problem and solution of a given
of a given problem solution of a
Software) add features to it problem
given problem
C6
Is able to use the
Software Is adept in the use of Is able to use the
software tool
Usage software tool and can
effectively by
software tool but Is unable to use 
(Software) access advanced cannot access all the the software tool
accessing all the
C3 features required features
required features
Is able to efficiently
Is able to complete
complete a given task
a given task using
Programming using advanced Is unable to
required Is able to partially
Language programming language
programming complete a given
partially 
(Software) constructs / methods / complete a given
language constructs task
C3–C6 commands and/or add task
/ methods /
features to the original
commands
task

16
Student Workbook EE-07310: Microprocessor based Embedded Systems

GENERALIZED LAB RUBRICS

Component Above Approaching Below


Meeting Expectation Use Weight Score
Domain with Expectation Expectation Expectation / 100
(3) d (1–4)
Taxonomy (4) (2) (1) (Optional)

Safety Assesses and Assesses and complies Assesses and complies Assesses and
Instructions complies with all with most EHS with some EHS complies with ☐
(PLO6) EHS instructions instructions while in instructions while in few EHS
A4 while in lab lab lab instructions in lab
Does not exhibit
Exhibits exemplary Makes an effort to professional
Professional Exhibits professional
professional ethics exhibit professional ethics while
Ethics ethics while dealing
while dealing with
with fellow students,
ethics while dealing dealing with ☐
(PLO8) fellow students, lab with fellow students, fellow students,
A3 lab staff and instructor
staff and instructor lab staff and instructor lab staff and
all the time
all the time all the time instructor all the
time
Consistently shows
Shows some
full preparation by
Consistently shows full preparation which is Shows very little
Contribution completing all
preparation by mostly at superficial or no preparation
(PLO9) agreed tasks and
completing all agreed level in completing a in completing a 
A5 provides additional
tasks and work requires task and work requires task and work
resources for the
Affective

little or no revisions much revisions and quality is poor


group and work
editing
quality is excellent
Internalized positive
Attitude Consistent positive Neither helpful nor Discouraging
behavior and
(PLO9) encourages and
behavior most of the damaging and shows behavior towards ☐
A5 time towards other disinterest in the other team
helps other team
team members performance of others members
members
Report on all Report on all relevant Report on all relevant
relevant sections sections related to the sections related to the
Report related to the lab lab tasks is completed lab tasks is completed Report on all
Writing tasks is completed but few deficiencies but many deficiencies relevant sections
accurately, meeting are present in terms of are present in terms of related to the lab ☐
(PLO10)
A2 the requirements, in accuracy / meeting the accuracy / meeting the tasks is not
prescribed time and requirements / requirements / completed
with good language prescribed time / good prescribed time / good
skills language skills language skills
Lab Task Does not manage
Management Manages tasks well
within given
Manages tasks within Manages tasks in an tasks even in ☐
(PLO11) given timeframe extended timeframe extended
A3 timeframe
timeframes

17
Student Workbook EE-07310: Microprocessor based Embedded Systems

LABORATORY SESSION # 12
12 Manual Speed Control of a DC Motor using Keypad and LCD
with STM32F100xx [Open Ended Lab]

12.1 EQUIPMENT & MATERIAL REQUIRED

- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________

12.2 PRE-LAB PREPARATIONS

_____________________________________________________________________
_____________________________________________________________________

12.3 PROCEDURE
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

18
Student Workbook EE-07310: Microprocessor based Embedded Systems

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

12.4 OBSERVATION & RESULTS

- Complete code

main.c
#include "main.h"
#include "delay.h"
#include "keypad4x4.h"
#include "LCD.h"
#include "PWM.h"

void SystemInit(void)
{
}

int main(void)
{
LCD_Init();
Keypad4x4_Init();
LED_Init();

PWM_Init();
BP = 0x0000;
GPIOC_ODR = 0x0100;
while(1)
{

Scan4x4();

if ( ((BP & B5)!=0) && ((BP & B8)!=0) ) //20%


{
Duty_Vary_Ch_1(4000);
BP = 0x0000;

}
if ( ((BP & B6)!=0) && ((BP & B8)!=0) ) //50%
{
Duty_Vary_Ch_2(10000);

19
Student Workbook EE-07310: Microprocessor based Embedded Systems

BP = 0x0000;

}
if ( ((BP & B7)!=0) && ((BP & B8)!=0) ) //80%
{
Duty_Vary_Ch_1(16000);
BP = 0x0000;

}
}

Figure 12.1: Complete main.c code

20
Student Workbook EE-07310: Microprocessor based Embedded Systems

- Pictures of overall hardware setup

Figure 12.2: Complete hardware setup


- Record the speed of motor for different entered %age values of duty cycle
(20%, 50% & 80%)

Duty cycle 20%:


Speedof motor on meter Duty Cycle on LCD

Figure 12.3:Speed of motor with duty cycle 20%

Duty cycle 50%:

Speed of motor on meter Duty Cycle on LCD

Figure 12.4:Speed of motor with duty cycle 50%

21
Student Workbook EE-07310: Microprocessor based Embedded Systems

Duty cycle 80%:


Speed of motor on meter Duty Cycle on LCD

Figure 12.5:Speed of motor with duty cycle 80%

12.5 LEARNING OUTCOMES

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

22
Student Workbook EE-07310: Microprocessor based Embedded Systems

12.6 EXERCISE QUESTIONS

- Modify the program such that it takes input from the keypad to rotate the
motor clockwise or anticlockwise

main.c
#include "main.h"
#include "delay.h"
#include "keypad4x4.h"
#include "LCD.h"
#include "PWM.h"

void SystemInit(void)
{
}

int main(void)
{
LCD_Init();
Keypad4x4_Init();
LED_Init();

PWM_Init();
BP = 0x0000;
GPIOC_ODR = 0x0100;
while(1)
{

Scan4x4();

if ( ((BP & B1)!=0) ) //foward50%


{
Duty_Vary_Ch_1(10000); //TIM1_CCR1 : PA6 to left pin 1
BP = 0x0000;

}
if ( ((BP & B5)!=0) ) //reverse50%
{
Duty_Vary_Ch_2(10000); //TIM1_CCR2 : PA7 to left pin 2
BP = 0x0000;

}
}
Figure 12.6: main.c code

23
Student Workbook EE-07310: Microprocessor based Embedded Systems

This open–ended lab also qualifies as a Complex Engineering Problem as it meets the
criterion 1 and criterion 3.

S# Attribute Complex Problems = 1 &(2 | 3 | 4 | 5 | 6 | 7 | 8 | 9)

Engineering problems which cannot be resolved


1 Preamble without in-depth engineering knowledge, and have ☒
some or all of the characteristics listed below:

Range of conflicting Involve wide-ranging or conflicting technical,


2 ☐
requirements engineering and other issues.

Have no obvious solution and require abstract


3 Depth of analysis required thinking, originality in analysis to formulate suitable ☒
models.

Requires research-based knowledge much of which is


Depth of knowledge at, or informed by, the forefront of the professional
4 ☐
required discipline and which allows a fundamentals-based,
first principles analytical approach.

5 Familiarity of issues Involve infrequently encountered issues ☐

Are outside problems encompassed by standards and


6 Extent of applicable codes ☐
codes of practice for professional engineering.

Extent of stakeholder
Involve diverse groups of stakeholders with widely
7 involvement and level of ☐
varying needs.
conflicting requirements

8 Consequences Have significant consequences in a range of contexts. ☐

Are high level problems including many component


9 Interdependence ☐
parts or sub-problems.

24
Student Workbook EE-07310: Microprocessor based Embedded Systems

GENERALIZED LAB RUBRICS


Component Above Meeting Approaching Below Weight / Score
Domain with Expectation Expectation Expectation Expectation Used 100
(1–4)
Taxonomy (4) (3) (2) (1) (Optional)

Is able to build a given


setup neatly and timely Is able to assemble Is not able to
Psychomotor

Is only able to copy


Building using correct hardware a given setup using assemble a given
(Hardware) components and / or correct hardware
a given setup using
setup using 
correct hardware
P4 can reorganize / adapt components after correct hardware
components
to new / special minor revisions components
requirements
Recording
Is able to record Is only able to
Measurements Is able to record Is unable to
(Hardware / accurate measurements
accurate record accurate
record accurate ☐
measurements most measurements on
Software) all the time measurements
of the time some occasions
C3
Is able to formulate
Is partially able to
/develop theories in Is able to evaluate
Investigation evaluate /conclude Is unable to
addition to evaluating /conclude correctly
(Hardware /
/concluding correctly about investigation
correctly about comprehend 
Software) investigation investigation
about investigation parameters by
C5 parameters by parameters
parameters by assessing assessing data
assessing data
data
Design /
Is unable to
Development Is able to design / Is able to partially
Is able to design / partially design /
Cognitive

of Solution develop the solution of design / develop the ☐


develop the solution develop the
(Hardware / a given problem and solution of a given
of a given problem solution of a
Software) add features to it problem
given problem
C6
Is able to use the
Software Is adept in the use of Is able to use the
software tool
Usage software tool and can
effectively by
software tool but Is unable to use 
(Software) access advanced cannot access all the the software tool
accessing all the
C3 features required features
required features
Is able to efficiently
Is able to complete
complete a given task
a given task using
Programming using advanced Is unable to
required Is able to partially
Language programming language
programming complete a given
partially 
(Software) constructs / methods / complete a given
language constructs task
C3–C6 commands and/or add task
/ methods /
features to the original
commands
task

25
Student Workbook EE-07310: Microprocessor based Embedded Systems

GENERALIZED LAB RUBRICS

Component Above Approaching Below


Meeting Expectation Use Weight Score
Domain with Expectation Expectation Expectation / 100
(3) d (1–4)
Taxonomy (4) (2) (1) (Optional)

Safety Assesses and Assesses and complies Assesses and complies Assesses and
Instructions complies with all with most EHS with some EHS complies with ☐
(PLO6) EHS instructions instructions while in instructions while in few EHS
A4 while in lab lab lab instructions in lab
Does not exhibit
Exhibits exemplary Makes an effort to professional
Professional Exhibits professional
professional ethics exhibit professional ethics while
Ethics ethics while dealing
while dealing with
with fellow students,
ethics while dealing dealing with ☐
(PLO8) fellow students, lab with fellow students, fellow students,
A3 lab staff and instructor
staff and instructor lab staff and instructor lab staff and
all the time
all the time all the time instructor all the
time
Consistently shows
Shows some
full preparation by
Consistently shows full preparation which is Shows very little
Contribution completing all
preparation by mostly at superficial or no preparation
(PLO9) agreed tasks and
completing all agreed level in completing a in completing a 
A5 provides additional
tasks and work requires task and work requires task and work
resources for the
Affective

little or no revisions much revisions and quality is poor


group and work
editing
quality is excellent
Internalized positive
Attitude Consistent positive Neither helpful nor Discouraging
behavior and
(PLO9) encourages and
behavior most of the damaging and shows behavior towards ☐
A5 time towards other disinterest in the other team
helps other team
team members performance of others members
members
Report on all Report on all relevant Report on all relevant
relevant sections sections related to the sections related to the
Report related to the lab lab tasks is completed lab tasks is completed Report on all
Writing tasks is completed but few deficiencies but many deficiencies relevant sections
accurately, meeting are present in terms of are present in terms of related to the lab ☐
(PLO10)
A2 the requirements, in accuracy / meeting the accuracy / meeting the tasks is not
prescribed time and requirements / requirements / completed
with good language prescribed time / good prescribed time / good
skills language skills language skills
Lab Task Does not manage
Management Manages tasks well
within given
Manages tasks within Manages tasks in an tasks even in ☐
(PLO11) given timeframe extended timeframe extended
A3 timeframe
timeframes

26

You might also like