1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Giáo trình bài tập & hướng dẫn sử dụng Training .Kit.8951 potx

51 414 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Training Kit 8951
Trường học University of Danang - Education University of Danang
Chuyên ngành Electrical Engineering
Thể loại Giáo trình bài tập & hướng dẫn sử dụng
Năm xuất bản Not specified
Thành phố Danang
Định dạng
Số trang 51
Dung lượng 1,84 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Hin thi LCD Thí c hanh: man hınh tinh th lòng 2 dếng.... DAC, Sềng Sin, Motor DC Thí c hanh: Chuyn ơửi sẩ - tể ựng tí ơiớu khin motor dc va tấo sềng sin.. Motor bể ờc Thí c hanh: ơiớu kh

Trang 1

1 Gia o trınh ly thuye t ho vi ề ìu khỉn 8051

2 Gia o trınh bậi tưp vậ hớ ơ ng d̃n s dung

r a i ngng.K t n8K9 5 1

3 Иa CD cợng cu lưp trınh vậ datasheet

NOVAS mong nhưn ề ớ óc gừp y tạ bản ề o c

r ai ngng.Ktn8K9 5 1

Trang 2

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

Training.Kit.PLC, Training.Kit.Inverter, Training.Kit.Microcontroller

Muc luc

Bai 1 Cụng cầ lôp trınh 3

Bai 2 Phứn cư ng 4

Bai 3 Hin thi LED ơựn (Thí c hanh: lam quen 8951, tễnh tr̃) 4

Bai 4 Hin thi LED 7 ơoấn (Thí c hanh: xu t port, quỏt led) 5

Bai 5 Hin thi LED ma trôn 10

Bai 6 Hin thi LCD (Thí c hanh: man hınh tinh th lòng 2 dếng) 11

Bai 7 Giao tiắp ban phễm (Thí c hanh: ng˘ t ngoai, chẩng nảy khi n va nhổ phễm, quỏt phễm, chuyn ơửi hex sang ascii, gữi d˜ lie u lÂn m´ y tễnh) 15

Bai 8 Am thanh (Thí c hanh: tấo tr̃ dặng vếng lóp) 19

Bai 9 DAC, Sềng Sin, Motor DC (Thí c hanh: Chuyn ơửi sẩ - tể ựng tí ơiớu khin motor dc va tấo sềng sin) 25 Bai 10 ADC (Thí c hanh: chuyn ơửi tể ựng tí - sẩ, ng˘ t ngoai, ng˘ t timer, hin thi LED 7 ơoấn) 27

Bai 11 Motor bể ờc (Thí c hanh: ơiớu khin motor bể ờc, giao tiắp ban phễm, hin thi) 30

Bai 12 Tấo 2 sềng vuụng (Thí c hanh: ng˘ t ơinh thĐi) 35

Bai 13 Ð iớu chắ ơo ro ng xung PWM Pulse Width Modulation (Thí c hanh: ng˘ t ơinh thĐi) 36

Bai 14 Ð á ng há sẩ (Thí c hanh: ng˘ t ơinh thĐi, LED 7 ơoấn kiu quỏt, v n ơớ lôp trınh IO va bổo ve thanh ghi vời ISR) 38

Bai 15 Encoder (Thí c hanh: Nhôp xu t port, Ng˘ t ngoai, Bo ơắm, LED 7 ơoấn, bổo ve thanh ghi vời ISR) 46

Bai 16 Giao tiắp m´ y tễnh (Thí c hanh: giao tiắp nẩi tiắp m´ y tễnh theo giao thư c RS232) 48

Trang 3

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

eang T 3

Bậi 1 Cợng cu lưp trınh

1.1 Trınh soản thêo Crimson

Soan tho noi dung trong cư a sí chınh, lổ u file dổ ơi dang asm

1.2 Trınh soản thêo vậ biị n dich 8051ide

File ng˜ vốo: asm, file ng˜ ra: hex

Trang 4

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

1.3 Trınh nảp EZ Downloader

Ńi PC vố Kit nap b˘ng cí ng RS232, sư dung trđnh EZ

ểe nap chip 8951, file ng˜ vốo dang hex (biịn dich dâng trđnh 8051ide)

Bậi 2 Phứn cựng

Mo hınh day hđ c vi ề ieu khỉ n (Training.Kit.8951) ề ợơc chia thầnh nhieu module nhợ sau:

