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

📄 gpscode.c

📁 GPS read and write,retrieve time,loction from gps
💻 C
📖 第 1 页 / 共 2 页
字号:
// This is the interface program for the LX200GPS Sensor Module (LSM)
// defined in available specifications document. This program runs on
// on the 83c4051 atmel processor family. The crystal used is 24MHz.
//

#include "reg_AT89C4051.h"

#define VERSION                   0x01
#define TIMER_INTERVAL            ( unsigned ) 0xFF00    
#define HEADING_INTERVAL          0                    

//**********************************************
//*
//*     Define flag true/false values and port
//*   bit on/off values
//*
//**********************************************

#define TRUE                      1
#define FALSE                     0
#define ON                        1
#define OFF                       0
#define LOW_ACTIVE_ON             0
#define LOW_ACTIVE_OFF            1
#define HIGH_ACTIVE_ON            1
#define HIGH_ACTIVE_OFF           0

#define PC_GETVERSION				 0x00
#define PC_ON_GPRMCLong    		 0x01
#define PC_ON_GPGGA               0x02
#define PC_OFF_GPS                0x03
#define PC_DUMP_GPS               0x04
#define PC_RESET_HI               0x05
#define PC_RESET_LO               0x06
#define PC_ON_GPRMCShort          0x07
#define PC_COLDSTART					 0x08

#define Meade_Address             0x08

//**********************************************
//*
//*     Define location and names of bit flag
//*     variables
//*
//**********************************************

union mixvar
   {
   unsigned short w;
   struct
      {
      unsigned char b1;    // msb
      unsigned char b2;    // lsb
      }h;
   };

union mixlong
   {
   unsigned long w;
   struct
      {
      unsigned char b1;    // msb
      unsigned char b2;
      unsigned char b3;
      unsigned char b4;    // lsb
      }h;
   };

bdata unsigned char USER_FLAGS;
sbit Datain                     = USER_FLAGS ^ 0;
sbit senddata                   = USER_FLAGS ^ 1;
sbit bithold                    = USER_FLAGS ^ 2;
sbit lastedge                   = USER_FLAGS ^ 3;
sbit instring                   = USER_FLAGS ^ 4;
sbit GPSoutdata                 = USER_FLAGS ^ 5;
sbit lookGPGGA                  = USER_FLAGS ^ 6;
sbit lookGPRMCLong              = USER_FLAGS ^ 7;

bdata unsigned char U_F1;
sbit lookGPRMCShort             = U_F1 ^ 0;

bdata unsigned char auxaddress;
sbit auxaddresslow              = auxaddress ^ 0;      

bdata unsigned char bytecnt;
sbit bytecntlow                 = bytecnt ^ 0;      

unsigned char GPSdata[33];
unsigned char incnt,savecnt,commandpos,outpos,inserialcnt;
unsigned char header0,header1,header2,header3,header4,nextout;
unsigned short outcnt;
union mixvar timecnt;
union mixlong shiftout;

//**********************************************
//*
//*     Define constants used to specify the
//*     various project-specific I/O port bit
//*     assignments
//*
//**********************************************

sbit GPS_RESET                  = P1 ^ 0; 
sbit testbit1                   = P1 ^ 2;
sbit testbit2                   = P1 ^ 3;
sbit testbit3                   = P1 ^ 4;
sbit testbit4                   = P1 ^ 5; 
sbit BIT_DTAPIC                 = P1 ^ 6;  
sbit BIT_CLKP                   = P3 ^ 2;  
sbit BIT_CLKPNT                 = P3 ^ 3;  
sbit On_Bit                     = P3 ^ 7;  
   
//**********************************************
//*
//*     Define function prototypes
//*
//**********************************************

void main( void );                  
void ClockActiveHandler( void );     
void ClockInactiveHandler( void );     
void TimerInt( void );
void SerialInt( void );
      
//**********************************************
//*
//*     ********
//*     * main *
//*     ********
//*
//**********************************************

void main( void ) using 0
{
USER_FLAGS=0;
U_F1=0;
nextout=0;
header4=0;
P1=0xfe;
P3=0xff;
incnt=8;
commandpos=0;
PCON = 0;
TMOD = 0x22;            // timer 0 timer timer 1 timer
TCON = 0x05;            // both external int's are edge
senddata = FALSE;
lastedge=0;
outcnt=0;
IE = 0x97;             // enable both external int's ,timer0, & serial
SCON = 0x50;           // mode 1 serial
TH1=245;               // 4800 K w/SMOD = 0
TL1=245;
TH0=0;
TL0=0;
TR0 = 1;
TR1 = 1;

while (1)
   {
   if ((commandpos) || (incnt!=8))
      {
      //testbit3=1;
      if (outcnt >= 13020)
         {
         incnt=8;
         commandpos=0;
         lastedge=0;
         }
      }
//   else
//      testbit3=0;
   }
}

void ClockActiveHandler() interrupt 0  using 1  
{
//testbit1=1;
if ((!lastedge) && (!BIT_CLKP))
   {
   lastedge=1;
   Datain=1;
   bithold=BIT_DTAPIC;
   outcnt=0;
   switch (commandpos)
      {
      case 0 : bytecnt <<= 1;                // reading byte count
               bytecntlow = bithold;
               --incnt;
               if (!incnt)
                  {
                  commandpos=1;
                  incnt=8;
                  }
               break;
	   case 1 : auxaddress <<= 1;           // reading address
	            auxaddresslow = bithold;
	            --incnt;
   	         if (!incnt)
	               {
	               incnt=8;
	               if (auxaddress == Meade_Address)
	                  {
	                  commandpos=2;
   	               --bytecnt;
	                  }
	               else
	                  {
	                  --bytecnt;
	                  if (!bytecnt)
	                     commandpos=5;
   	               else
	                  	commandpos=4;
   	               }
	               }
	            break;
      case 2 : auxaddress <<= 1;           // reading command if correct address
               auxaddresslow = bithold;
               --incnt;
               if (!incnt)
                  {
                  senddata = TRUE;
                  //commandpos=3;
                  commandpos=12;
                  incnt=8;
                  switch ( auxaddress )           
      	            {
      	            case PC_COLDSTART:  shiftout.h.b1=0;
                                         incnt=8; 
                                         SBUF='@';
                                         nextout=4;
                                         break;
                     case PC_GETVERSION: shiftout.h.b1=1;
                                         shiftout.h.b2=VERSION;
                                         incnt=16;          
                                         break;
                     case PC_ON_GPRMCShort:   shiftout.h.b1=0;
                                         incnt=8; 
                                         On_Bit=0;
                                         lookGPRMCShort=1;         
                                         lookGPRMCLong=0;
                                         lookGPGGA=0;
                                         break;
                     case PC_ON_GPRMCLong:   shiftout.h.b1=0;
                                         incnt=8; 
                                         On_Bit=0;
                                         lookGPRMCShort=0;         
                                         lookGPRMCLong=1;
                                         lookGPGGA=0;
                                         break;
                     case PC_ON_GPGGA:   shiftout.h.b1=0;
                                         incnt=8; 
                                         On_Bit=0;
                                         lookGPGGA=1;
                                         lookGPRMCLong=0;         
                                         lookGPRMCShort=0;
                                         break;
                     case PC_OFF_GPS:    shiftout.h.b1=0;
                                         incnt=8; 
                                         On_Bit=1;         
                                         lookGPGGA=0;
                                         lookGPRMCShort=0;         
                                         lookGPRMCLong=0;
                                         break;
                     case PC_RESET_HI:   shiftout.h.b1=0;
                                         incnt=8; 
                                         GPS_RESET=1;
                                         break;
                     case PC_RESET_LO:   shiftout.h.b1=0;
                                         incnt=8; 
                                         GPS_RESET=0;
                                         break;
                     case PC_DUMP_GPS:   if (instring)
                                            {
                                            commandpos=12;
                                            incnt=8;
                                            shiftout.h.b1=0;
                                            header4=0;

⌨️ 快捷键说明

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