SHARE
TWEET

Untitled

a guest Sep 23rd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define PBIN (volatile unsigned char *) 0xFFFFFFF3
  2. #define PBOUT (volatile unsigned char *) 0xFFFFFFF4
  3. #define PBDIR (volatile unsigned char *) 0xFFFFFFF5
  4. #define PCONT (volatile unsigned char *) 0xFFFFFFF7
  5. #define CNTM (volatile unsigned char *) 0xFFFFFFD0
  6. #define CTCON (volatile unsigned char *) 0xFFFFFFD8
  7. #define CTSTAT (volatile unsigned char *) 0xFFFFFFD9
  8. #define IVECT (volatile unsigned char *) 0x20
  9. /*Setup should all be same as part A but need a few more vars*/
  10. interrupt void intserv();
  11.  
  12. int main() {
  13.     char digit = 0;     /*Digit for disp*/
  14.    
  15.     *PBDIR = 0xF0;      /*Port B dir as output */
  16.     *CTCON = 0x2;       /*Stop Timer*/
  17.     *CSTAT = 0x0;       /* Clear 'reached 0' flag*/
  18.     *CNTM = 100000000;  /*Initialize timer */
  19.     *PBOUT = 0x0;           /*Display 0*/
  20.    
  21.     *IVECT = (unsigned int * ) &intserv; /*Set Interuppt vec*/
  22.     asm("MoveControl PSR, #0x40");      /*CPU responds to IRQ*/
  23.     *PCONT = 0x40;                      /*Enable PBIN interrupts*/
  24.    
  25.    
  26.     while(1) {
  27.         while((*CTSTAT & 0x1) == 0);
  28.         *CSTAT = 0x0;
  29.         digit = (digit + 1)%10;
  30.         *PBOUT = digit << 4;
  31.     }
  32.    
  33.     exit(0);
  34. }
  35.  
  36. interrupt void intserv() {
  37.     unsigned char sample; /*Port B input sample*/
  38.     sample = *PBIN & 0x3; /*Sample PBIN, isolate bits [1:0] */
  39.     if (sample == 0x1) *CTCON = 0x1; /*start timer*/
  40.     else if (sample == 0x2) *CTCON = 0x2; /*Stop timer*/
  41.    
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top