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

📄 gps source code.txt

📁 用单片机控制GPS模块C51源代码。。希望对大家了解单片机控制GPS有帮助。
💻 TXT
📖 第 1 页 / 共 5 页
字号:
,566220034
,566219203
,566218345
,566217462
,566216552
,566215618
,566214660
,566213677
,566212672
,566211644
,566210593
,566209522
,566208429
,566207317
,566206185
,566205035
,566203866
,566202680
,566201478
,566200260
,566199026
,566197778
,566196517
,566195242
,566193956
,566192658
,566191349
,566190031
,566188704
,566187368
,566186026
,566184676
,566183321
,566181961
,566180597
,566179229
,566177860
,566176488
,566175115
,566173743
,566172371
,566171001
,566169634
,566168270
,566166910
,566165555
,566164205
,566162862
,566161527
,566160200
,566158882
,566157573
,566156275
,566154989
,566153714
,566152453
,566151205
,566149971
,566148753
,566147551
,566146365
,566145196
,566144046
,566142914
,566141802
,566140709
,566139638
,566138587
,566137559
,566136554
,566135571
,566134613
,566133678
,566132769
,566131886
,566131028
,566130197
,566129393
,566128616
,566127868
,566127148
,566126457
,566125795
,566125163
,566124561
,566123989
,566123448
,566122939
,566122460
,566122014
,566121599
,566121217
,566120867
,566120550
,566120266
,566120015
,566119797
,566119612
,566119461
,566119343
,566119259
,566119208
,566119191
,566119208
,566119259
,566119343
,566119461
,566119612
,566119797
,566120015
,566120266
,566120550
,566120867
,566121217
,566121599
,566122014
,566122460
,566122939
,566123448
,566123989
,566124561
,566125163
,566125795
,566126457
,566127148
,566127868
,566128616
,566129393
,566130197
,566131028
,566131886
,566132769
,566133678
,566134613
,566135571
,566136554
,566137559
,566138587
,566139638
,566140709
,566141802
,566142914
,566144046
,566145196
,566146365
,566147551
,566148753
,566149971
,566151205
,566152453
,566153714
,566154989
,566156275
,566157573
,566158882
,566160200
,566161527
,566162862
,566164205
,566165555
,566166910
,566168270
,566169634
,566171001
,566172371
,566173743
};

/**
 *   Select the desired RAM profile to generate a 1200 or 2200Hz FM tone
 *
 *   @param state true for 2200Hz tone; false for 1200Hz tone
 */
inline void ddsAFSK (boolean state)
{
    if (state)
        output_high (IO_PS0);
    else
        output_low (IO_PS0);
}

/**
 *   Initialize the DDS regsiters and RAM.
 */
