CL(L
t o * * * -
TRUONG DAI HOC SU PHAM KY THUAT
THANH PHO HO CHI MINH
KHOA CO KHI CHE TAO MAY
BO MON CO DIEN Ttf
DAP AN
DE THI CUOI HOC KY I NAM HOC 2023-2024
Mon: VI XU' LY (MIC0236929)
Be s6/Ma <38: 122023. .Be thi co 02 trang.
Thai gian: 90 phut. Ngay thi: 15/12/2023
Duac phep su dung tai lieu giay.
Lieu y: Dap an chi trinh bay mot (01) phucrng an giai quyet van d e trong de bai.
Nhieng each trinh bay khac hoac hu&ng tiep can khac giai quyet dieacyeu cau
de bai deu duac chain iron diem.
Cho he thong co dien tu nhir hinh gom:
- Bang tai duac van hanh bang dong co DC 24V. Bieu khien bai mach Relay tich
cue muc thap.
- Nut nhan dieu lehien he thong: B0, B l, B2, B3. Cam bien hanh trinh SI va S2
tich cue muc thap.(ve so do nguyen ly nhu mot Switch)
- Man hinh hi8n thi 2 LED 7 doan loai Cathod chung. Dieu khien bdi 2 IC thanh
ghi dich 74HC595 mac noi tiep.
U2 RN1
11
14
12 ^ST CP
10
13
SH CP
DS
MR
OE
Q0
Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q7'
15 1 16
1 2 15 e -
r .
2 3 14
3 4 13
4 5 12
5 6 11
6 7 10
7 8 9
9
74HC595
11
14 d s - U 3
Q2
ST CP Q3
Q4
Q5
Q6
MR Q7
OE Q7
RN2
1 1 16
22^ w v - 15 J
??14
4 4 13
5 5 12 >
6 6 11
7 7 10
989
74HC595 330
Cau 1: (1 diem)
Ve so do nguyen ly he thong su dung vi dieu khien STM32F103C8T6. Thach anh
noi. Nguon cap 3V3 va 24V co san. Luu y dat ten nhan tin hieu chan du lieu (14) la
MOSI, chan xung clock du lieu (11) la SCK va chan xung ch6t du lieu (12) la RCK.
So hieu: BM1/QT-PDT-RDTV/02 Lan soat xet: 02 Ngay hieu lire: 15/5/2020 Trang: 1/7
Cau 2: (1
Viet ham SHIFT595(uint8_t n) de chuyen 1 byte n ra cac chan cua IC 74HC595.
Chan du lieu Q7 la MSB cua dir lieu n.
a) Ve lira do
b) Viet chuong trinh.
ivoid SHIFT595(uint8_t n) {
! for (uint8_t i=0; i<8; i++) {
HAL_GPIO_WritePin (MOSI_GPIO_Port, MOSI_Pin, (n& (0x80»i) ) ) ;
HAL_GPIO_WritePin(SCK_GPIO_Port, SCK_Pin, 1);
HAL_GPIO_WritePin(SCK_GPIO_Port, SCK_Pin, 0) ;
- 1
fl
Cau 3: (1 dilm)
Su dung ham SHIFT595 da viet a cau 2 de viet ham LED_put(int8_t n) vbi chuc nang
1 LED 7 doan se sang so tuong ung voi so tham so n dua vao ham. Neu n > 9 thi hien
thi E. Neu n<0 thi tat hien thi.
U I E 3S5B189 E
a) Ve lira do
So hieu: BM1/QT-PDT-RDTV/02 Lan soat xet: 02 Ngay hieu luc: 15/5/2020 Trang: 2/7
b) Viet chuong trinh.
void LED_put(int8_t n) {
const uint8_t LED[] = {0x3F,0x06,Qx5B,0x4F;0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x79,0x00};
// 0 1 2 3 4 5 6 7 8 9 E OFF
if (n>9) n = 10; // E
else if (n<Q) n = 11; // OFF
SHIFT595(LED[n]);
HAL_GPIO_WritePin(RCK_GPIO_Port, RCK_Pin, 1);
HAL GPIO_WritePin(RCK_GPIO_Port, RCK_Pin, 0) ;
I
Cau 4: (1 d i e m ) ^
Su dung ham LED_put da vi§t a cau 3 d<3 vilt ham LED_display(int8_t n) vdi chuc
nang sang 2 LED 7 doan tuang ung vai so tham so n dua vao ham. (Thu tu hang chuc
va hang don vi nhu hinh ve). Neu n>99 thi hien thi EE. Neu n<0 thi tat hien thi.
a) Ve hru do
So hieu: BM1/QT-PDT-RDTV/02 Lan soat xet: 02 Ngay hieu luc: 15/5/2020 Trang: 3/7
b) Viet chirong trinh.
void LED_display(int8_t n) {
uint8_t donvi = (n%10);
uint8_t chuc = (n/10);
i if (n>99) {
donvi = 10;
chuc = 10;
}
i else if (n<0) {
donvi = 11;
chuc = 11;
}
LED_put(donvi);
HAL_GPIO_WritePin(SCK_GPIO_Port, SCK_Pin, 1);
HAL_GPIO_WritePin(SCK_GPIO_Port, SCK_Pin, 0);
LED_put(chuc);
HAL_GPIO_WritePin(RCK_GPIO_Port, RCK_Pin, 1);
HAL GPIO WritePin(RCK GPIO Port, RCK Pin, 0);
I " " " "
Cau 5: (1 diem)
Sir dung ham LED_display da viet a cau 4 de viet ham LED_string(uint8_t *s) vbi
chuc nang sang 2 LED 7 doan tuang ung vai so tham so con tro *s dua vao ham. Biet
*s truyen vao chudi dang so nhu 0” , 1, 2, ... 9”, 10, 11, 12, . . . , 99.
a) Ve luu do
S6 hieu: BM1/QT-PDT-RDTV/02 Lan soat xet: 02 Ngay hieu luc: 15/5/2020 Trang: 4/7
b) Viet chuang trinh.
ivoid LED_string (uint8_t *s) {|
uint8_t num=0;
if (* (s+1) == 0)
num = * s - 'O';
else
num = (*s-'0 ')*10 + *(s+l)-'0';
LED display(num);
1
Cau 6: (3 diem)
Su dung ky thuat lap trinh may trang thai (State machine) d<§ viet doan chuang trinh
dieu khien bang tai: (co the sir dung cac ham da viet a cac cau trade va khong can viet
lai). Chi viet chuang trinh, khong can ve luu do.
- Mdi khi nhan nut nhan BO se chay/ngimg bang tai. (Neu bang tai dang ngirng
thi khi nhan nut BO se lam bang tai chay vanguoc lai)
uint8_t BO, Bl, B2, B3; // button read
uint8_t B0_state=0, Bl_state=0, B2_state=0, B3_state=0;
HAL_GPIO_WritePin(M_GPIO_Port, M_Pin, 0);
while (1)
BO = HAL_GPIO_ReadPin(BO_GPIO_Port,B0_Pin);
if ((B0_state==0)&&(B0==0)) {
B0_state = 1;
HAL_GPIO_TogglePin(M_GPIO_Port, M_Pin);
1
if ((B0_state==l)&&(BO!=0)) {
B0_state = 0;
1
- Moi khi nMn nut nhan B l, hai LED 7 doan hien thi tang 1 don vi.
So hieu: BM1/QT-PDT-RDTV/02 Lan soat xet: 02 Ngay hieu luc: 15/5/2020 Trang: 5/7