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

📄 timer.c

📁 基于USB接口的GPS驱动程序.gps后段接受以及输出,及usp驱动读写
💻 C
字号:
/******************************************************************
 Module description:
   This module is used to set the timer for GP2021 data collection
   also the timer interrupt service, to get GP2021 accum data and measurement every TIC
   also send command from PC to control GP2021

 Author : Yu Lu
          luyu1974@gmail.com

*****************************************************************/

#include "timer.h"
#include "gbl_macro.h"

extern void puthex_char(char);
//extern void put_char(char);
extern void get_gp2021_6ch_accum(unsigned int addr);
extern void get_gp2021_6ch_cntl(unsigned int addr);
extern void get_gp2021_epochchk(unsigned int addr);
extern void write_gps_noint(char add, char lo, char hi);
extern void read_gps(char add, unsigned int addr);
extern void process_host_data(void);

extern unsigned char xdata gp2021_reg_buf[];
extern unsigned char data  status, event;



void init_timer(void)
{

 frm_count = 0;
 frm_count1 = 0;
 tic_flag = 0; 

 buf_idx = (frm_count1 & 0x01)*ONE_FRM_SIZE;  // buf_idx = 0 at very beginning
 usb_snd_idx=((frm_count1+1) & 0x01)*ONE_FRM_SIZE; // usb_snd_idx = 1 at very beginning

 TMOD &= 0XF1;
 TMOD |= 0X01;
 TR0 = 0;
 TH0 = RELOADVALH;
 TL0 = RELOADVALL;
 TR0 = 1;
}

void timer0(void) interrupt 1
{
 unsigned int xram_pt;
 unsigned char accum_stsb_hi;

 EA  = 0;
 TR0 = 0;
 TH0 = RELOADVALH;
 TL0 = RELOADVALL;
 TR0 = 1;

 xram_pt = frm_count*ONE_CHN_SIZE;
 
 write_gps_noint(0x80,0,0);    // latch status regs 
 get_gp2021_6ch_accum((unsigned int)(gp2021_reg_buf + buf_idx + xram_pt));

 accum_stsb_hi = gp2021_reg_buf[buf_idx + xram_pt + 7]; // get high byte of ACCUM_STATUS_B

 if(accum_stsb_hi & 0x20)  // TIC is set
 {
  get_gp2021_6ch_cntl((unsigned int)(gp2021_reg_buf + buf_idx + 224));
  tic_flag = 1;   // prevent following epoch_check access to damage measurement
 }

 if( !tic_flag )
  get_gp2021_epochchk( (unsigned int)(gp2021_reg_buf + buf_idx + 224 + frm_count*12) );

 gp2021_reg_buf[320 + buf_idx + frm_count] = frm_count1;   // time stamp for future check 

 frm_count++;
 
 if(frm_count >= 4)
 {

  if( HOST_SEND_DATA_FLAG )  // we get some data from host
  {
    process_host_data();
    CLR_HOST_SEND_DATA_FLAG;   // clean this flag
  }

  frm_count = 0;
  tic_flag = 0;
  frm_count1++;
  // if frm_count1 is odd, we will write all accum data to gp2021_reg_buf[ONE_FRM_SIZE+]
  // else  , we will write all accum data to gp2021_reg_buf[0+]
  buf_idx = (frm_count1 & 0x01)*ONE_FRM_SIZE; 
  usb_snd_idx=((frm_count1+1) & 0x01)*ONE_FRM_SIZE; 
  status = status | 0x80; // it's time to send all 4ms 's data to host , so set the flag;
 }
 EA = 1;
}

⌨️ 快捷键说明

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