Professional Documents
Culture Documents
MBES - Lab 10-12 PDF
MBES - Lab 10-12 PDF
MBES - Lab 10-12 PDF
LABORATORY SESSION # 10
10 Interfacing of 16x2 LCD with STM32F100xx
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
- __________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
10.3 PROCEDURE
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
1
Student Workbook EE-07310: Microprocessor based Embedded Systems
#include "main.h"
#include "LED.h"
#include "LCD.h"
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)
{
}
3
Student Workbook EE-07310: Microprocessor based Embedded Systems
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
4
Student Workbook EE-07310: Microprocessor based Embedded Systems
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;
}
5
Student Workbook EE-07310: Microprocessor based Embedded Systems
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
6
Student Workbook EE-07310: Microprocessor based Embedded Systems
7
Student Workbook EE-07310: Microprocessor based Embedded Systems
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
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.3 PROCEDURE
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
9
Student Workbook EE-07310: Microprocessor based Embedded Systems
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Algorithm:
10
Student Workbook EE-07310: Microprocessor based Embedded Systems
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 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
#endif
4
Student Workbook EE-07310: Microprocessor based Embedded Systems
keypad4x4.c
#include "main.h"
#include "LCD.h"
#include "delay.h"
#include "keypad4x4.h"
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
6
Student Workbook EE-07310: Microprocessor based Embedded Systems
LCD_Write_Char_To_Buff('3',++count);
}
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
8
Student Workbook EE-07310: Microprocessor based Embedded Systems
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
9
Student Workbook EE-07310: Microprocessor based Embedded Systems
- Assess the changes in the code if the rows are the output and columns are the
input group.
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
11
Student Workbook EE-07310: Microprocessor based Embedded Systems
LCD_Write_Char_To_Buff('7',++count);
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"
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
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);
}
LCD_Update();
}
15
Student Workbook EE-07310: Microprocessor based Embedded Systems
16
Student Workbook EE-07310: Microprocessor based Embedded Systems
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
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.3 PROCEDURE
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
18
Student Workbook EE-07310: Microprocessor based Embedded Systems
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
- 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 & 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;
}
}
20
Student Workbook EE-07310: Microprocessor based Embedded Systems
21
Student Workbook EE-07310: Microprocessor based Embedded Systems
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
22
Student Workbook EE-07310: Microprocessor based Embedded Systems
- 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 & 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.
Extent of stakeholder
Involve diverse groups of stakeholders with widely
7 involvement and level of ☐
varying needs.
conflicting requirements
24
Student Workbook EE-07310: Microprocessor based Embedded Systems
25
Student Workbook EE-07310: Microprocessor based Embedded Systems
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
26