SHARE
TWEET

NewProgram

a guest Dec 3rd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   //interrupt routine
  2. void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)
  3. {
  4.     flag = 1;
  5. }
  6.  
  7. bit flag;
  8.  
  9.  //main loop
  10.     while(1)
  11.     {
  12.         // Prepare data every iteration, if needed
  13.         if(i2s_addData(chls, false))
  14.         {
  15.             n++;
  16.             chls[0] = 16400*sin(1256*n/48000);
  17.         }
  18.         // Write data to port if interrupt has been called
  19.         // Downside: writeout may not happen immediatly
  20.         // Upside: writout is in main loop, so guaranteed to be in sync with dataPrepare
  21.         if (flag == 1) {
  22.             flag = 0;
  23.            
  24.             loadShift();               //load the shift registers and inhibi    
  25.             // Perform data writout to port.
  26.             while(SCLK);;
  27.             SHIFT_INH = 0;
  28.    
  29.             IFS0bits.T1IF = 0;          //Clear Timer1 interrupt flag
  30.             PORTBbits.RB9 ^= 1;
  31.    
  32.             //selecteer de volgende dataset de laatste byte is verstuurt
  33.             inTrans.index++;
  34.             if(inTrans.index == BYTESPERFSYNC)  
  35.             {
  36.                 inTrans = queued;
  37.             }
  38.             dataToPort();               //prepare next data set
  39.         }
  40.        /* if(AMP_checkError())
  41.         {
  42.             pcbLeds_write(0x05);        
  43.         }*/
  44.     }
  45.  
  46.  
  47. //fuctie die de data voorbereid voor de interrupt functie
  48. bool i2s_addData(signed int chl[], bool overWrite)
  49. {
  50.    
  51.     if(inTrans.order != queued.order) return false;;
  52.    
  53.     chl[0] = (chl[0] ^ 0xffff) +1;
  54.     chl[1] = (chl[1] ^ 0xffff) +1;
  55.     chl[2] = (chl[2] ^ 0xffff) +1;
  56.     chl[3] = (chl[3] ^ 0xffff) +1;
  57.    
  58.     queued.data1[0].val = chl[0];
  59.     queued.data1[1].val = chl[0]>>8;
  60.     queued.data1[2].val = chl[1];
  61.     queued.data1[3].val = chl[1]>>8;
  62.    
  63.     queued.data2[0].val = chl[2];
  64.     queued.data2[1].val = chl[2]>>8;
  65.     queued.data2[2].val = chl[3];
  66.     queued.data2[3].val = chl[3]>>8;
  67.    
  68.     queued.index = 0;
  69.     queued.order = inTrans.order + 1;
  70.     return true;
  71. }
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