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
00001 #include "mbed.h" 00002 00003 00004 00005 InterruptIn iiUp(p15); 00006 DigitalIn diUp(p15); 00007 00008 InterruptIn iiDown(p12); 00009 DigitalIn diDown(p12); 00010 00011 BusOut leds(LED1, LED2, LED3, LED4); 00012 00013 // prototypes 00014 00015 // functions 00016 // Diese Funktion ist zum Entprellen von Tastern geeignet: 00017 // Durch den zusätzlichen Code kann eine Entprellzeit von durchschnittlich 1,5-4ms 00018 // (mindestens 8*150us = 1,2ms) erreicht werden. 00019 // Grundsätzlich prüft die Funktion den Pegel des Pins eines DigitalIn. 00020 // Wenn der Pegel 8 Mal konstant war, wird die Schleife verlassen. 00021 // Diese Funktion kann sehr gut eingesetzt werden, um in einer Endlosschleife Taster 00022 // anzufragen, da sie, wie erwähnt, eine kurze Wartezeit hat. 00023 uint8x_t debounce(DigitalIn myIn) 00024 { 00025 #define LEVEL_CHECKS 8 00026 #define MAX_LOOPS 30 // stoppt das Überprüfen des Prellen nach max. MAX_LOOPS Durchläufen 00027 unsigned char port_buffer; 00028 unsigned char debounceCounter = 0; 00029 uint8x_t loopCounter = 0; 00030 00031 do { 00032 port_buffer = myIn; 00033 wait_us(150); 00034 loopCounter++; 00035 if(myIn == port_buffer) 00036 debounceCounter++; // mindestens 'LEVEL_CHECKS' Abtastungen in Folge: gleicher Pegel 00037 else 00038 debounceCounter = 0; 00039 } while ((debounceCounter <= LEVEL_CHECKS) && (loopCounter <= MAX_LOOPS)); 00040 return loopCounter; 00041 } 00042 00043 // ISR 00044 void cntUp() 00045 { 00046 debounce(diUp); 00047 leds = leds + 1; 00048 } 00049 00050 void cntDown() 00051 { 00052 debounce(diDown); 00053 leds = leds - 1; 00054 } 00055 00056 00057 // main program 00058 int main() 00059 { 00060 iiUp.rise(&cntUp); 00061 iiDown.rise(&cntDown); 00062 while(1) { 00063 } 00064 }
Generated on Fri Jul 15 2022 04:23:10 by
 1.7.2
 1.7.2