hallo allerseits.
Sitze seit tagen vor einer kleinen Aufgabe zur
Mikrocontroller-Programmierung.
Es geht um ein LED-Lauflicht, das mit Hilfe von Keyboard-Interrupts auf
dem Port a unterbrochen und wieder gestartet werden soll.
Habe folgendes zusammengeschustert:
(selbst geschrieben ist im Grunde nur der Teil,
der mit Interrupt und Port a zusaemmenhaengt)
1 | #include <hidef.h> /* for EnableInterrupts macro */
|
2 | #include "derivative.h" /* include peripheral declarations */
|
3 |
|
4 | int delay = 50;
|
5 |
|
6 |
|
7 | // eine simple delay Funktion die soweit vorgegeben war
|
8 | static void Delay(void) {
|
9 | int cnt=0;
|
10 | while (cnt <delay) {
|
11 | __RESET_WATCHDOG();
|
12 | cnt++;
|
13 | }}
|
14 |
|
15 |
|
16 | // die Hauptfunktion, in der ich versucht habe, dem Programm beizubringen, // nur bei gesetztem interrupt weiterzugehen
|
17 | #pragma TRAP_PROC
|
18 | void Lightshow (void) {
|
19 | unsigned char i;
|
20 | for (i=1; i>0; i<<=1) {
|
21 |
|
22 | // nur wenn port a == 1 soll das programm weiterlaufen
|
23 | while (PTA == 1) {
|
24 | PTB = i;
|
25 | Delay();
|
26 | // Keaboard Acknowledge bit löschen
|
27 | KBSCR_ACKK = 1;
|
28 | }}}
|
29 |
|
30 | void main(void) {
|
31 |
|
32 | //zuweisung des interrupts an port a
|
33 | DDRA = 0x00;
|
34 | KBSCR_MODEK = 0;
|
35 | KBSCR_IMASKK = 0;
|
36 | KBIER = 0x01;
|
37 |
|
38 |
|
39 | DDRB = 0xFF;
|
40 | PTB = 0x0;
|
41 |
|
42 |
|
43 | EnableInterrupts;
|
44 | for(;;) {
|
45 | Lightshow();
|
46 | // __RESET_WATCHDOG(); /* feeds the dog */
|
47 | } /* loop forever */
|
48 | /* please make sure that you never leave main */
|
49 | }
|
Wäre super wenn jemand mir sagen koennte, wie zum Geier ich hier weiter
kaeme.