KD7LMO - V1.03 HF-APRS Source Code//
// Name: psk31beacon.c
//
//
// Revision History:
//
// M. Gray 21 Dec 2003 V1.00 Initial release.
//
// M. Gray 6 Jan 2004 V1.01 Pre-flight release that includes all functions.
//
// M. Gray 17 Jun 2004 V1.02 ANSR-19 test flight
//
// M. Gray 26 Jun 2004 V1.03 Changed 1200 bps, A-FSK APRS status packet to include web link,
// removed 'Balloon' from 3rd line of PSK-31 text,
// modified I/O to support more accurate 1-PPS for TCXO correction, and
// added list of 3 frequencies and amplitudes for PSK-31 band tuning.
//
//
// COPYRIGHT (c) 2001-2004 Michael Gray, KD7LMO
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Hardware specific configuration.
#include <18f252.h>
#device ADC=10
// NOTE: Even though we are using an external clock, we set the HS oscillator mode to
// make the PIC 18F252 work with our external clock which is a clipped 1V P-P sine wave.
#fuses HS,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP
// Standard includes.
#include <stdlib.h>
#include <string.h>
// These compiler directives set the clock, serial port, and I/O configuration.
#use delay(clock=19200000)
#use rs232(baud=9600, xmit=PIN_B6, stream=PC_HOST)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
// Map I/O names to the hardware pins.
#define IO_GPS_PWR PIN_B3
#define IO_LED PIN_B4
#define IO_PA PIN_B2
#define IO_UPDATE PIN_A5
#define IO_CS PIN_B0
#define IO_PS1 PIN_C0
#define IO_PS0 PIN_A3
#define IO_OSK PIN_C2
// We define types that are used for all variables. These are declared
// because each processor has a different sizes for int and long.
// The PIC compiler defines int8_t, int16_t, and int32_t.
typedef int8 int8_t;
typedef unsigned int8 uint8_t;
typedef int16 int16_t;
typedef unsigned int16 uint16_t;
typedef int32 int32_t;
typedef unsigned int32 uint32_t;
// Public methods, constants, and data structures for each class.
// Constants for the DDS mode in method ddsSetMode
enum DDS_MODE
{
DDS_MODE_APRS,
DDS_MODE_PSK31,
DDS_MODE_HF_APRS
};
inline void ddsAFSK (boolean state);
void ddsInit();
void ddsPhase (boolean phase);
void ddsSetAmplitude (uint16_t amplitude);
inline void ddsPTT (boolean state);
void ddsSetFreq (uint32_t freq);
void ddsSetMode (DDS_MODE mode);
char *gpsGetBuffer();
void gpsInit();
int16_t gpsParseAltitude();
uint16_t gpsParseDOP();
uint8_t gpsParseHours();
uint8_t gpsParseIsGGAValid();
uint8_t gpsParseIsRMCValid();
uint8_t gpsParseMinutes();
uint8_t gpsParseSatCount();
uint8_t gpsParseSeconds();
boolean gpsSetup();
void gpsUpdate();
boolean gpsWaitMessage(uint8_t messageType);
boolean psk31CreateDataPacket();
void psk31Init();
void psk31TimeUpdate();
void psk31TxPacket(uint8_t minutes);
void psk31TxByte (uint8_t value);
void psk31TxNull ();
void psk31TxString (char *string, uint8_t length);
boolean serialHasData();
void serialInit();
uint8_t serialRead();
void serialUpdate();
uint16_t sysCRC16(uint8_t *buffer, uint8_t length, uint16_t crc);
inline void sysPAOutput (boolean state);
// Constants for time duty cycle in method timeSetDutyCycle
#define TIME_DUTYCYCLE_10 1
#define TIME_DUTYCYCLE_70 7
// Constants for the time base mode in method timeSetMode
enum TIME_MODE
{
TIME_MODE_APRS,
TIME_MODE_PSK31,
TIME_MODE_HF_APRS
};
uint8_t timeGetTicks();
void timeInit();
void timeSetDutyCycle (uint8_t dutyCycle);
void timeSetMode (TIME_MODE mode);
void timeUpdate();
void tncInit();
boolean tncIsFree();
void tncTimeUpdate();
void tncTxByte (uint8_t value);
void tncTxPacket();
// ****************************************************************************
// DDS control
//
// AD9954 Registers
#define DDS_AD9954_CFR0 0x00
#define DDS_AD9954_CFR1 0x01
#define DDS_AD9954_ASF 0x02
#define DDS_AD9954_ARR 0x03
#define DDS_AD9954_FTW0 0x04
#define DDS_AD9954_POW0 0x04
#define DDS_AD9954_FTW1 0x06
#define DDS_AD9954_NLSCW 0x07
#define DDS_AD9954_PLSCW 0x08
// Frequency Word List - 3.5KHz FM frequency deviation at 50.62Mhz
const uint32_t f[256] =
{
566175115
,566176076
,566177036
,566177995
,566178953
,566179907
,566180859
,566181808
,566182753
,566183693
,566184627
,566185556
,566186479
,566187395
,566188304
,566189204
,566190096
,566190979
,566191853
,566192716
,566193569
,566194411
,566195241
,566196059
,566196864
,566197657
,566198435
,566199200
,566199950
,566200685
,566201405
,566202109
,566202796
,566203467
,566204121
,566204758
,566205376
,566205977
,566206558
,566207121
,566207665
,566208189
,566208693
,566209177
,566209640
,566210082
,566210504
,566210904
,566211282
,566211639
,566211974
,566212286
,566212577
,566212844
,566213089
,566213311
,566213510
,566213686
,566213839
,566213968
,566214074
,566214156
,566214215
,566214250
,566214262
,566214250
,566214215
,566214156
,566214074
,566213968
,566213839
,566213686
,566213510
,566213311
,566213089
,566212844
,566212577
,566212286
,566211974
,566211639
,566211282
,566210904
,566210504
,566210082
,566209640
,566209177
,566208693
,566208189
,566207665
,566207121
,566206558
,566205977
,566205376
,566204758
,566204121
,566203467
,566202796
,566202109
,566201405
,566200685
,566199950
,566199200
,566198435
,566197657
,566196864
,566196059
,566195241
,566194411
,566193569
,566192716
,566191853
,566190979
,566190096
,566189204
,566188304
,566187395
,566186479
,566185556
,566184627
,566183693
,566182753
,566181808
,566180859
,566179907
,566178953
,566177995
,566177036
,566176076
,566175115
,566174155
,566173195
,566172236
,566171278
,566170323
,566169371
,566168423
,566167478
,566166538
,566165604
,566164674
,566163752
,566162836
,566161927
,566161027
,566160135
,566159252
,566158378
,566157515
,566156662
,566155820
,566154990
,566154172
,566153367
,566152574
,566151796
,566151031
,566150281
,566149546
,566148826
,566148122
,566147434
,566146763
,566146110
,566145473
,566144855
,566144254
,566143672
,566143110
,566142566
,566142042
,566141538
,566141054
,566140591
,566140149
,566139727
,566139327
,566138948
,566138592
,566138257
,566137944
,566137654
,566137387
,566137142
,566136920
,566136721
,566136545
,566136392
,566136263
,566136157
,566136075
,566136016
,566135980
,566135969
,566135980
,566136016
,566136075
,566136157
,566136263
,566136392
,566136545
,566136721
,566136920
,566137142
,566137387
,566137654
,566137944
,566138257
,566138592
,566138948
,566139327
,566139727
,566140149
,566140591
,566141054
,566141538
,566142042
,566142566
,566143110
,566143672
,566144254
,566144855
,566145473
,566146110
,566146763
,566147434
,566148122
,566148826
,566149546
,566150281
,566151031
,566151796
,566152574
,566153367
,566154172
,566154990
,566155820
,566156662
,566157515
,566158378
,566159252
,566160135
,566161027
,566161927
,566162836
,566163752
,5661