void ddsInit()
{
    uint16_t i;

    // Setup the SPI port for the DDS interface.    
    setup_spi( SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4 | SPI_XMIT_L_TO_H );    

    // Turn off the output.
    output_low (IO_OSK);

    // CFR1 (Control Function Register No. 1)
    output_low (IO_CS);
    spi_write (0x00);

    spi_write (0x83);  // RAM Enable, OSK Enable, Auto OSK keying
    spi_write (0x00);
    spi_write (0x02);  // SDIO input only
    spi_write (0x40);  // Power down comparator circuit
    output_high (IO_CS);

    // RSCW0 (RAM Control Segment Word No. 0)
    output_low (IO_CS);
    spi_write (0x07);

    spi_write (0x38);   // Ramp rate LSB - 1200 Hz
    spi_write (0x01);   // Ramp rate MSB
    spi_write (0xff);   // RAM segment 0 address range 0x000 to 0x0ff
    spi_write (0x00);
    spi_write (0x80);   // Circular buffer mode
    output_high (IO_CS);

    // RSCW1 (RAM Control Segment Word No. 1)
    output_low (IO_CS);
    spi_write (0x08);

    spi_write (0xaa);   // Ramp rate LSB - 2200 Hz
    spi_write (0x00);   // Ramp rate MSB
    spi_write (0xff);   // RAM segment 1 address range 0x100 to 0x1ff
    spi_write (0x01);
    spi_write (0x84);   // Circular buffer mode
    output_high (IO_CS);

    // Strobe the DDS so the RAM controller knows where to write the RAM data.
    output_high (IO_UPDATE);
    output_low (IO_UPDATE);
    
    // Select RAM profile 0.
    output_low (IO_PS0);
    output_low (IO_PS1);

    // Write 256 bytes into RAM locations 0x000 to 0x0ff
    output_low (IO_CS);
    spi_write (0x0b);

    for (i = 0; i < 256; ++i) {
        spi_write ((f[i] >> 24) & 0xff);
        spi_write ((f[i] >> 16) & 0xff);
        spi_write ((f[i] >> 8) & 0xff);
        spi_write (f[i] & 0xff);
    }
    
    output_high (IO_CS);

    // Select RAM profile 1.
    output_high (IO_PS0);

    // Write 256 bytes into RAM location 0x100 to 0x1ff
    output_low (IO_CS);
    spi_write (0x0b);

    for (i = 0; i < 256; ++i) {
        spi_write ((f1[i] >> 24) & 0xff);
        spi_write ((f1[i] >> 16) & 0xff);
        spi_write ((f1[i] >> 8) & 0xff);
        spi_write (f1[i] & 0xff);
    }

    output_high (IO_CS);

    // Select RAM profile 0.
    output_low (IO_PS0);

    // ASF (Amplitude Scale Factor) to full scale (0x3fff).
    ddsSetAmplitude (0x3fff);

    // ARR (Amplitude Ramp Rate) to 15mS for OSK
    output_low (IO_CS);
    spi_write (0x03);

    spi_write (0xff);
    output_high (IO_CS);

    // CFR2 (Control Function Register No. 2)
    output_low (IO_CS);
    spi_write (0x01);

    spi_write (0x00);     // Unused register bits
    spi_write (0x00);
    spi_write (0xa4);     // 20x reference clock multipler, high VCO range, nominal charge pump current
    output_high (IO_CS);

    // Set the frequency tuning word. 3.0 MHz
    ddsSetFreq (0x2555555);
    
    // CFR1 (Control Function Register No. 1)
    output_low (IO_CS);
    spi_write (0x00);

    spi_write (0x03);  // Disable RAM Enable, OSK Enable, Auto OSK keying  was 0x83
    spi_write (0x00);
    spi_write (0x02);  // SDIO input only
    spi_write (0x40);  // Power down comparator circuit
    output_high (IO_CS);

    // Strobe the part so we apply the updates.
    output_high (IO_UPDATE);
    output_low (IO_UPDATE);
}


void ddsSetAmplitude (uint16_t amplitude)
{
    output_low (IO_CS);
    spi_write (0x02);

    spi_write ((amplitude >> 8) & 0xff);
    spi_write (amplitude & 0xff);
    output_high (IO_CS);

    // Strobe the part so we apply the updates.
    output_high (IO_UPDATE);
    output_low (IO_UPDATE);
}

/**
 *   Set the output phase.
 *
 *   @param phase true for 180 degree phase shift; false for 0 degree phase shift
*/
void ddsPhase (boolean phase)
{
    // Set the POW0 (Phase Offset Word 0) to 0 or 180 degrees.
    output_low (IO_CS);
    spi_write (0x05);   

    if (phase) {
        spi_write (0x20);
        spi_write (0x00);
    } else {
        spi_write (0x00);
        spi_write (0x00);
    }

    output_high (IO_CS);

    // Strobe the DDS to write the phase change.
    output_high (IO_UPDATE);
    output_low (IO_UPDATE);
}

/**
 *    Turn on the DDS output.
 *
 *    @param state true to activate; otherwise false
 */
inline void ddsPTT (boolean state)
{
    if (state)
        output_high (IO_OSK);
    else
        output_low (IO_OSK);
}

/**
 *  Set DDS frequency tuning word.  The output frequency is equal to RefClock * (ftw / 2 ^ 32).
 *
 *  @param ftw Frequency Tuning Word
 */
void ddsSetFreq (uint32_t ftw)
{
    // Set FTW0 (Frequency Tuning Word 0)
    output_low (IO_CS);
    spi_write (DDS_AD9954_FTW0);

    spi_write ((ftw >> 24) & 0xff);
    spi_write ((ftw >> 16) & 0xff);
    spi_write ((ftw >> 8) & 0xff);
    spi_write (ftw & 0xff);

    output_high (IO_CS);
    
    // Strobe the DDS to set the frequency.
    output_high (IO_UPDATE);
    output_low (IO_UPDATE);     
}

/**
 *  Set DDS frequency tuning word.  The output frequency is equal to RefClock * (ftw / 2 ^ 32).
 *
 *  @param ftw Frequency Tuning Word
 */
void ddsSetFSKFreq (uint32_t ftw0, uint32_t ftw1)
{
    // Set FTW0 (Frequency Tuning Word 0)
    output_low (IO_CS);
    spi_write (DDS_AD9954_FTW0);

    spi_write ((ftw0 >> 24) & 0xff);
    spi_write ((ftw0 >> 16) & 0xff);
    spi_write ((ftw0 >> 8) & 0xff);
    spi_write (ftw0 & 0xff);

    output_high (IO_CS);
    
    // Set FTW0 (Frequency Tuning Word 1)
    output_low (IO_CS);
    spi_write (DDS_AD9954_FTW1);

    spi_write ((ftw1 >> 24) & 0xff);
    spi_write ((ftw1 >> 16) & 0xff);
    spi_write ((ftw1 >> 8) & 0xff);
    spi_write (ftw1 & 0xff);

    output_high (IO_CS);
    
    // Strobe the DDS to set the frequency.
    output_high (IO_UPDATE);
    output_low (IO_UPDATE);     
}

/** 
 *   Set the DDS to run in A-FSK, FSK, or PSK31 mode
 *
 *   @param mode <i>DDS_MODE_APRS</i>, <i>DDS_MODE_PSK31</i>, or <i>DDS_MODE_HF_APRS</i> constant
 */
void ddsSetMode (DDS_MODE mode)
{
    switch (mode) {
        case DDS_MODE_APRS:
            // CFR0 (Control Function Register No. 0)
            output_low (IO_CS);
            spi_write (DDS_AD9954_CFR0);

            spi_write (0x83);  // Set RAM Enable, OSK Enable, Auto OSK keying
            spi_write (0x00);
            spi_write (0x02);  // SDIO input only
            spi_write (0x40);  // Power down comparator circuit
            output_high (IO_CS);
            break;
            
        case DDS_MODE_PSK31:
            // CFR0 (Control Function Register No. 0)
            output_low (IO_CS);
            spi_write (DDS_AD9954_CFR0);

            spi_write (0x03);  // Clear RAM Enable, OSK Enable, Auto OSK keying
            spi_write (0x00);
            spi_write (0x02);  // SDIO input only
            spi_write (0x40);  // Power down comparator circuit
            output_high (IO_CS);
            break;

        case DDS_MODE_HF_APRS:
            // CFR0 (Control Function Register No. 0)
            output_low (IO_CS);
            spi_write (DDS_AD9954_CFR0);

            spi_write (0x03);  // Clear RAM Enable, OSK Enable, Auto OSK keying
            spi_write (0x20);  // Enable linear sweep
            spi_write (0x02);  // SDIO input only
            spi_write (0x40);  // Power down comparator circuit
            output_high (IO_CS);

            // NOTE: The sweep rate requires 1/4 of a bit time to transition.
            // 200Hz delta = 2236 counts  (200Hz / 384MHz) * 2 ^ 32
            // SYNC_CLK = 96MHz  1/96MHz * 2236 * 36 = 838uS

            // NLSCW (Negative Linear Sweep Control Word)
            output_low (IO_CS);
            spi_write (DDS_AD9954_NLSCW);

            spi_write (36);    // Falling sweep ramp rate word
            spi_write (0x00);  // Delta frequency tuning word
            spi_write (0x00);
            spi_write (0x00);
            spi_write (0x01); 
            output_high (IO_CS);

            // PLSCW (Positive Linear Sweep Control Word)
            output_low (IO_CS);
            spi_write (DDS_AD9954_PLSCW);

            spi_write (36);    // Falling sweep ramp rate word
            spi_write (0x00);  // Delta frequency tuning word
            spi_write (0x00);
            spi_write (0x00);
            spi_write (0x01); 
            output_high (IO_CS);
            break;
            
    } // END switch
    
    // Strobe the DDS to change the mode.
    output_high (IO_UPDATE);
    output_low (IO_UPDATE);      
}

// ****************************************************************************
//   GPS
//
#define GPS_WAIT_MSG 0
#define GPS_GGA_MSG 1
#define GPS_RMC_MsG 2

// The maximum length of a single NMEA GPS message
#define GPS_BUFFER_SIZE 80

uint8_t gpsState, gpsIndex;
uint8_t gpsBuffer[GPS_BUFFER_SIZE]; 

static char GPS_GGA_TEXT[] = "$GPGGA";
static char GPS_RMC_TEXT[] = "$GPRMC";

/**
 *   Get a pointer to the GPS buffer that contains the NMEA message.
 *
 *   @return pointer to NULL terminated string
 */
char *gpsGetBuffer()
{
    return gpsBuffer;
}

/** 
 *    Initialize the GPS subsystem.
 */
void gpsInit()
{
    gpsState = GPS_WAIT_MSG;
    gpsIndex = 0;

⌨️ 快捷键说明

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