|
发表于 2012-4-12 16:07:49
|
显示全部楼层
程序文件一:main.c
#include"config.h"
#include<reg51.h>
#include "lcd1602.h"
#include "gps.h"
void main()
{
lcd_init();
Lcd_Display(1 ,0, "Lat :");
Lcd_Display(2 ,0, "Lon :");
Uart_Init();
while(1)
{
if(gps_receive() == 1)
select();
}
}
程序文件二:gps.c
#include<reg51.h>
#include "config.h"
#include "lcd1602.h"
uchar gpsdat[36] =" " ;
uchar dispbuf[10] = "no signal";
void Uart_Init()
{
TMOD=0x20; //初始化串口
TL1 =0xfa;
TH1 =0xfa; //4800波特率
SCON=0x50; //工作方式1:八位异步通信,允许接收
PCON=0x00; //波特率加倍关
TR1=1; //开启启动定时器1
}
void shift1_data()
{
uchar temp_dat;
temp_dat = dispbuf[3];
dispbuf[3] = dispbuf[4];
dispbuf[4] = temp_dat;
temp_dat = dispbuf[2];
dispbuf[2] = dispbuf[3];
dispbuf[3] = temp_dat;
}
void shift2_data()
{
uchar temp_dat;
temp_dat = dispbuf[4];
dispbuf[4] = dispbuf[5];
dispbuf[5] = temp_dat;
temp_dat = dispbuf[3];
dispbuf[3] = dispbuf[4];
dispbuf[4] = temp_dat;
}
void select()
{
uchar sb = 0;
uchar fk= 0;
uchar *pda,*pjd;
pda = gpsdat;
pjd = dispbuf;
for(fk=0;fk<10;fk++) //经度数据挑选
{
*pjd=*(pda+23+fk);
pjd++;
}
*pjd = '\0';
shift2_data( );
Lcd_Display(2 ,6, dispbuf);
pjd = dispbuf;
for(sb=0;sb<9;sb++) //维度数据挑选
{
*pjd=*(pda+11+sb);
pjd++;
}
*pjd='\0';
shift1_data( );
Lcd_Display(1 ,6, dispbuf);
}
int gps_receive()
{
uchar *pdat;
uchar rec_con=0; //接收数据计数
pdat = gpsdat;
while(!RI);
RI = 0;
if(SBUF != '$')
return 0;
while(!RI);
RI = 0;
if(SBUF != 'G')
return 0;
while(!RI);
RI = 0;
if(SBUF != 'P')
return 0;
while(!RI);
RI = 0;
if(SBUF != 'G')
return 0;
while(!RI);
RI = 0;
if(SBUF !='G')
return 0;
while(!RI);
RI = 0;
if(SBUF != 'A')
return 0;
for(rec_con=0;rec_con<35;rec_con++)
{
while(!RI);
RI = 0;
*pdat= SBUF;
pdat++ ;
}
*pdat= '\0';
return 1;
}
程序文件三:lcd1602.c
#include<reg51.h>
#include"config.h"
sbit rs=P3^5;
sbit lcden=P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
void lcd_delay(uint16 x)
{
uint16 a,b;
for(a=x;a>0;a--)
for(b=3;b>0;b--);
}
void write_com(uchar com)
{
P0=com;
rs=0;
lcden=0;
lcd_delay(10);
lcden=1;
lcd_delay(10);
lcden=0;
}
void write_date(uchar date)
{
P0=date;
rs=1;
lcden=0;
lcd_delay(10);
lcden=1;
lcd_delay(10);
lcden=0;
}
void lcd_init()
{
dula=0;
wela=0;
write_com(0x38);
lcd_delay(20);
write_com(0x0f);
lcd_delay(20);
write_com(0x06);
lcd_delay(20);
write_com(0x01);
lcd_delay(20);
}
void Lcd_Display(uchar line ,uchar position,uchar *buf)
{
uint8 a=0;
uint8 counter =0;
if(line == 1)
{
write_com(0x80+position);
//lcd_delay(20);
}
else
{
write_com(0xc0+position);
}
lcd_delay(20);
while( ((*buf) != '\0'))
{
write_date(*buf);
lcd_delay(20);
buf++;
counter++;
}
}
void Lcd_Display(uchar line ,uchar position,uchar *buf);
#endif
帮我把这个程序改成只显示时分秒,急用,非常感谢 |
|