Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #define PAOUT (volatile unsigned char *) 0xFFFFFFF1
  2. //needs change to be PBOUT -> 0xFFFFFFF.
  3. #define PBIN (volatile unsigned char *) 0xFFFFFFF3
  4.  
  5. //set both inputs to 1 because start unpressed.
  6. #define PBDIR (volatile unsigned char *) 0xFFFFFFF5
  7. #define CNTM (volatile unsigned int *) 0xFFFFFFD0
  8. #define CTCON (volatile unsigned char *) 0xFFFFFFD8
  9. #define CTSTAT (volatile unsigned char *) 0xFFFFFFD9
  10. #define IVECT (volatile unsigned int *) (0x20)
  11.  
  12. interrupt void intserv();
  13. unsigned char digit = 0; /* Digit to be displayed, init to 0. */
  14.  
  15. int main() {
  16.  
  17. *PBDIR = 0x00; /* Set Port B direction to input */
  18. *CTCON = 0x02; /* Stop Timer */
  19. *CTSTAT = 0x0; /* Clear “reached 0” flag */
  20. *CNTM = 100000000; /* Initialize Timer */
  21. *IVECT = (unsigned int *) &intserv; /* Set interrupt vector */
  22. asm(“MoveControl PSR,#0x40”); /* CPU responds to IRQ */
  23. *CTCON = 0x11; /* Enable Timer interrupts & start counting */
  24. *PBOUT = 0x00; /* Display 0 */
  25.  
  26. while (1) { //our actual program, setup already completed.
  27.  
  28. while ((*PBIN & 0x2) != 0); /* Wait until E SW is pressed */
  29. while ((*PBIN & 0x2) == 0); /* Wait until E SW is released */
  30.  
  31. // bitwise AND &, good way to implement don't cares.
  32. //handles the press/depress for E switch
  33. //DO THE COUNTING.
  34. *PBOUT = (digit << 4); /* Update Port B */
  35. /* We can also put “*CTCON &= 0xEF;” before and “*CTCON |= 0x10;”
  36. * after the last statement, to make sure that intserv() is not
  37. * interfering with main() accessing shared digit/led/PAOUT */
  38.  
  39. while((*PBIN & 0x1) != 0);
  40. while(*PBIN & 0x1) == 0));
  41.  
  42. *PBOUT = (0 << 4)
  43.  
  44. }
  45. exit(0);
  46. }
  47.  
  48. interrupt void intserv() {
  49. *CTSTAT = 0x0; /* Clear “reached 0” flag */
  50. digit = (digit + 1)%10; /* Increment digit */
  51. *PBOUT = ((digit << 4)); /* Update Port B */
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement