Jörg Sturm
/
Vorlage
Encoder
Revision 0:46dbd1b71de5, committed 2020-02-20
- Comitter:
- JoergSturm
- Date:
- Thu Feb 20 17:40:36 2020 +0000
- Commit message:
- Vorlage offline
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 20 17:40:36 2020 +0000 @@ -0,0 +1,60 @@ +#include "mbed.h" + +DigitalOut myled(LED1); +DigitalOut Center(PA_9); +DigitalIn Port0(PA_8); +DigitalIn Port1(PA_10); + +PortOut C(PortC,0xFF); +InterruptIn irqA(PA_1); +InterruptIn irq0(PA_8); +InterruptIn irq1(PA_10); + +int z=0,Zustand=0,Zustandalt=0; + +void isr(void) +{ + myled=!myled; + +} + +void isrEnc(void) +{ + Zustandalt=Zustand; + if (Port0==0 && Port1==0) Zustand=0; + if (Port0==1 && Port1==0) Zustand=1; + if (Port0==1 && Port1==1) Zustand=2; + if (Port0==0 && Port1==1) Zustand=3; + if (Zustandalt==3 && Zustand==0) z++; + if (Zustandalt==0 && Zustand == 3) z--; + C=(z<<2)+Zustand; +} + +int main() { + Center=1; + // Port0.mode(PullDown); + // Port1.mode(PullDown); + irqA.rise(&isr); + irqA.mode(PullDown); + irq0.rise(&isrEnc); + irq0.fall(&isrEnc); + irq0.mode(PullDown); + irq1.rise(&isrEnc); + irq1.fall(&isrEnc); + irq1.mode(PullDown); + + RCC->AHBENR|=0b100; + GPIOC->MODER=0x5555; + //GPIOC->ODR=0x55; + C=0; + while(1) { + + /* + myled = 1; // LED is ON + wait(0.2); // 200 ms + myled = 0; // LED is OFF + wait(1.0); // 1 sec + C=0; + */ + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Feb 20 17:40:36 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file