⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msp430-fw-dds[1].c

📁 老外用DDSAD9854和MSP430做的一个收音机的源程序.
💻 C
📖 第 1 页 / 共 2 页
字号:

      // 3 x 8 bit = 24 bit

      tmp = scn;
      DDS_DATA_OUT = 0x04; setBit(DDS_CTRL_OUT,DDS_ALE); clrBit(DDS_CTRL_OUT,DDS_ALE);
      DDS_DATA_OUT = (tmp>>24)&0xFF; clrBit(DDS_CTRL_OUT,DDS_NWR); setBit(DDS_CTRL_OUT,DDS_NWR);

      tmp = scn;
      DDS_DATA_OUT = 0x05; setBit(DDS_CTRL_OUT,DDS_ALE); clrBit(DDS_CTRL_OUT,DDS_ALE);
      DDS_DATA_OUT = (tmp>>16)&0xFF; clrBit(DDS_CTRL_OUT,DDS_NWR); setBit(DDS_CTRL_OUT,DDS_NWR);

      tmp = scn;
      DDS_DATA_OUT = 0x06; setBit(DDS_CTRL_OUT,DDS_ALE); clrBit(DDS_CTRL_OUT,DDS_ALE);
      DDS_DATA_OUT = (tmp>>8)&0xFF; clrBit(DDS_CTRL_OUT,DDS_NWR); setBit(DDS_CTRL_OUT,DDS_NWR);

      DDS_DATA_OUT = 0x07; setBit(DDS_CTRL_OUT,DDS_ALE); clrBit(DDS_CTRL_OUT,DDS_ALE);
      DDS_DATA_OUT = 0xFF; clrBit(DDS_CTRL_OUT,DDS_NWR); setBit(DDS_CTRL_OUT,DDS_NWR);
      DDS_DATA_OUT = 0x08; setBit(DDS_CTRL_OUT,DDS_ALE); clrBit(DDS_CTRL_OUT,DDS_ALE);
      DDS_DATA_OUT = 0xFF; clrBit(DDS_CTRL_OUT,DDS_NWR); setBit(DDS_CTRL_OUT,DDS_NWR);
      DDS_DATA_OUT = 0x09; setBit(DDS_CTRL_OUT,DDS_ALE); clrBit(DDS_CTRL_OUT,DDS_ALE);
      DDS_DATA_OUT = 0xFF; clrBit(DDS_CTRL_OUT,DDS_NWR); setBit(DDS_CTRL_OUT,DDS_NWR);

      DDS_commit();

      if(kbdUnreadCount>0)
       {
         LCD_writeHexByte(kbdGetChar());
         LCD_writeChar('/');
      }

      if(wheel_counter<0)
         { wheel_counter=0; dir=NEG_STEP; LCD_writeChar('-'); }
      if(wheel_counter>0)
         { wheel_counter=0; dir=POS_STEP; LCD_writeChar('+'); }
   }
   
   return;
}



//-------------------------------------------------------------------
// DDS_manualscan ( )
//
// Manual frequency scanning loop, function does NOT return but
// checks the serial and keyboard data, and tuning wheel state.
// 
void DDS_manualscan(void) 
{
   long long oldTW;
   unsigned char metres; 
   char *out;
   
   DDS_DATA_DIR = 0xFF;

   // load DDS multipliers (just to be safe)
   DDS_writeByte(0xFF, 0x21);
   DDS_writeByte(0xFF, 0x22);
   DDS_writeByte(0xFF, 0x23);
   DDS_writeByte(0xFF, 0x24);
   
   // set startup frequency
   DDS_writeLongTuningword(dds_lo_tw);
   DDS_commit();
   out = DDS_Tuningword2FreqStr(dds_lo_tw,1);
   if(1==FWConfig.LCD_enabled) { 
      LCD_home(2);
      LCD_writeString(out);
   }
   PC_writeString("FREQ ");
   PC_writeString(&freq_str[12]);
   PC_writeString((char*)STR_CRLF);
   
   // -- user tuning
   //kbdResume();

   while(1) {

      oldTW=dds_lo_tw;

      // handle remote commands from PC and local keyboard entry
      processCmdPC();
      processCmdKeyboard();

      // tuning wheel turned?
      if((wheel_counter/dds_wheeldivider)<0 ) { //&& (dds_lo_tw>=SCAN_LIM_LO)) {
         wheel_counter+=WHEEL_DIV_RESO; dds_lo_tw -= dds_delta;
         //if((dds_lo_tw<SCAN_LIM_LO) || (dds_lo_tw>SCAN_LIM_HI)) dds_lo_tw=SCAN_LIM_LO;
      }
      if((wheel_counter/dds_wheeldivider)>0 ) { // && (dds_lo_tw<=SCAN_LIM_HI)) {
         wheel_counter-=WHEEL_DIV_RESO; dds_lo_tw += dds_delta;
         //if((dds_lo_tw<SCAN_LIM_LO) || (dds_lo_tw>SCAN_LIM_HI)) dds_lo_tw=SCAN_LIM_HI;
      }

//>>DEBUG
      if(dds_lo_tw>SCAN_LIM_HI) { PC_writeChar('#'); }
      //if((dds_lo_tw<SCAN_LIM_LO) || (dds_lo_tw>SCAN_LIM_HI)) dds_lo_tw=DEFAULT_LO_TW;
//>>
      
      // update the DDS freq and user display?
      if(oldTW!=dds_lo_tw) {
   
         DDS_writeLongTuningword(dds_lo_tw);
         DDS_commit();

         out = DDS_Tuningword2FreqStr(dds_lo_tw,1);

         // write to PC 
         PC_writeString("FREQ ");
         PC_writeString(&freq_str[12]);
         PC_writeString((char*)STR_CRLF);
         // write to LCD if enabled
         if(1==FWConfig.LCD_enabled) {
            LCD_home(2);
            out = DDS_Tuningword2FreqStr(dds_lo_tw,1);
            LCD_writeString(out);
         
            metres = getBandMetres((dds_lo_tw/1000)/DDS_1HZ_STEP);
            if(metres!=0) {
               LCD_writeChar(' ');
               if(metres>99) { 
                  LCD_writeChar('1');
                  metres%=100; 
               }
               if(metres>9) { 
                  LCD_writeChar('0'+metres/10);
                  metres%=10;
               }
               LCD_writeChar('0'+metres);
               LCD_writeChar('m');
               LCD_writeChar(' ');
               LCD_writeChar(' ');
            } else {
               LCD_writeString("      \0");
            }
            
            //DDS_Smeter(5); // todo: use msp430 internal ADC
            
         }
      }

  }//(infinite loop)

}




