forked from KolibriOS/kolibrios
2f54c7de00
git-svn-id: svn://kolibrios.org@8097 a494cfbc-eb01-0410-851d-a64ba20cac60
143 lines
3.5 KiB
Plaintext
143 lines
3.5 KiB
Plaintext
(*
|
|
Пример для STM32L152C-DISCO
|
|
|
|
Синий светодиод мигает по прерыванию от таймера TIM6,
|
|
зеленый - от TIM7.
|
|
*)
|
|
|
|
MODULE TIM67;
|
|
|
|
IMPORT SYSTEM;
|
|
|
|
|
|
CONST
|
|
|
|
GPIOB = 40020400H;
|
|
GPIOBMODER = GPIOB;
|
|
GPIOBOTYPER = GPIOB + 04H;
|
|
GPIOBOSPEEDR = GPIOB + 08H;
|
|
GPIOBPUPDR = GPIOB + 0CH;
|
|
GPIOBIDR = GPIOB + 10H;
|
|
GPIOBODR = GPIOB + 14H;
|
|
GPIOBBSRR = GPIOB + 18H;
|
|
GPIOBLCKR = GPIOB + 1CH;
|
|
GPIOBAFRL = GPIOB + 20H;
|
|
GPIOBAFRH = GPIOB + 24H;
|
|
GPIOBBRR = GPIOB + 28H;
|
|
|
|
|
|
RCC = 40023800H;
|
|
RCC_CR = RCC;
|
|
RCC_AHBENR = RCC + 1CH;
|
|
RCC_APB2ENR = RCC + 20H;
|
|
RCC_APB1ENR = RCC + 24H;
|
|
|
|
|
|
TIM6 = 40001000H;
|
|
TIM6_CR1 = TIM6;
|
|
CEN = {0};
|
|
UDIS = {1};
|
|
URS = {2};
|
|
OPM = {3};
|
|
ARPE = {7};
|
|
|
|
TIM6_CR2 = TIM6 + 04H;
|
|
|
|
TIM6_DIER = TIM6 + 0CH;
|
|
UIE = {0};
|
|
|
|
TIM6_SR = TIM6 + 10H;
|
|
UIF = {0};
|
|
|
|
TIM6_EGR = TIM6 + 14H;
|
|
UG = {0};
|
|
|
|
TIM6_CNT = TIM6 + 24H;
|
|
TIM6_PSC = TIM6 + 28H;
|
|
TIM6_ARR = TIM6 + 2CH;
|
|
|
|
|
|
TIM7 = 40001400H;
|
|
TIM7_CR1 = TIM7;
|
|
TIM7_CR2 = TIM7 + 04H;
|
|
TIM7_DIER = TIM7 + 0CH;
|
|
TIM7_SR = TIM7 + 10H;
|
|
TIM7_EGR = TIM7 + 14H;
|
|
TIM7_CNT = TIM7 + 24H;
|
|
TIM7_PSC = TIM7 + 28H;
|
|
TIM7_ARR = TIM7 + 2CH;
|
|
|
|
|
|
NVIC = 0E000E100H;
|
|
NVIC_ISER0 = NVIC;
|
|
NVIC_ISER1 = NVIC + 04H;
|
|
NVIC_ISER2 = NVIC + 08H;
|
|
|
|
NVIC_ICER0 = NVIC + 80H;
|
|
NVIC_ICER1 = NVIC + 84H;
|
|
NVIC_ICER2 = NVIC + 88H;
|
|
|
|
|
|
BLUELED = 6;
|
|
GREENLED = 7;
|
|
|
|
|
|
VAR
|
|
x: SET;
|
|
state1, state2: BOOLEAN;
|
|
|
|
|
|
(* обработчик прерываний от TIM6 *)
|
|
PROCEDURE tim6 [59];
|
|
BEGIN
|
|
SYSTEM.PUT(TIM6_SR, 0); (* сбросить флаг прерывания *)
|
|
state1 := ~state1;
|
|
(* включить или выключить синий светодиод *)
|
|
SYSTEM.PUT(GPIOBBSRR, {BLUELED + 16 * ORD(state1)})
|
|
|
|
END tim6;
|
|
|
|
|
|
(* обработчик прерываний от TIM7 *)
|
|
PROCEDURE tim7 [60];
|
|
BEGIN
|
|
SYSTEM.PUT(TIM7_SR, 0); (* сбросить флаг прерывания *)
|
|
state2 := ~state2;
|
|
(* включить или выключить зеленый светодиод *)
|
|
SYSTEM.PUT(GPIOBBSRR, {GREENLED + 16 * ORD(state2)})
|
|
END tim7;
|
|
|
|
|
|
BEGIN
|
|
state1 := FALSE;
|
|
state2 := FALSE;
|
|
|
|
(* подключить GPIOB *)
|
|
SYSTEM.GET(RCC_AHBENR, x);
|
|
SYSTEM.PUT(RCC_AHBENR, x + {1});
|
|
|
|
(* подключить TIM6 и TIM7 *)
|
|
SYSTEM.GET(RCC_APB1ENR, x);
|
|
SYSTEM.PUT(RCC_APB1ENR, x + {4, 5});
|
|
|
|
(* настроить PB6 и PB7 на выход *)
|
|
SYSTEM.GET(GPIOBMODER, x);
|
|
SYSTEM.PUT(GPIOBMODER, x + {12, 14} - {13, 15});
|
|
|
|
(* разрешить прерывания от таймеров TIM6 (позиция 43) и TIM7 (позиция 44) *)
|
|
SYSTEM.PUT(NVIC_ISER1, {11, 12});
|
|
|
|
(* настроить и запустить TIM6 *)
|
|
SYSTEM.PUT(TIM6_ARR, 31);
|
|
SYSTEM.PUT(TIM6_PSC, 65535);
|
|
SYSTEM.PUT(TIM6_DIER, UIE);
|
|
SYSTEM.GET(TIM6_CR1, x);
|
|
SYSTEM.PUT(TIM6_CR1, x + CEN - (UDIS + URS + OPM + ARPE));
|
|
|
|
(* настроить и запустить TIM7 *)
|
|
SYSTEM.PUT(TIM7_ARR, 8000);
|
|
SYSTEM.PUT(TIM7_PSC, 80);
|
|
SYSTEM.PUT(TIM7_DIER, UIE);
|
|
SYSTEM.GET(TIM7_CR1, x);
|
|
SYSTEM.PUT(TIM7_CR1, x + CEN - (UDIS + URS + OPM + ARPE));
|
|
END TIM67. |