Студопедия

КАТЕГОРИИ:


Архитектура-(3434)Астрономия-(809)Биология-(7483)Биотехнологии-(1457)Военное дело-(14632)Высокие технологии-(1363)География-(913)Геология-(1438)Государство-(451)Демография-(1065)Дом-(47672)Журналистика и СМИ-(912)Изобретательство-(14524)Иностранные языки-(4268)Информатика-(17799)Искусство-(1338)История-(13644)Компьютеры-(11121)Косметика-(55)Кулинария-(373)Культура-(8427)Лингвистика-(374)Литература-(1642)Маркетинг-(23702)Математика-(16968)Машиностроение-(1700)Медицина-(12668)Менеджмент-(24684)Механика-(15423)Науковедение-(506)Образование-(11852)Охрана труда-(3308)Педагогика-(5571)Полиграфия-(1312)Политика-(7869)Право-(5454)Приборостроение-(1369)Программирование-(2801)Производство-(97182)Промышленность-(8706)Психология-(18388)Религия-(3217)Связь-(10668)Сельское хозяйство-(299)Социология-(6455)Спорт-(42831)Строительство-(4793)Торговля-(5050)Транспорт-(2929)Туризм-(1568)Физика-(3942)Философия-(17015)Финансы-(26596)Химия-(22929)Экология-(12095)Экономика-(9961)Электроника-(8441)Электротехника-(4623)Энергетика-(12629)Юриспруденция-(1492)Ядерная техника-(1748)

Лекція № 5

Ret

Ret

RET

Приклад програми для лабораторної роботи №8

Керувати швидкістю обертання двигуна постійного струму використовуючи вбудований апаратний ШІМ-контролер. Швидкість встановлюється відповідно до положення ручки джойстика, верхнє положення – мінімальна швидкість, нижнє положення – максимальна швидкість, 1 режим роботи, 12- бітний ШІМ, частота 675Гц.

 

 

$include (mod841)

 

org 0

JMP Start;перехід на мітку Start

 

ORG 030H

 

Start:

call Init_PWM;виклик ініціалізації ШІМ

call ADCInit;виклик ініціалізації АЦП

 

mov PWM1H, #00fh;встановлення розрядності ШІМ 12-біт

mov PWM1L, #0ffh

mov PWM0H, #007h;початкове значення ШІМ (50%)

mov PWM0L, #0ffh

BEGIN:;мітка початку основного циклу програми

call Measurev;виклик процедури вимірювання АЦП

mov PWM0H,R7;запис в старший байт ШІМ значення тетради старшого байту з АЦП

mov PWM0L,R5;запис в молодший байт ШІМ значення молодшого байту з АЦП

 

JMP BEGIN;перехід на початок циклу

 

Init_PWM:;ініціалізація ШІМ

mov PWMCON, #00010111b;1-режим, дільник робочої частоти на 4, тактування від кварца контролера

ADCInit:;ініціалізація АЦП

mov ADCCON1, #10111100b

Measurev:;вимірювання

;In: -

;Out: R7:R6 -- ADC result

;Alters: a, PSW

mov ADCCON2, #00010110b

jnb ADCI, $

mov a, ADCDATAH

anl a, #0fh

mov R7, a

mov R6, ADCDATAL

END

 

 


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

; File: TIC.asm

; Hardware: ADuC842/ADuC843

;

; Description: Demonstrates a use of a timer interval counter for

; counting longer intervals than the standard 8052

; timers are capable of.

;

; The LED will, on power up, flash at 6.4Hz. By pressing

; the external interrupt button INT0 the counter will

; count how long the button is pressed correct to

; 1/128th of a second. When released the program will

; flash the light at the measured time correct only to

; the nearest unit (1/128s, seconds, minutes or hours)

; rounded DOWN.

; eg) If the button was pressed for 0.91000s the light

; would complement every 0.90625s (less than 1 second

; therefore it measures in 1/128s and the nearest unit

; less than 0.91000s is 0.90625s). However if the light

; was on for 1.6s it complements every 1s as the nearest

; unit is now the second.

; Pressing the INT0 button again will record a new