//===================================================================
//
//       UI HELPERS
//


//-------------------------------------------------------------------
// long DDS_Tuningword2Freq ( long long )
//
// Converts the tuning word into Hertz.
// 
unsigned long DDS_Tuningword2Freq(long long tuningword)
{
   // f_dds = (ref*multipl) * tuningword / 2^48
   //          200 MHz * tuningword / 2^48 = tw / (2^48/200E6)
   //       = tw / 1407374.884 [Hz]
   return (unsigned long) ( ((unsigned long long)tuningword / (unsigned long long)DDS_1HZ_STEP) );
}


//-------------------------------------------------------------------
// char* DDS_Tuningword2FreqStr ( long long, char )
//
// Creates a string representation in Hz of the specified DDS 
// tuning word. Formatting is in both LCD style, which is 
// with dots and no leading 0 in the 10MHz's, and PC style,
// which is just the plain Hz display.
// The string is placed into global 'freq_str'.
// freq_str[0..11] = LCD formatted, freq_str[12..23] = PC formatted
// Returns pointer to the actual start of the string.
//
char* DDS_Tuningword2FreqStr(long long tuningword, char LCDformat)
{
   unsigned char tmp;
   register unsigned char c;
   unsigned long freqhz;
   int i, j;
   
   // f_dds = (ref*multipl) * tuningword / 2^48
   //          200 MHz * tuningword / 2^48 = tw / (2^48/200E6)
   //       = tw / 1407374.884 [Hz]
   freqhz = (long) ( ((long long)tuningword / (long long)DDS_1HZ_STEP) );

   i=0;  // starting idx for LCD format
   j=12; // starting idx for PC format
   
   //
   // LCD format : freq_str[0..11, or 0..10]
   //   format as "12.345.678"(MHz) when freq>=10MHz 
   //   or "1.234.567"(Mhz) when freq<10MHz
   //
   // PC format :  freq_str[12..23]
   //   format as "12345678"(Hz) always
   //

   tmp=(freqhz/10000000); 
   freqhz = freqhz%10000000; //  10*1E6
   c='0'+tmp;
   freq_str[i++]=c; 
   freq_str[j++]=c;
   tmp=(freqhz/1000000); 
   freqhz = freqhz%1000000;   //   1*1E6
   c='0'+tmp;
   freq_str[i++]=c; 
   freq_str[j++]=c;
   freq_str[i++]='.';                               //     '.'
   tmp=(freqhz/100000);  
   freqhz = freqhz%100000;    // 100*1E3
   c='0'+tmp;
   freq_str[i++]=c;
    freq_str[j++]=c;
   tmp=(freqhz/10000); 
   freqhz = freqhz%10000;     //  10*1E3
   c='0'+tmp;
   freq_str[i++]=c;
    freq_str[j++]=c;
   tmp=(freqhz/1000);  
   freqhz = freqhz%1000;      //   1*1E3
   c='0'+tmp;
   freq_str[i++]=c;
    freq_str[j++]=c;
   freq_str[i++]='.';                               //     '.'
   tmp=(freqhz/100);     
   freqhz = freqhz%100;       //     100
   c='0'+tmp;
   freq_str[i++]=c;
    freq_str[j++]=c;
   tmp=(freqhz/10);    
     freqhz = freqhz%10;        //      10
   c='0'+tmp;
   freq_str[i++]=c; 
   freq_str[j++]=c;
   c='0'+freqhz;
   freq_str[i++]=c;
    freq_str[j++]=c;                //       1
   
   freq_str[i++]='\0'; 
   //freq_str[j++]='\0';

   // Return pointer to LCD formatting 
   if(1==LCDformat) {
      // return without a leading zero
      if('0'==freq_str[0]) { return (char*)&freq_str[1]; }
      else { return (char*)&freq_str[0]; }
   }
   // PC formatting, simply return pointer to second part of string
   return (char*)&freq_str[12];
}


//-------------------------------------------------------------------
// DDS_Smeter ( )
//
// Display s-meter on the second LCD line.
//
void DDS_Smeter(unsigned char s) 
{
   if(s<=9) 
   {
      LCD_moveTo(55);
      LCD_writeChar('S');
      LCD_writeChar(s+'0');
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -