GPS时钟 STC 89C52RC +GPS 模块

2013-09-16 16:00:32  阅读 4565 次 评论 0 条

这个是用一个淘来的GPS模块做的GPS 时钟, 这样这个时钟就不用校准时间了 只要有GPS信号 就可以准确的显示时间了

因不需要定位 只要在靠近窗户的房间里就可以准确的获得时间信号的

以下为源代码

#include <reg52.h>
#include <intrins.h>
#define uchar  unsigned char
#define uint   unsigned int
uchar code LEDTab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; //数码管段码表0--9码
//sbit MIAO =P2^7; //秒点 ,数码管第二位小数点,可以自己随意定义.
sbit K0=P2^0; 
sbit K1=P2^1; 
sbit K2=P2^2;
sbit K3=P2^3; 
sbit K4=P2^4; 
sbit K5=P2^5; 
sbit K6=P2^6;
sbit K7=P2^7; 

char code TIME_AREA= 8;           //时区
unsigned char time[6];            //时间
//串口中断需要的变量
unsigned char seg_count;            //逗号计数器
unsigned char byte_count;            //位数计数器
unsigned char cmd_number;            //命令类型
unsigned char mode;                        //0:结束模式,1:命令模式,2:数据模式
unsigned char buf_full;                  //1:整句接收完成,相应数据有效。0:缓存数据无效。
unsigned char cmd[5];                  //命令类型存储数组
//显示需要的变量
unsigned int dsp_count;            //刷新次数计数器
unsigned char time_count;

void delay1ms(unsigned int i)  
{
 while(i--)
 {
    unsigned char b;
    for(b=1;b>0;b--)
 {}
 }
}

 

void main()
{
unsigned char s,Tim0,Tim1;
TMOD = 0x20;
 TL1 = 0xFD;
 TH1 = 0xFD;          //波特率为:9600
 ET1 = 0;             //T1用作波特率发生器,禁止T1中断
 TR1 = 1;             //启动定时器T1
 SCON = 0x70;         //方式1,SM2位为1
 PCON = 0;            //波特率无倍增
 EA = 1;
 ES = 1;
 s=10;
while(1)
 {
  if(((time[1]-0x30)+(time[0]-0x30)*10)<16)
  {
    Tim0=((time[1]-0x30)+8)/10+(time[0]-0x30);
    Tim1=((time[1]-0x30)+8) %10;
   delay1ms(1);
  }
  else if(((time[1]-0x30)+(time[0]-0x30)*10)>15)
   {
   Tim0=0;
   Tim1=((time[1]-0x30)+(time[0]-0x30)*10)-16;
   delay1ms(1);
   }
  P2=0xff;
  K0=0;
  P1= LEDTab[Tim0];
  delay1ms(s);
  P2=0xff;
  K1=0;
  P1= LEDTab[Tim1];
  delay1ms(s);
  P2=0xff;
  K2=0;
  P1= 0xbf;
  delay1ms(s);
  P2=0xff;
  K3=0;
  P1= LEDTab[time[2]-32-16];
  delay1ms(s);
  P2=0xff;
  K4=0;
  P1= LEDTab[time[3]-32-16];
  delay1ms(s);
  P2=0xff;
  K5=0;
  P1= 0xbf;
  delay1ms(s);
  P2=0xff;
  K6=0;
  P1= LEDTab[time[4]-32-16];
  delay1ms(s);
  P2=0xff;
  K7=0;
  P1= LEDTab[time[5]-32-16];
  delay1ms(s);
  P2=0xff;
}
}

 

//串口接收中断
void uart(void) interrupt 4
{
     unsigned char tmp;
  //disp_12232_char(0,0,'$');
     if(RI){
           tmp=SBUF;
           switch(tmp)
     {
                 case '$':
                       cmd_number=0;            //命令类型清空
                       mode=1;                  //接收命令模式
                       byte_count=0;            //接收位数清空
                       break;
                 case ',':
                       seg_count++;            //逗号计数加1
                       byte_count=0;
                       break;
                 case '*':
                       mode=0;
        buf_full=1;
                       break;
                 default:
                       if(mode==1){
                             //命令种类判断
                             cmd[byte_count]=tmp;                  //接收字符放入类型缓存
                             if(byte_count>=4){                        //如果类型数据接收完毕,判断类型
                                   if(cmd[0]=='G'){
                                         if(cmd[1]=='P'){
                                               if(cmd[2]=='R'){
                                                   if(cmd[3]=='M'){
                                                          if(cmd[4]=='C'){
                                                                 cmd_number=1;
                                                                 mode=2;
                                                                 seg_count=0;
                                                                 byte_count=0;
                                                                }
                                                                   }
                                                             }
                                                       }
                                                 }
                                             }
                                   }
                          else if((mode==2)&cmd_number){

                                         switch(seg_count){
               case 1:
                                                     if(byte_count<6)                        //时间处理
                                                           time[byte_count]=tmp;     
                                                     break;
                                                               }
                                     
                                     }
                      
                       byte_count++;            //接收数位加1
                       break;
     }
           }
     RI=0;
 
}

本文地址:http://financialos.cn/?id=113
免责声明:本文为原创文章,版权归 jinesc 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?