forked from KolibriOS/kolibrios
114 lines
2.8 KiB
Plaintext
114 lines
2.8 KiB
Plaintext
|
(*
|
||
|
Пример для STM32L152C-DISCO
|
||
|
|
||
|
При нажатии на кнопку USER (PA0), меняется
|
||
|
состояние светодиодов.
|
||
|
*)
|
||
|
|
||
|
MODULE Button;
|
||
|
|
||
|
IMPORT SYSTEM;
|
||
|
|
||
|
|
||
|
CONST
|
||
|
|
||
|
GPIOA = 40020000H;
|
||
|
GPIOAMODER = GPIOA;
|
||
|
GPIOAOTYPER = GPIOA + 04H;
|
||
|
GPIOAOSPEEDR = GPIOA + 08H;
|
||
|
GPIOAPUPDR = GPIOA + 0CH;
|
||
|
GPIOAIDR = GPIOA + 10H;
|
||
|
GPIOAODR = GPIOA + 14H;
|
||
|
GPIOABSRR = GPIOA + 18H;
|
||
|
GPIOALCKR = GPIOA + 1CH;
|
||
|
GPIOAAFRL = GPIOA + 20H;
|
||
|
GPIOAAFRH = GPIOA + 24H;
|
||
|
GPIOABRR = GPIOA + 28H;
|
||
|
|
||
|
|
||
|
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;
|
||
|
|
||
|
|
||
|
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;
|
||
|
|
||
|
|
||
|
EXTI = 040010400H;
|
||
|
EXTI_IMR = EXTI;
|
||
|
EXTI_RTSR = EXTI + 08H;
|
||
|
EXTI_FTSR = EXTI + 0CH;
|
||
|
EXTI_PR = EXTI + 14H;
|
||
|
|
||
|
|
||
|
LINE0 = {0};
|
||
|
|
||
|
Blue = 6;
|
||
|
Green = 7;
|
||
|
|
||
|
|
||
|
VAR
|
||
|
x: SET;
|
||
|
state: INTEGER;
|
||
|
|
||
|
|
||
|
(* обработчик прерываний от EXTI0 *)
|
||
|
PROCEDURE PushButton [22];
|
||
|
BEGIN
|
||
|
SYSTEM.PUT(EXTI_PR, LINE0); (* сбросить флаг прерывания *)
|
||
|
state := (state + 1) MOD 4;
|
||
|
(* изменить состояние светодиодов *)
|
||
|
CASE state OF
|
||
|
|0: SYSTEM.PUT(GPIOBBSRR, {Blue + 16, Green + 16})
|
||
|
|1: SYSTEM.PUT(GPIOBBSRR, {Blue, Green + 16})
|
||
|
|2: SYSTEM.PUT(GPIOBBSRR, {Blue + 16, Green})
|
||
|
|3: SYSTEM.PUT(GPIOBBSRR, {Blue, Green})
|
||
|
END
|
||
|
END PushButton;
|
||
|
|
||
|
|
||
|
BEGIN
|
||
|
state := 0;
|
||
|
|
||
|
(* подключить GPIOA и GPIOB *)
|
||
|
SYSTEM.GET(RCC_AHBENR, x);
|
||
|
SYSTEM.PUT(RCC_AHBENR, x + {0, 1});
|
||
|
|
||
|
(* настроить PB6 и PB7 на выход *)
|
||
|
SYSTEM.GET(GPIOBMODER, x);
|
||
|
SYSTEM.PUT(GPIOBMODER, x + {12, 14} - {13, 15});
|
||
|
|
||
|
(* настроить PA0 на вход *)
|
||
|
SYSTEM.GET(GPIOAMODER, x);
|
||
|
SYSTEM.PUT(GPIOAMODER, x - {0, 1});
|
||
|
|
||
|
(* разрешить прерывания от EXTI0 (позиция 6) *)
|
||
|
SYSTEM.PUT(NVIC_ISER0, {6});
|
||
|
|
||
|
(* разрешить прерывания от LINE0 по нарастающему краю импульса *)
|
||
|
SYSTEM.PUT(EXTI_IMR, LINE0);
|
||
|
SYSTEM.PUT(EXTI_RTSR, LINE0);
|
||
|
END Button.
|