Anda di halaman 1dari 4

P N - THI GIA HC K 2, 2011-2012

Lp CQ DD08
Mn thi: THIT K H THNG NHNG - Thi gian: 50 pht
(Sinh vin c php tham kho ti liu;
Sinh vin khng c php s dng my vi tnh, laptop)
Bi 1: (3 im) Cho mt d n thit k h thng nhng s dng chip PIC16F877 cho sn phm my bm
ti cy t ng vi m t sau:
H thng c kh nng t bm nc ti cy theo thi gian ci t trc, kh nng cnh bo khi
nc trong h cha cn, kh nng t ng ngt van khi nc trong h cha y, kh nng cnh
bo khi bm qu nhit.
H thng h tr mn hnh LCD1602, bn phm 16 nt, cm bin nhit LM35, cm bin mc nc,
IC thi gian thc DS1302, ci bo hiu.
H thng h tr chc nng chnh gi h thng, chnh gi ti, c cm bin nhit, cm bin mc
nc, iu khin bm v van nc h cha bng FET IRF630N.
Hy m t li h thng theo c t (specification) ca quy trnh thit k h thng nhng.
Tr li:
No.
Specification
Description
(Thng s k thut)
M t
1
Product specification
H thng c kh nng t bm nc ti cy theo thi gian ci t
trc, kh nng cnh bo khi nc trong h cha cn, kh nng t
ng ngt van khi nc trong h cha y, kh nng cnh bo khi
bm qu nhit.
2
Engineering specification
Input: cm bin nhit, cm bin mc nc, tn hiu ng h thi
gian thc
Output: iu khin relay bm, van nc h cha
User interface: LCD, bn phm, ci bo hiu
3
Hardware specification
Hnh v s khi:
LCD
Cm bin nhit
Cm bin mc
nc

iu khin
bm

PIC16F877

IC thi gian

iu khin van
iu khin ci

Vi iu khin: PIC16F877, clock 20Mhz


Cm bin: LM35, DS1302,
B tha hnh: FET, ci
4

Software specification

Chc nng: chnh gi h thng, chnh gi ti, c cm bin nhit,


cm bin mc nc, iu khin relay bm, van nc h cha.

Gii thut iu khin:


-iu khin ON/OFF theo iu kin thi gian
-Cnh bo theo iu kin cm bin
Test specification
Platform: mch PIC16F877
Tin trnh kim tra:
- Kim tra hot ng ca bn phm, LCD
- Kim tra hot ng ca cm bin nhit, cm bin mc nc
- Kim tra hot ng ca mch iu khin bm v ci
- Kim tra hot ng ca gii thut iu khin
(Ch : p n c th ty bin, sinh vin tr li y 5 loi c t s nhn trn s im)

Bi 2: (3 im) Tr li cc cu hi sau v vi iu khin ARM Cortex-M3


a) Hy cho bit tm a ch dnh cho SRAM v dung lng ti a ca n l bao nhiu?
Tm a ch: 0x20000000 - 0x3FFFFFFF
Dung lng ti a: 0.5GB
b) Hy vit on chng trnh di chuyn 10 words t a ch 0x60000000 n 0x70000000.
MOV R0,#0x60000000
MOV R1,#0x70000000
MOV R2,#10
LOOP LDR R3,[R0]
STR R3,[R1]
ADD R0,#4
ADD R1,#4
SUBS R2,#1
BNE LOOP
c) Hy vit on chng trnh ghi gi tr cha trong thanh ghi R1 vo thanh ghi CONTROL
MSR CONTROL, R1
Bi 3: (4 im) Cho mt h thng nhng s dng PIC16F84A c m t nh sau:
Port A (RA0,RA1,RA2) ni vi 3 nt nhn tch cc mc thp, c tn l UP, DOWN, CLEAR
Port B (RB0, RB1,, RB6) ni vi mt LED 7 on Anode chung, c cc chn A,B,C,D,E,F,G.
Sau khi RESET, LED 7 on hin th s 0
Khi nhn nt UP, s hin th s tng 1 (ti a tng n s 9).
Khi nhn nt DOWN th s hin th s gim 1 (ti thiu gim n s 0).
Khi nhn nt CLEAR, s hin th v 0.
Khi khng nhn nt th s hin th gi nguyn
a) (1 im) Hy v s mch chi tit cho h thng trn
b) (3 im) Hy vit chng trnh C thc hin chc nng iu khin h thng trn. Cho trc 2 files:
main.h , io.h. Yu cu vit 2 files: main.c, v io.c.
/* main.h */
/* io.h */
#include <16F84a.h>
#include <16F84a.h>
#use delay(clock=20000000)
#use delay(clock=20000000)

int button_check(); //Hm kim tra nt nhn


// tr v 0 nu khng c nt nhn,
// tr v 1 nu nt UP c nhn,
// tr v 2 nu nt DOWN c nhn,
// tr v 3 nu nt CLEAR c nhn,

//nh ngha nt nhn


#define UP PIN_A0
#define DOWN PIN_A1
#define CLEAR PIN_A2
//nh ngha ng ra LED 7 on
#define out_LED7(x) output_B(x)

void display(int BCD);//Th tc xut gi tr ra LED


7 on
// chuyn m BCD sang m LED 7 on
// v xut ra Port B
Tr li:
a) S mch:

R1

R2

R3

10k

10k

10k

UP
C1
DOWN
1nF

X1
CRYSTAL

C2
1nF

CLEAR

U1
16
15
4

OSC1/CLKIN
OSC2/CLKOUT
MCLR

R11

RA0
RA1
RA2
RA3
RA4/T0CKI
RB0/INT
RB1
RB2
RB3
RB4
RB5
RB6
RB7

10k

RESET

17
18
1
2
3
6
7
8
9
10
11
12
13

R4
R5
R6
220
R7
220
R8
220
R9
220
R10
220
220
220

PIC16F84A

b) Chng trnh iu khin:


/* main.c */
#include "main.h"

/* io.c */
#include <io.h>

void main()
{
int button;
int BCD = 0;
output_B(0);
while(1)
{
button = button_check();
switch (button)

int button_check()
{
int1 button_UP, button_DOWN, button_CLEAR;
button_UP = input(PIN_A0);
button_DOWN = input(PIN_A1);
button_CLEAR = input(PIN_A2);
if (!button_UP)
{

{
case 1:
if (BCD<9)BCD++;
break;
case 2:
if (BCD>0)BCD--;
break;
case 3:
BCD = 0;
break;
default:
break;
}
display(BCD);
delay_ms(20);
}
}

delay_ms(10);
button_UP = input(UP);
if (!button_UP) return 1;
}
else if(!button_DOWN)
{
delay_ms(10);
button_DOWN = input(DOWN);
if (!button_DOWN) return 2;
}
else if(!button_CLEAR)
{
delay_ms(10);
button_CLEAR = input(CLEAR);
if (!button_CLEAR) return 3;
}
else
return 0;
}
void display(int BCD)
{
const int data[10] = {0xc0, 0xf9, 0xa4, 0xb0,
0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
int out;
if (BCD<10) out = data[BCD];
else
out = 0xff;
out_LED7 (out);
}