ç Module xư lı trung tựm: chip 8951, mach dao ểong thach anh, reset

ç Module ADC, DAC (chuyen ểí i tổ õng tậ sang ś vố ś sang tổ õng tậ) nhện tın hiừu

tổ õng tậ tế cm biấn, xuềt tın hiừu tổ õng tậ ểiáu khien motor DC, ểo sẩng LED

ç Module giao tiấp mẩy tınh theo chuỏ n RS232

ç Module motor bổ ơc

ç Module motor mot chiáu, ểiáu chấ ểo rong xung PWM

ç Module hien thi mốn hđnh tinh the lồ ng (LCD)

ç Module hien thi LED 7 ểoan

ç Module hien thi LED ma trện

ç Module hien thi LED ểõn

Thậc hốnh mot ểoan lừnh ểõn gin nhềt vơi LED ểõn, qua

ểủ kiem tra sậ hoat ểong côa cễ ng cu lệp trđnh, bo lệp trđnh

vố Kit8951 Hieu cẩch tao tr̃ ểõn gin

(Phứn c´ng: Xem phu luc)

; RESET ;reset routine

.ORG 0H ;locate routine at 00H

AJMP START ;jump to START

Trang 5

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

; Real code starts below The first two routines are for delays so we

; can slow down the blinking so we can see it (Without a delay, it

; would blink so fast it would look like it was always on

;**************************************************************************

;This delay program is quite bad compared to using DJNZ, see NOVAS lecture notes

DELAYMS: ;millisecond delay routine

; ;

MOV R7,#00H ;put value of 0 in register R7

LOOPA:

INC R7 ;increase R7 by one (R7 = R7 +1)

MOV A,R7 ;move value in R7 to Accumlator (also known as A)

CJNE A,#0FFH,LOOPA ;compare A to FF hex (256) If not equal go to LOOPA

RET ;return to the point that this routine was called from

;**************************************************************************

DELAYHS: ;half second delay above millisecond delay

; This delay forming is bad compared to what shown in NOVAS lecture notes

MOV R6,#00H ;put 0 in register R6 (R6 = 0)

MOV R5,#002H ;put 2 in register R5 (R5 = 2)

LOOPB:

INC R6 ;increase R6 by one (R6 = R6 +1)

ACALL DELAYMS ;call the routine above It will run and return to here

MOV A,R6 ;move value in R6 to A

JNZ LOOPB ;if A is not 0, go to LOOPB

DEC R5 ;decrease R5 by one (R5 = R5 -1)

MOV A,R5 ;move value in R5 to A

JNZ LOOPB ;if A is not 0 then go to LOOPB

RET

;**************************************************************************

START: ;main program (on power up, program starts at this point)

ACALL INITIALIZE ;set up control registers

LOOP:

CPL P1.0 ;ComPLement (invert) P1.0 (this makes LED change)

ACALL DELAYHS ;go to above routine that causes a delay

AJMP LOOP ;go to LOOP(always jump back to point labeled LOOP)

.END ;end program

Bậi 4 Hỉn thi LED 7 ề oản (Thíc hậnh: xuét port, quỏt led)

ç (Phứn c´ng: Xem phu luc)

Trang 6

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

Trang 7

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

; RESET ;reset routine

ORG 0H ;locate routine at 00H

AJMP START ;jump to START

Trang 8

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

ORG 1BH ;timer 1 interrupt

; Real code starts below

; This program is very bad compared to using DJNZ

;**************************************************************************

DELAYMS: ;millisecond delay routine

MOV R7,#00H ;put value of 0 in register R7

LOOPA:

INC R7 ;increase R7 by one (R7 = R7 +1)

MOV A,R7 ;move value in R7 to Accumlator (also known as A)

CJNE A,#0FFH,LOOPA ;compare A to FF hex (256) If not equal go to LOOPA

RET ;return to the point that this routine was called from

;**************************************************************************

DELAYHS: ;half second delay above millisecond delay

MOV R6,#00H ;put 0 in register R6 (R6 = 0)

MOV R5,#002H ;put 2 in register R5 (R5 = 2)

LOOPB:

INC R6 ;increase R6 by one (R6 = R6 +1)

ACALL DELAYMS ;call the routine above It will run and return to here

MOV A,R6 ;move value in R6 to A

JNZ LOOPB ;if A is not 0, go to LOOPB

DEC R5 ;decrease R5 by one (R5 = R5 -1)

MOV A,R5 ;move value in R5 to A

JNZ LOOPB ;if A is not 0 then go to LOOPB

RET

;**************************************************************************

DISPLAY_0: ; Display 0 on the Seven Segment Display

MOV P2, #00000001B ; P2.7 is on the left and P2.0 on the right

RET ; The B at the end means it is a binary number

;**************************************************************************

DISPLAY_1: ; Display 1 on the Seven Segment Display

MOV P2, #01001111B ; P2.7 is on the left and P2.0 on the right

RET ; The B at the end means it is a binary number

;**************************************************************************

DISPLAY_2: ; Display 2 on the Seven Segment Display

MOV P2, #00010010B ; P2.7 is on the left and P2.0 on the right

RET ; The B at the end means it is a binary number

;**************************************************************************

DISPLAY_3: ; Display 3 on the Seven Segment Display

MOV P2, #00000110B ; P2.7 is on the left and P2.0 on the right

RET ; The B at the end means it is a binary number

;**************************************************************************

DISPLAY_4: ; Display 4 on the Seven Segment Display

MOV P2, #01001100B ; P2.7 is on the left and P2.0 on the right

RET ; The B at the end means it is a binary number

;**************************************************************************

DISPLAY_5: ; Display 5 on the Seven Segment Display

Trang 9

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

eang T 9

MOV P2, #00100100B ; P2.7 is on the left and P2.0 on the right

RET ; The B at the end means it is a binary number

START: ;main program (on power up, program starts at this point)

ACALL INITIALIZE ;set up control registers

LOOP:

ACALL DISPLAY_0 ;Display 0 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_1 ;Display 1 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_2 ;Display 2 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_3 ;Display 3 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_4 ;Display 4 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_5 ;Display 5 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

Trang 10

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

ACALL DISPLAY_6 ;Display 6 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_7 ;Display 7 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_8 ;Display 8 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_9 ;Display 9 on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_A ;Display A on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_b ;Display b on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_C ;Display C on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_d ;Display d on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_E ;Display E on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay

ACALL DISPLAY_F ;Display F on the seven segment display

ACALL DELAYHS ;go to above routine that causes a delay AJMP LOOP ;go to LOOP(always jump back to point labeled LOOP)

END ;end program

Bậi 5 Hỉn thi LED ma trưn

(Phứn c´ng: Xem phu luc)

; -

; Matrix LED Display novas

; -

h equ p0

;low nible for red color, high nible for green color

col equ p2 ;8 columns

ORG 0H ;locate routine at 00H LJMP MAIN

Trang 11

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

ç (Phứn c´ng: xem phu luc)

ç Gần tềt c cẩc jum khi thậc thi bối tệp nốy, thẩo jum khi khễ ng dâng LCD

6.2 Mợ tê

ç Mễ t LCD 16 chựn:

Trang 12

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

Pin Description Pin Description Pin Description Pin Description

; novas display on LCD 16 pins

; display in fast or slow speeds nvlcd.asm

;**************************************************************************

; PORT USAGE

;cr equ 0dh ;carrier return

enable equ p2.0 ; enable pin 6 LCD

Trang 13

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

eang T13

RW equ p2.2 ; read/write pin 5 LCD

RS equ p2.1 ; register select pin 4 LCD

slow_disp set 30h ; 0 = fast display, 1 = slow display

; P1 connected to 8bit data bus of LCD, in the normal sequence

; P1.0 to P1.7 connected to D0 to D7

ORG 0 ;locate routine at 00H

LJMP MAIN

;**************************************************************************

; INTERRUPTS ; not used

ORG 03H ;external interrupt 0

Trang 14

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

mov p1,a ; write data

lcall long_delay ; - slow

slow_data: lcall delay

movc a,@a+dptr ; get character

jz exit ; stop if char == null

lcall write_data ; else send it

inc dptr ; point to next char

sjmp send_string

exit: ret

; number 0 put at the end to recognize the end point

; see the novas lecture notes

mess1: db '_NOVAS Automation & Embedded System/',0

mess2: db '_Truong Cao dang Cong nghe/',0

Trang 15

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

ç Chuyen ểí i mẤ hex sang ascii, gư i lịn PC

a n phım lịn (INC) ểe tĐ ng giẩ tri ểấm, File: nvkey.asm

b Cẩch kất ńi bốn phım nhổ trong hđnh 9.2 sẩch V— K, nguyịn tầc giao tiấp bốn phım tiất

kiừm ś chựn ng˜ vốo (saving inputs) 16 phım ền ńi tơi 8 ng˜ vốo 8951, File: nvkey1.asm

SETB EX1 ;external 1 interrupt

CLR IT1 ;Negative Edge Active, IT0 = TCON.0

setb inc_key ;see lecture notes NOVAS

Trang 16

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

Trang 17

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

; b keypad, reads keypad & send to PC via Serial port

; low nibble for rows, high nibble for columns

org 0

; *******************************************************************

main: lcall in_hex ; get code from keypad

lcall htoa ; convert to ascii

lcall outchar ; send to terminal

sjmp main

; *******************************************************************

; debounce keypress and key release

; *******************************************************************

in_hex: mov r3,#50 ; debounce count

back: lcall get_key ; key pressed?

jnc in_hex ; no - check again

djnz r3,back ; yes - repeat 50 times

push acc ; save key code

back2: mov r3,#50 ; wait for key release

back3: lcall get_key ; key still pressed?

jc back2 ; yes - keep checking

djnz r3,back3 ; no - repeat 50 times

pop acc ; recover key code

ret

; *******************************************************************

; get keypad status - return with C = 0 if no key pressed

; - return with C = 1, and key in acc if pressed

Trang 18

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

; *******************************************************************

get_key: mov a,#0feh ; start with column 0

mov r6,#4 ; use r6 as a counter

test_next: movx p1,a ; activate column line

mov r7,a ; save a

mov a,p1 ;read back from keypad

anl a,#0f0h ; isolate row lines

cjne a,#0f0h,key_hit ; row line active?

mov a,r7 ; no - move to next column line

rl a

djnz r6,test_next

clr c ; no key pressed

sjmp exit ; return with c = 0

key_hit: mov r7,a ; save row code in r7

mov a,#4 ; prepare to calc column weighting

clr c

subb a,r6 ; 4-r6 = column weighting

mov r6,a ; save in r6

mov a,r7 ; restore scan code in acc

swap a ; put scan code in low nibble

mov r5,#4 ; use r5 as counter

again: rrc a ; rotate until zero bit found

jnc done ; done when c = 0

inc r6 ; add 4 until active row found

inc r6

inc r6

inc r6

djnz r5,again

done: setb c ; c = 1 (key pressed)

mov a,r6 ; hex code in acc

lcall lookup_key ; change mapping to suit your keypad

Trang 19

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

; The acc contains the original value, so we need to add this value

; to the start of the table to get the new value

a Tao ựm thanh tã n ś 440Hz khễ ng dâng bo ểinh thỗi

b Tao 2 ựm thanh tã n ś 500Hz vố 250Hz ểó ng thỗi

c Tao chuữi ựm thanh củ tã n ś gim dã n

d Tao chuữi ựm thanh tã n ś biấn thiịn tĐ ng vố gim

; RESET ;reset routine

ORG 0 ;locate routine at 00H

AJMP START ;jump to START

;**************************************************************************

; Real code starts below

DELAY440: ;millisecond delay routine

MOV R7,#02CH ;put value of 2C (44 in decimal) in register R7

LOOPA:

INC R7 ;increase R7 by one (R7 = R7 +1)

MOV A,R7 ;move value in R7 to Accummulator (also known as A)

CJNE A,#0FFH,LOOPA ;compare A to FF hex (255) If not equal go to LOOPA

RET ;return to the point that this routine was called from

;**************************************************************************

;

START: ;main program (on power up, program starts at this point)

CPL P1.0 ;ComPLement (invert) P1.0 (this makes LED change)

ACALL DELAY440 ;go to above routine that causes a delay

AJMP START

END ;end program

Trang 20

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

;***************************************************************************

;* novas ờ

b Alternating Tones: 500Hz and 250Hz

;***************************************************************************

RESET ;reset routine

ORG 0H ;locate routine at 00H

AJMP START ;jump to START

INC R7 ;increase R7 by one (R7 = R7 +1)

MOV A,R7 ;move value in R7 to Accumlator (also known as A)

CJNE A,#0FFH,LOOPA ;compare A to FF hex (256) If not equal go to LOOPA

RET ;return to the point that this routine was called from

;**************************************************************************

DELAYHS: ;half second delay above millisecond delay

; ;

MOV R6,#080H ;put 0 in register R6 (R6 = 0)

MOV R5,#002H ;put 2 in register R5 (R5 = 2)

LOOPB:

INC R6 ;increase R6 by one (R6 = R6 +1)

ACALL DELAYMS ;call the routine above It will run and return to here

MOV A,R6 ;move value in R6 to A

JNZ LOOPB ;if A is not 0, go to LOOPB

DEC R5 ;decrease R5 by one (R5 = R5 -1)

MOV A,R5 ;move value in R5 to A

JNZ LOOPB ;if A is not 0 then go to LOOPB

RET

;**************************************************************************

TONE_ONE: ;About 500 Hz

Trang 21

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

eang T21

MOV R4,#00H ;put 0 in register R4

MOV R3,#02H ;put 2 in register R3

LOOPC:

INC R4 ;increase R4 by one

ACALL DELAYMS ;Delay One Millisecond

CPL P1.0

MOV A,R4 ;move value in R4 to A

JNZ LOOPC ;if A is not 0, go to LOOPC

DEC R3 ;decrease R3 by one

MOV A,R3 ;move value in R3 to A

JNZ LOOPC ;if A is not 0 then go to LOOPC

RET

;**************************************************************************

TONE_TWO: ;About 250 Hz

MOV R4,#00H ;put 0 in register R4

MOV R3,#01H ;put 1 in register R3

LOOPD:

INC R4 ;increase R4 by one

ACALL DELAYMS ;Delay One Millisecond

ACALL DELAYMS ;Delay One Millisecond

CPL P1.0

MOV A,R4 ;move value in R4 to A

JNZ LOOPD ;if A is not 0, go to LOOPD

DEC R3 ;decrease R3 by one

MOV A,R3 ;move value in R3 to A

JNZ LOOPD ;if A is not 0 then go to LOOPD

RET

;**************************************************************************

START: ;main program (on power up, program starts at this point)

ACALL INITIALIZE ;set up control registers

LOOP:

ACALL TONE_ONE

ACALL TONE_TWO

AJMP LOOP ;go to LOOP(always jump back to point labeled LOOP)

.END ;end program

; RESET ;reset routine

ORG 0H ;locate routine at 00H

AJMP START ;jump to START

Trang 22

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

INC R7 ;increase R7 by one (R7 = R7 +1)

MOV A,R7 ;move value in R7 to Accumlator (also known as A)

CJNE A,#0FFH,LOOPA ;compare A to FF hex (256) If not equal go to LOOPA

RET ;return to the point that this routine was called from

MOV R6,#080H ;put 0 in register R6 (R6 = 0)

MOV R5,#002H ;put 2 in register R5 (R5 = 2)

LOOPB:

INC R6 ;increase R6 by one (R6 = R6 +1)

ACALL DELAYMS ;call the routine above It will run and return to here

MOV A,R6 ;move value in R6 to A

JNZ LOOPB ;if A is not 0, go to LOOPB

DEC R5 ;decrease R5 by one (R5 = R5 -1)

MOV A,R5 ;move value in R5 to A

JNZ LOOPB ;if A is not 0 then go to LOOPB

INC R4 ;increase R4 by one

ACALL DELAY ;Delay

ACALL DELAYMS

DEC R2 ; This time decrement R2 to make tone go down in frequency

CPL P1.0

MOV A,R4 ;move value in R4 to A

JNZ LOOPC ;if A is not 0, go to LOOPC

DEC R3 ;decrease R3 by one

MOV A,R3 ;move value in R3 to A

JNZ LOOPC ;if A is not 0 then go to LOOPC

INC R7 ;increase R7 by one (R7 = R7 +1)

MOV A,R7 ;move value in R7 to Accumlator (also known as A)

CJNE A,#0FFH,LOOPE ;compare A to FF hex (256) If not equal go to LOOPA

RET ;return to the point that this routine was called from

;

;**************************************************************************

Trang 23

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

eang T23

START: ;main program (on power up, program starts at this point)

ACALL INITIALIZE ;set up control registers

MOV R2, #00H

LOOP:

ACALL TONE_ONE

AJMP LOOP ;go to LOOP(always jump back to point labeled LOOP)

END ;end program

;***************************************************************************

;* novas

; d sounds go up and down

;***************************************************************************

; RESET ;reset routine

ORG 0H ;locate routine at 00H

AJMP START ;jump to START

INC R7 ;increase R7 by one (R7 = R7 +1)

MOV A,R7 ;move value in R7 to Accumlator (also known as A)

CJNE A,#0FFH,LOOPA ;compare A to FF hex (256) If not equal go to LOOPA

RET ;return to the point that this routine was called from

Trang 24

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

; ;

MOV R6,#080H ;put 0 in register R6 (R6 = 0)

MOV R5,#002H ;put 2 in register R5 (R5 = 2)

LOOPB:

INC R6 ;increase R6 by one (R6 = R6 +1)

ACALL DELAYMS ;call the routine above It will run and return to here

MOV A,R6 ;move value in R6 to A

JNZ LOOPB ;if A is not 0, go to LOOPB

DEC R5 ;decrease R5 by one (R5 = R5 -1)

MOV A,R5 ;move value in R5 to A

JNZ LOOPB ;if A is not 0 then go to LOOPB

INC R4 ;increase R4 by one

ACALL DELAY ;Delay

; ACALL DELAYMS

DEC R2 ; This time decrement R2 to make tone go down in frequency

CPL P1.0

MOV A,R4 ;move value in R4 to A

JNZ LOOPC ;if A is not 0, go to LOOPC

DEC R3 ;decrease R3 by one

MOV A,R3 ;move value in R3 to A

JNZ LOOPC ;if A is not 0 then go to LOOPC

INC R4 ;increase R4 by one

ACALL DELAY ;Delay

; ACALL DELAYMS

INC R2 ; INCrement R2 to make frequency go up

CPL P1.0

MOV A,R4 ;move value in R4 to A

JNZ LOOPD ;if A is not 0, go to LOOPC

DEC R3 ;decrease R3 by one

MOV A,R3 ;move value in R3 to A

JNZ LOOPD ;if A is not 0 then go to LOOPC

Trang 25

Gi´ o trınh bai tôp r ai ngng.Ktn8K9 5 1

eang T25

MOV A,R7 ;move value in R7 to Accumlator (also known as A)

CJNE A,#0FFH,LOOPE ;compare A to FF hex (256) If not equal go to LOOPA

RET ;return to the point that this routine was called from

;

;**************************************************************************

START: ;main program (on power up, program starts at this point)

ACALL INITIALIZE ;set up control registers

LOOP:

ACALL TONE_ONE

ACALL TONE_TWO

AJMP LOOP ;go to LOOP(always jump back to point labeled LOOP)

END ;end program

Bậi 9 DAC, Sừng Sin, Motor DC (Thíc hậnh: Chuỷn ề ữi sẩ -

tớ ẫ ng tí ề ìu khỉn motor dc vậ tảo sừng sin)

9.1 Muc ề ễch

ç Xuềt tın hiừu tổ õng tậ ểiáu khien ểong cõ mot chiáu chay vơi cẩc t́c ểo khẩc nhau qua

nhẵ ng khong thỗi gian khẩc nhau, file: nvdac.asm

ç Tao sủng sine, file: nvsine.asm

9.2 Mợ tê

8951 xuềt ra DAC cẩc giẩ tri ś lơn bò khẩc nhau, giẩ tri tổ õng tậ ng˜ ra dâng ểiáu khien motor

dc theo cẩc t́c ểo yịu cã u tai nhẵ ng thỗi ểiem ểinh sợn

Sủng sine: Mach giao tiấp DAC nhổ hđnh 9.14 trang 245 sẩch vdk Kh nĐ ng xư lı cẩc con ś côa

8951 củ han nịn bng tđm kiấm ểổ ức sư dung (củ the sư dung trđnh C ểe tao bng tđm kiấm củ

1024 ểiem nhệp vơi cẩc giẩ tri tế 0 ểấn 255, kất qu lổ u vốo mot file sine.src, mữi ểiem nhệp

ểở ng trổ ơc bỉ i ch1 dẽn DB ểe tổ õng thıch mẤ nguó n côa 8951)

top: push acc

mov dptr,#speed_level ; get value from table

Ngày đăng: 09/08/2014, 02:22

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w