; time interval which will flash the light in the same

; way.

 

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

 

$MOD842; Use 8052&ADuC842 predefined symbols

 

LED EQU P3.4; P3.4 drives red LED on eval board

BUTTON EQU P3.2; P3.2 drives the INT0 button on the

; eval board

;____________________________________________________________________

; BEGINNING OF CODE

CSEG

 

ORG 0000h

 

JMP MAIN; jump to main program

 

;____________________________________________________________________

; EXTERNAL INTERRUPT VECTOR SPACE

ORG 0003h; (INT0 ISR)

 

CLR LED; Turn ON the LED while the INT0

; is pressed

 

; reset all counters and then start counting

ANL TIMECON, #0FEh; Clear the TCEN bits to clear the

; registers;

; -Hthsec

; -sec

; -min

; -hour.

; and to clears the internal counter

 

ORL TIMECON, #01h; Set the TCEN bit to restart counting

 

JNB BUTTON, $; Wait here while button is pressed

 

ANL TIMECON, #0FDh; Clear the TIEN bit to stop the

; counter

 

; after button is released we can store the value in intval

 

LOOP: SETB LED; Turn off LED to indicate that the

; button is released.

MOV A, HOUR

CJNE A, #00H, HOURS; Check if any hrs have been counted

; If so jump to HOURS

MOV A, MIN

CJNE A, #00H, MINS; Check if any mins have been counted

; If so jump to MINS

MOV A, SEC

CJNE A, #00H, SECS; Check if any secs have been counted

; If so jump to SECS

 

HUNTHS: MOV INTVAL, HTHSEC;load the value of HTHSEC into INTVAL

MOV TIMECON, #00h; clear TCEN to reset the registers

MOV TIMECON, #03H; change TIMECON to measure in 1/128s

; reset TIEN

RETI

 

SECS: MOV INTVAL, SEC; load the value of SEC into INTVAL

MOV TIMECON, #00h; clear TCEN to reset the registers

MOV TIMECON, #13H; change TIMECON to measure in secs

RETI

 

MINS: MOV INTVAL, MIN; load the value of MIN into INTVAL

MOV TIMECON, #00h; clear TCEN to reset the registers

MOV TIMECON, #23H; change TIMECON to measure in mins

RETI

 

HOURS: MOV INTVAL, HOUR; load the value of HOUR onto INTVAL

MOV TIMECON, #00h; clear TCEN to reset the registers

MOV TIMECON, #33H; change TIMECON to measure in hours

RETI

;____________________________________________________________________

; TII INTERRUPT VECTOR SPACE

ORG 0053h

 

CPL LED; Complement the LED every time the

; measured time runs up.

RETI

;_____________________________________________________________________

 

ORG 0060h

 

MAIN:

 

; Configure Time Interval Counter

MOV PLLCON,#07H; Allow sufficient time for instructions to execute

MOV TIMECON, #03h; initialise timecon to count in 1/128s

; -set TCEN to enable the time clock

; -set TIEN to enable the TIC

; -clear STI to allow automatic relaod

; of interval timeout

; -clear TFH to disable 24 hr counting

 

MOV INTVAL, #0Ah; initialise to blink LED every 10 units

; the units are 1/128s

 

; Configure External Interrupt

SETB IT0; INT0 edge triggered

SETB EX0; enable INT0 (button on eval board)

MOV IEIP2,#04H; enable time interval interrupt

 

SETB EA; enable global interrupts

 

 

JMP $; wait here for interrupts

; main program can be inserted here

 

;____________________________________________________________________

 

END

 


<== предыдущая лекция | следующая лекция ==>
Короткі теоретичні відомості | Структура вузла АЦП в мікроконтролері ADuC841. Програмні драйвери зчитування інформаціїї
Поделиться с друзьями:


Дата добавления: 2014-01-14; Просмотров: 434; Нарушение авторских прав?; Мы поможем в написании вашей работы!


Нам важно ваше мнение! Был ли полезен опубликованный материал? Да | Нет



studopedia.su - Студопедия (2013 - 2024) год. Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав! Последнее добавление




Генерация страницы за: 0.024 сек.