Created
October 3, 2016 03:48
-
-
Save cpjk/68fd4a0c4517473032c44ce30049d4de 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 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 = 0x0; /* LED state: 0/4 = on/off */ | |
int main() { | |
*PBDIR = 0xFC; // set port b directions | |
*CTCON = 0x02; // turn countdown off initially and disable timer interrupt | |
*CTSTAT = 0x0; // clear "reached 0" bit | |
*CNTM = 100000000; // set countdown timer to 1 second | |
*IVECT = (unsigned int *) &intserv; // set interrupt vector | |
asm(“MoveControl PSR,#0x40”); // enable interrupts | |
*PBOUT = 0x04; //set display to 0 and turn off LED (0) | |
*PCONT = 0x40; // SET ENBIN=1 - enable interrupts when PBIN is ready for writing | |
*CTCON = 0x01; // start countdown timer | |
while(1) { | |
while((*CTSTAT & 0x1) != 0x1); // "reached 0" bit not set | |
if(led == 0x0) { // LED is ON. Turn it OFF | |
led = 0x4; | |
} | |
else { | |
led 0x0; | |
} | |
*PBOUT = ((digit << 4) | led); // set/unset LED bit in PBOUT | |
*CTSTAT = 0x0; // clear "reached 0" bit | |
*CNTM = 100000000; // set countdown timer to 1 second | |
} | |
} | |
interrupt void intserv() { | |
if((*PBIN & 0x1) == 0) { // INC pressed | |
digit = (digit + 1) % 10; | |
} | |
else if ((*PBIN & 0x2) == 0){ // DEC pressed | |
digit = (digit - 1) % 10; | |
} | |
*PBOUT = ((digit << 4) | led); // set display digit bits | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment