惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
博客园 - 司徒正美
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog

博客园 - 邵利超

ZigBee学习之37——osalInitTasks()分析 ZigBee2006协议栈介绍 点对点(单向)传输实验之LED灯指示 ZigBee四种绑定方式在TI Z-Stack中的应用【转载】 DSP串行FLASH(AT45DB642)的源代码 at45db642 程序代码 点对点通信实验小结 CC2430串口收发数据 CC2430串口测试实验(UART) 正则表达式集合 C#版万年历 在C#中调用视图 c#调用SqlServer中的存储过程 SQL Server 2005 BI综合案例系列课程 SQL2005 BI系列课程 微软工程师主讲的SqlServer2005视频教程 多线程C#2.0聊天软件 内含代码 C#网络编程概述 三 C#网络编程概述 二
gps 信号解析与显示
邵利超 · 2010-07-04 · via 博客园 - 邵利超

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •    
  •    
  • #include <AVR_PQ1A.H>       //包含自定义常量头文件    
  • #include <AVR interrupt.h>    
  •    
  • uchar buf[500];       
  • uint readCount=0;     
  • uint writeCount=0;    
  • uchar Time[6];        
  • uchar Date[6];        
  • uchar Status;         
  • uchar Latitude[9];    
  • uchar NSIndicator;    
  • uchar Longitude[10];  
  • uchar EWIndicator;    
  • uchar Speed[4];       
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • void Uart_init(uint baud)                                
  • {    
  •    baud=MCLK/16/baud-1;                     
  •    UCSRB=0x00;    
  •    UCSRA=0x00;                              
  •    UCSRC=(1<<URSEL)|(0<<UPM0)|(3<<UCSZ0); UBRRH="baud" UBRRL="baud;" 选择UCSRC,异步模式,禁止校验,1位停止位,8位数据位>>8;                            
  •    UCSRB=(1<<TXEN)|(1<<RXEN)|(1<<RXCIE); if(writeCount ++writeCount; 将接收到的数据存入全局数组 buf[writeCount]="UDR;" 关闭接收中断 UCSRB&="~BIT(RXCIE);" { ISR(USART_RXC_vect) ******************************************** 无 : 返回值 数: 参 异步串口接收 能: 功 Uart_RX 函数名称: ******************************************* } Uart_sendB(*sendpt++); 字符串未结束则继续发送 while(*sendpt) *sendpt) Uart_sentstr(uchar void sendpt--发送的数组指针 异步串口发送一个字符串 Uart_sentstr 清除发送完毕状态位 UCSRA|="1<<TXC;" 等待发送完毕 while(!(UCSRA&(1<<TXC))); 发送数据 UDR="sendB;" 等待发送缓冲区为空 while(!(UCSRA&(1<<UDRE))); sendB) Uart_sendB(uchar sendB--发送的字节数据 异步串口发送一个字节 Uart_sendB 配置TX为输出(很重要) DDRD|="0X02;" 全局中断开放 sei(); 接收、发送使能,接收中断使能> 499)   
  •     writeCount = 0;   
  •  UCSRB|=BIT(RXCIE);                       
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • uchar Read_byte(void)   
  • {   
  •     uchar temp;   
  •     while(readCount == writeCount)   
  •     {   
  •         Delayms(10);       
  •     }   
  •     temp = buf[readCount];   
  •     ++readCount;   
  •     if(readCount > 499)   
  •         readCount = 0;   
  •     return temp;       
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • void LCD1602_portini(void)   
  • {   
  •     LCDa_CTRL_DDR |= BIT(LCDa_RS)|BIT(LCDa_RW)|BIT(LCDa_E);  
  •     LCDa_DATA_DDR |= 0xFF;  
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • uchar LCD1602_readbyte(uchar DatCmd)   
  • {   
  •     uchar dByte;   
  •     if (DatCmd == iCmd)        
  •         LCDa_CLR_RS;   
  •     else   
  •         LCDa_SET_RS;   
  •            
  •     LCDa_SET_RW;               
  •     LCDa_SET_E;   
  •     LCDa_DATA_DDR=0x00;        
  •     dByte=LCDa_DI;             
  •     Delayms(1);                
  •     LCDa_CLR_E;    
  •     LCDa_DATA_DDR|=0xff;       
  •     return dByte;   
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •  
  •    
  • void LCD1602_sendbyte(uchar DatCmd, uchar dByte)   
  • {   
  •     if (DatCmd == iCmd)       
  •         LCDa_CLR_RS;   
  •     else   
  •         LCDa_SET_RS;          
  •            
  •     LCDa_CLR_RW;              
  •     LCDa_SET_E;   
  •     LCDa_DO = dByte;          
  •     Delayms(1);   
  •     LCDa_CLR_E;    
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • void LCD1602_sendstr(uchar *ptString)   
  • {   
  •     while((*ptString)!='\0')           
  •     {   
  •         LCD1602_sendbyte(iDat, *ptString++);   
  •     }   
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • void LCD1602_clear(void)   
  • {   
  •     LCD1602_sendbyte(iCmd,LCDa_CLS);  
  •     Delayms(40);  
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • uchar LCD1602_readBF(void)   
  • {        
  •     uchar busy;   
  •     busy=LCD1602_readbyte(iCmd);          
  •     if(busy&0x80)                         
  •         busy=1;   
  •     else                                  
  •         busy=0;   
  •     return busy;   
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •  
  •    
  • void LCD1602_gotoXY(uchar Row, uchar Col)   
  • {      
  •     switch (Row)            
  •     {   
  •         case 1:   
  •             LCD1602_sendbyte(iCmd, LCDa_L1 + Col); break;     
  •         case 2:   
  •             LCD1602_sendbyte(iCmd, LCDa_L2 + Col); break;     
  •         default:   
  •             break;   
  •                
  •     }   
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • void LCD1602_initial(void)   
  • {   
  •     Delayms(100);                 
  •     LCD1602_portini();            
  •        
  •     LCD1602_sendbyte(iCmd, LCDa_FUNCTION);    
  •     while(LCD1602_readBF());                  
  •     LCD1602_sendbyte(iCmd, LCDa_ON);          
  •     while(LCD1602_readBF());                  
  •     LCD1602_clear();                          
  •     while(LCD1602_readBF());                  
  •     LCD1602_sendbyte(iCmd, LCDa_ENTRY);       
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • void clear_gprmc(void)   
  • {   
  •     uchar i;   
  •     for(i=0; i<6; i++)   
  •     {   
  •         Time[i] = '0';   
  •         Date[i] = '0';   
  •     }   
  •     for(i=0; i<9; i++)   
  •     {   
  •         Latitude[i] = '0';   
  •     }   
  •     for(i=0; i<10; i++)   
  •     {   
  •         Longitude[i] = '0';   
  •     }   
  •     for(i=0; i<4; i++)   
  •     {   
  •         Speed[i] = '0';   
  •     }          
  •     Status = '0';        
  •     NSIndicator = '0';   
  •     EWIndicator = '0';   
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • void Parse_gprmc(void)   
  • {   
  •     uchar i;   
  •     uchar temp;   
  •     clear_gprmc();   
  •     Read_byte();   
  •     temp = Read_byte();   
  •     if(',' != temp)   
  •     {   
  •         Time[0] = temp;   
  •         for(i=0; i<5; i++)   
  •         {   
  •             Time[i+1] = Read_byte();   
  •         }   
  •         Read_byte();   
  •         Read_byte();   
  •         Read_byte();   
  •         Read_byte();   
  •     }   
  •     Status = Read_byte();   
  •     Read_byte();   
  •     temp = Read_byte();   
  •     if(',' != temp)   
  •     {   
  •         Latitude[0] = temp;   
  •         for(i=0; i<3; i++)   
  •         {   
  •             Latitude[i+1] = Read_byte();   
  •         }   
  •         Read_byte();   
  •         for(i=0; i<5; i++)   
  •         {   
  •             Latitude[4+i] = Read_byte();   
  •         }   
  •         Read_byte();   
  •     }   
  •     temp = Read_byte();   
  •     if(',' != temp)   
  •     {   
  •         NSIndicator = temp;   
  •         Read_byte();   
  •     }   
  •     temp = Read_byte();   
  •     if(',' != temp)   
  •     {   
  •         Longitude[0] = temp;   
  •         for(i=0; i<4; i++)   
  •         {   
  •             Longitude[i+1] = Read_byte();   
  •         }      
  •         Read_byte();   
  •         for(i=0; i<5; i++)   
  •         {   
  •             Longitude[5+i] = Read_byte();   
  •         }      
  •         Read_byte();   
  •     }   
  •     temp = Read_byte();   
  •     if(',' != temp)   
  •     {   
  •         EWIndicator = temp;   
  •         Read_byte();   
  •     }   
  •     temp = Read_byte();   
  •     if(',' != temp)   
  •     {   
  •         Speed[0] = temp;   
  •         Read_byte();   
  •         for(i=0; i<3; i++)   
  •         {   
  •             Speed[1+i] = Read_byte();   
  •         }   
  •         Read_byte();   
  •     }   
  •     Read_byte();   
  •     temp = Read_byte();   
  •     if(',' != temp)   
  •     {   
  •         Date[0] = temp;   
  •         for(i=0; i<5; i++)   
  •         {   
  •             Date[i+1] = Read_byte();   
  •         }      
  •     }   
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • void Display_gprmc(void)   
  • {   
  •     uchar high,low,i;   
  •     high = Time[0];   
  •     low = Time[1];   
  •     low = low+8;   
  •     if(low > 57)   
  •     {   
  •         low = low - 10;   
  •         high = high + 1;    
  •     }   
  •     LCD1602_clear();   
  •     while(LCD1602_readBF());   
  •     LCD1602_gotoXY(1,0);   
  •     LCD1602_sendbyte(iDat,high);   
  •     LCD1602_sendbyte(iDat,low);   
  •     LCD1602_sendbyte(iDat,':');   
  •     LCD1602_sendbyte(iDat,Time[2]);   
  •     LCD1602_sendbyte(iDat,Time[3]);   
  •     LCD1602_sendbyte(iDat,':');   
  •     LCD1602_sendbyte(iDat,Time[4]);   
  •     LCD1602_sendbyte(iDat,Time[5]);   
  •     LCD1602_sendbyte(iDat,' ');   
  •     LCD1602_sendbyte(iDat,Status);   
  •     while(LCD1602_readBF());   
  •     LCD1602_gotoXY(2,0);   
  •     LCD1602_sendbyte(iDat,Date[4]);   
  •     LCD1602_sendbyte(iDat,Date[5]);   
  •     LCD1602_sendbyte(iDat,'.');   
  •     LCD1602_sendbyte(iDat,Date[2]);   
  •     LCD1602_sendbyte(iDat,Date[3]);   
  •     LCD1602_sendbyte(iDat,'.');   
  •     LCD1602_sendbyte(iDat,Date[0]);   
  •     LCD1602_sendbyte(iDat,Date[1]);   
  •     Delayms(50000);   
  •     LCD1602_clear();   
  •     while(LCD1602_readBF());   
  •     LCD1602_gotoXY(1,0);   
  •     LCD1602_sendbyte(iDat,Latitude[0]);   
  •     LCD1602_sendbyte(iDat,Latitude[1]);   
  •     LCD1602_sendbyte(iDat,'.');   
  •     for(i=0; i<7; i++)   
  •     {   
  •         LCD1602_sendbyte(iDat,Latitude[2+i]);   
  •     }   
  •     LCD1602_sendbyte(iDat,' ');   
  •     LCD1602_sendbyte(iDat,NSIndicator);   
  •     while(LCD1602_readBF());   
  •     LCD1602_gotoXY(2,0);   
  •     LCD1602_sendbyte(iDat,Longitude[0]);   
  •     LCD1602_sendbyte(iDat,Longitude[1]);   
  •     LCD1602_sendbyte(iDat,Longitude[2]);   
  •     LCD1602_sendbyte(iDat,'.');    
  •     for(i=0; i<7; i++)   
  •     {   
  •         LCD1602_sendbyte(iDat,Longitude[3+i]);   
  •     }      
  •     LCD1602_sendbyte(iDat,' ');   
  •     LCD1602_sendbyte(iDat,EWIndicator);   
  •     Delayms(50000);   
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • void Read_gprmc(void)   
  • {   
  •     uchar temp = 0;   
  •     temp = Read_byte();   
  •     if(temp == '$')   
  •     {   
  •         Read_byte();   
  •         Read_byte();   
  •         temp = Read_byte();   
  •         if(temp == 'R')   
  •         {   
  •             temp = Read_byte();   
  •             if(temp == 'M')   
  •             {   
  •                 temp = Read_byte();   
  •                 if(temp == 'C')   
  •                 {   
  •                     Parse_gprmc();   
  •                     Display_gprmc();   
  •                 }   
  •             }   
  •         }   
  •     }   
  • }   
  •    
  •  
  •  
  •  
  •  
  •  
  •    
  • int main(void)   
  • {   
  •  Board_init( );               
  •  Uart_init(9600);             
  •  LCD1602_initial();   
  •   while(LCD1602_readBF());   
  •   LCD1602_gotoXY(1,0);   
  •   LCD1602_sendstr("AVR_PQ1A BOARD");       
  •  while(1)   
  •  {   
  •     Read_gprmc();   
  •  }   
  • }   
  •