Created
October 3, 2016 03:48
-
-
Save cpjk/25ffb4fca804b039f7141da1216d9edc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PAIN (volatile unsigned char *) 0xFFFFFFF0 | |
#define PAOUT (volatile unsigned char *) 0xFFFFFFF1 | |
#define PADIR (volatile unsigned char *) 0xFFFFFFF2 | |
#define PBIN (volatile unsigned char *) 0xFFFFFFF3 | |
#define PBOUT (volatile unsigned char *) 0xFFFFFFF4 | |
#define PBDIR (volatile unsigned char *) 0xFFFFFFF5 | |
#define CNTM (volatile unsigned int *) 0xFFFFFFD0 | |
#define CTCON (volatile unsigned char *) 0xFFFFFFD8 | |
#define CTSTAT (volatile unsigned char *) 0xFFFFFFD9 | |
#define PCONT (volatile unsigned char *) 0xFFFFFFF7 | |
#define IVECT (volatile unsigned int *) (0x20) | |
interrupt void intserv(); | |
unsigned char digit = 0; /* Digit to be displayed */ | |
unsigned char led = 0x1; /* LED state: 0/1 = on/off */ | |
int main() { | |
*PADIR = 0x0F; // set port A directions | |
*PBDIR = 0xFF; // set port B directions (all output) | |
*PCONT = 0x10; // enable interrupts when PAIN has input to be read | |
asm(“MoveControl PSR,#0x40”); // enable interrupts | |
*CTCON = 0x02; // turn countdown off initially and disable timer interrupt | |
*CNTM = 100000000; // set countdown timer to 1 second | |
*CTSTAT = 0x0; // clear "reached 0" bit | |
*CTCON = 0x01; // turn countdown on, but keep timer interrupts disabled | |
*IVECT = (unsigned int *) &intserv; // set interrupt vector | |
*PAOUT = 0x0; | |
while(1) { | |
while(*CTSTAT == 0x0); // "reached 0" bit not set | |
if(led == 0x0) { // LED is ON. Turn it OFF | |
led = 0x1; | |
} | |
else { | |
led 0x0; | |
} | |
*PBOUT = led; // set/unset LED bit in PBOUT | |
*CTSTAT = 0x0; // clear "reached 0" bit | |
*CNTM = 100000000; // set countdown timer to 1 second | |
} | |
} | |
// triggered when the value of PAIN has changed | |
interrupt void intserv() { | |
// button was released. it was pressed down prior to this | |
if((*PAIN & 0x80) != 0) { | |
digit = (digit + 1) % 10; // increment digit with rollover | |
*PAOUT = digit; // set display digit bits | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment