Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:1c81da9fba37, 2021-05-27 (annotated)
- Committer:
- jack1930
- Date:
- Thu May 27 15:01:17 2021 +0000
- Revision:
- 0:1c81da9fba37
HP1920A1
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jack1930 | 0:1c81da9fba37 | 1 | /* mbed Microcontroller Library |
| jack1930 | 0:1c81da9fba37 | 2 | * Copyright (c) 2019 ARM Limited |
| jack1930 | 0:1c81da9fba37 | 3 | * SPDX-License-Identifier: Apache-2.0 |
| jack1930 | 0:1c81da9fba37 | 4 | */ |
| jack1930 | 0:1c81da9fba37 | 5 | |
| jack1930 | 0:1c81da9fba37 | 6 | #include "mbed.h" |
| jack1930 | 0:1c81da9fba37 | 7 | |
| jack1930 | 0:1c81da9fba37 | 8 | DigitalIn TE(PB_4); |
| jack1930 | 0:1c81da9fba37 | 9 | DigitalIn TA(PB_3); |
| jack1930 | 0:1c81da9fba37 | 10 | DigitalIn LS(PB_7); |
| jack1930 | 0:1c81da9fba37 | 11 | InterruptIn HALT(PB_0); |
| jack1930 | 0:1c81da9fba37 | 12 | PortOut ausgaenge(PortC,0x0F); |
| jack1930 | 0:1c81da9fba37 | 13 | DigitalOut Schieber(PC_0); |
| jack1930 | 0:1c81da9fba37 | 14 | DigitalOut Motor(PC_1); |
| jack1930 | 0:1c81da9fba37 | 15 | DigitalOut Luefter(PC_2); |
| jack1930 | 0:1c81da9fba37 | 16 | DigitalOut Pumpe(PC_3); |
| jack1930 | 0:1c81da9fba37 | 17 | |
| jack1930 | 0:1c81da9fba37 | 18 | DigitalOut warnlampe(PC_7); |
| jack1930 | 0:1c81da9fba37 | 19 | InterruptIn impuls(PA_1); |
| jack1930 | 0:1c81da9fba37 | 20 | volatile int z=0; |
| jack1930 | 0:1c81da9fba37 | 21 | |
| jack1930 | 0:1c81da9fba37 | 22 | |
| jack1930 | 0:1c81da9fba37 | 23 | DigitalOut test(PC_6); |
| jack1930 | 0:1c81da9fba37 | 24 | |
| jack1930 | 0:1c81da9fba37 | 25 | |
| jack1930 | 0:1c81da9fba37 | 26 | |
| jack1930 | 0:1c81da9fba37 | 27 | void HALT_ISR() |
| jack1930 | 0:1c81da9fba37 | 28 | { |
| jack1930 | 0:1c81da9fba37 | 29 | unsigned char merker; |
| jack1930 | 0:1c81da9fba37 | 30 | merker=ausgaenge; |
| jack1930 | 0:1c81da9fba37 | 31 | ausgaenge=0; |
| jack1930 | 0:1c81da9fba37 | 32 | while(HALT==0); |
| jack1930 | 0:1c81da9fba37 | 33 | ausgaenge=merker; |
| jack1930 | 0:1c81da9fba37 | 34 | } |
| jack1930 | 0:1c81da9fba37 | 35 | |
| jack1930 | 0:1c81da9fba37 | 36 | void impulsISR() |
| jack1930 | 0:1c81da9fba37 | 37 | { |
| jack1930 | 0:1c81da9fba37 | 38 | z++; |
| jack1930 | 0:1c81da9fba37 | 39 | //test=1; |
| jack1930 | 0:1c81da9fba37 | 40 | } |
| jack1930 | 0:1c81da9fba37 | 41 | |
| jack1930 | 0:1c81da9fba37 | 42 | void isrTIM6() |
| jack1930 | 0:1c81da9fba37 | 43 | { |
| jack1930 | 0:1c81da9fba37 | 44 | test=!test; |
| jack1930 | 0:1c81da9fba37 | 45 | if (z<50) |
| jack1930 | 0:1c81da9fba37 | 46 | { |
| jack1930 | 0:1c81da9fba37 | 47 | warnlampe=1; |
| jack1930 | 0:1c81da9fba37 | 48 | } |
| jack1930 | 0:1c81da9fba37 | 49 | else |
| jack1930 | 0:1c81da9fba37 | 50 | { |
| jack1930 | 0:1c81da9fba37 | 51 | warnlampe=0; |
| jack1930 | 0:1c81da9fba37 | 52 | } |
| jack1930 | 0:1c81da9fba37 | 53 | z=0; |
| jack1930 | 0:1c81da9fba37 | 54 | TIM6->SR=0; //Überlaufflag zurücksetzen |
| jack1930 | 0:1c81da9fba37 | 55 | HAL_NVIC_ClearPendingIRQ(TIM6_IRQn); //Pendingbit NVIC zurücksetzen |
| jack1930 | 0:1c81da9fba37 | 56 | } |
| jack1930 | 0:1c81da9fba37 | 57 | |
| jack1930 | 0:1c81da9fba37 | 58 | void init() { |
| jack1930 | 0:1c81da9fba37 | 59 | //Für die Demoplatine sind Pulldowns erfotderlich |
| jack1930 | 0:1c81da9fba37 | 60 | TE.mode(PullDown); |
| jack1930 | 0:1c81da9fba37 | 61 | TA.mode(PullDown); |
| jack1930 | 0:1c81da9fba37 | 62 | LS.mode(PullDown); |
| jack1930 | 0:1c81da9fba37 | 63 | HALT.mode(PullDown); |
| jack1930 | 0:1c81da9fba37 | 64 | |
| jack1930 | 0:1c81da9fba37 | 65 | //für die Abiaufgabe |
| jack1930 | 0:1c81da9fba37 | 66 | HALT.fall(&HALT_ISR); |
| jack1930 | 0:1c81da9fba37 | 67 | HALT.enable_irq(); |
| jack1930 | 0:1c81da9fba37 | 68 | __enable_irq(); |
| jack1930 | 0:1c81da9fba37 | 69 | |
| jack1930 | 0:1c81da9fba37 | 70 | //Lüfterüberwachung |
| jack1930 | 0:1c81da9fba37 | 71 | impuls.fall(&impulsISR); |
| jack1930 | 0:1c81da9fba37 | 72 | impuls.enable_irq(); |
| jack1930 | 0:1c81da9fba37 | 73 | //Timer TIM6 |
| jack1930 | 0:1c81da9fba37 | 74 | RCC->APB1ENR |= 0b10000; //TIM6 mit Takt versorgen |
| jack1930 | 0:1c81da9fba37 | 75 | TIM6->PSC=31999; //Prescaler für 1ms |
| jack1930 | 0:1c81da9fba37 | 76 | TIM6->CNT=0; //Zähler bei 0 starten |
| jack1930 | 0:1c81da9fba37 | 77 | TIM6->ARR=999; //Autoreload für 1s (0.999 = 1000 Zähltakte |
| jack1930 | 0:1c81da9fba37 | 78 | TIM6->SR=0; //Überlaufflag zurücksetzen |
| jack1930 | 0:1c81da9fba37 | 79 | TIM6->DIER=1; //Imterrupt freigeben Timer |
| jack1930 | 0:1c81da9fba37 | 80 | NVIC_SetVector(TIM6_IRQn, (uint32_t)&isrTIM6); //ISR zuordnen |
| jack1930 | 0:1c81da9fba37 | 81 | HAL_NVIC_EnableIRQ(TIM6_IRQn); //Interrupt freigeben NVIC |
| jack1930 | 0:1c81da9fba37 | 82 | TIM6->CR1=1; //Timer starten |
| jack1930 | 0:1c81da9fba37 | 83 | } |
| jack1930 | 0:1c81da9fba37 | 84 | |
| jack1930 | 0:1c81da9fba37 | 85 | |
| jack1930 | 0:1c81da9fba37 | 86 | int main() |
| jack1930 | 0:1c81da9fba37 | 87 | { |
| jack1930 | 0:1c81da9fba37 | 88 | init(); |
| jack1930 | 0:1c81da9fba37 | 89 | |
| jack1930 | 0:1c81da9fba37 | 90 | while (true) { |
| jack1930 | 0:1c81da9fba37 | 91 | ausgaenge=0b0000; |
| jack1930 | 0:1c81da9fba37 | 92 | while (TE==0); |
| jack1930 | 0:1c81da9fba37 | 93 | ausgaenge=0b1110; |
| jack1930 | 0:1c81da9fba37 | 94 | while (LS==0); |
| jack1930 | 0:1c81da9fba37 | 95 | ausgaenge=0b1111; |
| jack1930 | 0:1c81da9fba37 | 96 | while (TA==0); |
| jack1930 | 0:1c81da9fba37 | 97 | ausgaenge=0b0111; |
| jack1930 | 0:1c81da9fba37 | 98 | while (LS==1); |
| jack1930 | 0:1c81da9fba37 | 99 | } |
| jack1930 | 0:1c81da9fba37 | 100 | } |