嵌入式课设报告CAN总线与GPS模块数据通信.doc

上传人:jian****018 文档编号:7983661 上传时间:2020-03-26 格式:DOC 页数:19 大小:67.50KB
返回 下载 相关 举报
嵌入式课设报告CAN总线与GPS模块数据通信.doc_第1页
第1页 / 共19页
嵌入式课设报告CAN总线与GPS模块数据通信.doc_第2页
第2页 / 共19页
嵌入式课设报告CAN总线与GPS模块数据通信.doc_第3页
第3页 / 共19页
点击查看更多>>
资源描述
北 华 航 天 工 业 学 院课程设计报告(论文)设计课题:CAN总线与GPS模块 数据通信 专业班级: B11212 学生姓名: 王冰 王晓瑞 巴雅芳 赵雪志 彭宇龙指导教师: 姚晓琼 设计时间: 2014年6月 北华航天工业学院电子工程系 CAN总线与GPS模块数据通信 课程设计任务书姓 名:王冰专 业:电子信息工程班 级:B11212指导教师: 姚晓琼职 称:教授 学 号:(20114020326)课程设计题目:CAN总线与GPS模块数据通信设计要求:1、 实现双机CAN总线数据通信2、 实现单台实验箱GPS模块信息接收并显示(超级终端或实验箱LCD显示)3、 两台实验箱数据通信:一台实验箱通过GPS模块接收数据,通过CAN总线发送,另一台实验箱从CAN总线接收数据并通过超级终端显示4、 实现第3步,显示改为实验箱的LCD所需仪器设备:电脑,2个嵌入式实验箱(含硬件仿真器),GPS模块、天线。成果验收形式:演示,在超级终端或LCD上显示实验结果参考文献:嵌入式系统设计与实例开发清华大学出版社嵌入式处理器分类与现状液晶显示器的基本常识嵌入式系统构建时间安排(一)周一上午的工作安排(2014年6月9日):1、全体学生集中,介绍和说明本次综合课程设计的目的、实施方法和要完成的任务内容2、给学生一些本次综合课程设计相关参考资料(二)周一下午至周五(2014年6月9日-2014年6月13日):1、各小组完成实验要求2、 最后一天验收学生的课程设计成果(周五)2014年 6月 日注:本表下发学生一份,指导教师一份,栏目不够时请另附页。课程设计任务书装订于设计计算说明书(或论文)封面之后,目录页之前。内 容 摘 要 在当今的工业现场总线技术中,CAN总线技术凭借其实现数据通信的高可靠性、实时性和灵活性等优点,广泛运用于各个领域;无限数据通信网络的发展,使数据传输更加方便。本文提出了一种基于CAN总线与GPS的数据通信系统,给出了系统设计方案。索引关键词:CAN总线 GPS模块 目 录一 概 述 1二 方案设计与论证1三 单元程序设1 3.1.发送程序GPS13.2 接收程序 15 四 结论18五 心得体会18六 参考文献18 一、概述 CAN是控制器局域网络(Controller Area Network, CAN)的简称,是由研发和生产汽车电子产品著称的德国BOSCH公司开发了的,并最终成为国际标准(ISO 11898)。是国际上应用最广泛的现场总线之一。 在北美和西欧,CAN总线协议已经成为汽车计算机控制系统和嵌入式工业控制局域网的标准总线,并且拥有以CAN为底层协议专为大型货车和重工机械车辆设计的J1939协议。GPS模块就是集成了RF射频芯片、基带芯片和核心CPU,并加上相关外围电路而组成的一个集成电路。目前GPS模块的GPS芯片大部分还是采用全球市占率第一的SiRFIII系列为主。S3C2410处理器是Samsung公司基于ARM公司的ARM920T处理器核,采用FBGA封装,采用0.18um制造工艺的32位微控制器。该处理器拥有:独立的16KB指令Cache和16KB数据Cache,MMU,支持TFT的LCD控制器,NAND闪存控制器,3路UART,4路DMA,4路带PWM的Timer ,I/O口,RTC,8路10位ADC,Touch Screen接口,IIC-BUS 接口,IIS-BUS 接口,2个USB主机,1个USB设备,SD主机和MMC接口,2路SPI。S3C2410处理器最高可运行在203MHz。本次课设就是利用CAN总线实现一台实验箱接受GPS数据另一台实验箱显示实验数据。2、 方案设计与论证1、实现双机CAN总线数据通信(CAN总线调通,能实现简单的字符串的接受发送)2、实现CAN总线程序与GPS模块程序的融合并用超级终端显示三、单元程序设计1、发送程序#include #include #include .incgps.h#include inc/sys/uart.h#define USE_BEIJING_TIMEZONEstatic int GetComma(int num,char* str);static void UTC2BTC(date_time *GPS);static double get_double_number(char *s);/*int n;unsigned int id;int length;BOOL rxRTR, isExt;U8 data18=0,;U8 gps14;U8 i=0,flag=0;*/void show_gps(int a,GPS_INFO *GPS)char *data;if(a)show_date(GPS-D.year,GPS-D.month,GPS-D.day);show_time(GPS-D.hour,GPS-D.minute,GPS-D.second);Uart_Printf(0,DATE : %0ld-%02d-%02d n,GPS-D.year,GPS-D.month+1,GPS-D.day+1);Uart_Printf(0,TIME : %02d:%02d:%02d n,GPS-D.hour,GPS-D.minute+1,GPS-D.second+1);Uart_Printf(0,Latitude : %.4f %cn,GPS-latitude,GPS-NS);Uart_Printf(0,Longitude : %.4f%cn,GPS-longitude,GPS-EW);Uart_Printf(0,Highness : %.4f n,GPS-high);Uart_Printf(0,STATUS : %cn,GPS-status);/*if(!a)if(n=canPoll()!=-1)canRead(n, &id, data1, &length, &rxRTR, &isExt);if(data0=r)/发送换行Uart_SendByte(0,n);if(iD.hour =(buf 7-0)*10+(buf 8-0);GPS-D.minute =(buf 9-0)*10+(buf10-0);GPS-D.second =(buf11-0)*10+(buf12-0);tmp = GetComma(9,buf);GPS-D.day =(buftmp+0-0)*10+(buftmp+1-0);GPS-D.month =(buftmp+2-0)*10+(buftmp+3-0);GPS-D.year =(buftmp+4-0)*10+(buftmp+5-0)+2000;GPS-status =bufGetComma(2,buf);GPS-latitude =get_double_number(&bufGetComma(3,buf);GPS-NS =bufGetComma(4,buf);GPS-longitude=get_double_number(&bufGetComma(5,buf);GPS-EW =bufGetComma(6,buf);#ifdef USE_BEIJING_TIMEZONEUTC2BTC(&GPS-D);#endifif(c=A) /$GPGGAGPS-high = get_double_number(&bufGetComma(9,buf);static double get_double_number(char *s)char buf128;int i;double rev;i=GetComma(1,s);strncpy(buf,s,i);bufi=0;rev=atof(buf);return rev;static int GetComma(int num,char *str)int i,j=0;int len=strlen(str);for(i=0;isecond+; /加一秒if(GPS-second59)GPS-second=0;GPS-minute+;if(GPS-minute59)GPS-minute=0;GPS-hour+;GPS-hour+=8;if(GPS-hour23)GPS-hour-=24;GPS-day+=1;if(GPS-month=2 | GPS-month=4 | GPS-month=6 | GPS-month=9 | GPS-month=11 )if(GPS-day30) GPS-day=1;GPS-month+;elseif(GPS-day31) GPS-day=1;GPS-month+;if(GPS-year % 4 = 0 ) if(GPS-day 29 & GPS-month =2) GPS-day=1;GPS-month+;else if(GPS-day28 &GPS-month =2) GPS-day=1;GPS-month+;if(GPS-month12)GPS-month-=12;GPS-year+;Gps_main.c#include #include ./inc/gps.h#include ./inc/sys/lib.h#include inc/drv/Serial.h#include #include os_cpu.h#include ./ucos-ii/includes.h#include ./ucos-ii/ucos_ii.h#define FALSE 0#define TRUE 1volatile int STOP=FALSE;GPS_INFO gps_info;int GET_GPS_OK=FALSE;char GPS_BUF1024,*rxmsg;OS_EVENT *mbox;#define rULCON2(*(volatile unsigned *)0x50008000)/p317#define rUCON2(*(volatile unsigned *)0x50008004)/p318#define rUFCON2(*(volatile unsigned *)0x50008008)/p320#define rUTRSTAT2(*(volatile unsigned *)0x50008010)/p322#define rUERSTAT2(*(volatile unsigned *)0x50008014)/p323#define rUFSTAT2(*(volatile unsigned *)0x50008018)/p324#define rURXH2(*(volatile unsigned *)0x50008024)/326#define rUBRDIV2(*(volatile unsigned *)0x50008028)/327/*-*/* modem input handler */void show_gps_info(void * Id) char txmsg; INT8U err;while(1) rxmsg=OSMboxPend(mbox,0,&err); gps_parse(rxmsg,&gps_info); show_gps(1,&gps_info);/1为发送数据,0为接收数据。 OSTimeDly(50); /*-*/* modem input handler */void receive(void * Id) int i=0,counter=0;char c; char buf200;GPS_INFO GPS; Uart_Init(2,4800); OpenUartRev(2); hudelay(100); mbox=OSMboxCreate(void *)0);while (1) while(1) if(c=Uart_Getch(2) bufi+ = c; if(i=200)/防止buf越界 i=0; break; if(c = n) bufi=0; break; if(buf0 = $)i=0; OSMboxPost(mbox,(void *)buf); OSTimeDly(1000); Main.c#include./ucos-ii/includes.h /* uC/OS interface */#include ./ucos-ii/add/osaddition.h#include ./inc/drivers.h#include ./inc/sys/lib.h#include ./src/gui/gui.h#include #include #include ./inc/MCP25101.h#include ./inc/myuart1.h#pragma import(_use_no_semihosting_swi) / ensure no functions that use semihosting /*任务定义*/*OS_STK SYS_Task_StackSTACKSIZE= 0, ; /system task刷新任务堆栈#define SYS_Task_Prio1 void SYS_Task(void *Id);*/*OS_STK task1_StackSTACKSIZE=0, ; /Main_Test_Task堆栈void Task1(void *Id); /Main_Test_Task#define Task1_Prio 12*/*OS_STK task2_StackSTACKSIZE=0, ; /test_Test_Task堆栈void Task2(void *Id); /test_Test_Task#define Task2_Prio 15*/OS_STK Main_StackSTACKSIZE=0, ; /Main_Test_Task堆栈void Main_Task(void *Id); /Main_Test_Task#define Main_Task_Prio 10OS_STK Recv_StackSTACKSIZE=0, ; void receive(void *Id);#define Recv_Prio 15OS_STK Show_gps_StackSTACKSIZE= 0, ; void show_gps_info(void *Id); #define Show_gps_Prio 13/*已经定义的OS任务*#define SYS_Task_Prio1#define Touch_Screen_Task_Prio9#define Main_Task_Prio 12#define Key_Scan_Task_Prio 58#define Lcd_Fresh_prio 59#define Led_Flash_Prio 60int main(void)int n;unsigned int id;int length;BOOL rxRTR, isExt;U8 data18=0,;U8 gps15=0,;U8 i=0,flag=0;ARMTargetInit(); / do target (uHAL based ARM system) initialisation /OSInit(); / needed by uC/OS-II /OSInitUart();init_MCP2510(BandRate_250kbps);/可在该函数内设置成回环模式 /从而只用一台设备完成实验canSetup();Uart_SendByte(0,0xa);/换行Uart_SendByte(0,0xd);/回车/*for(;)if(n=canPoll()!=-1)/CAN总线收到数据,则发送到串口canRead(n, &id, data1, &length, &rxRTR, &isExt);/Uart_SendByte(0,data0);/显示采集的数据 /Uart_Printf(0,id is %x,id);if(data10=r)/发送换行Uart_SendByte(0,n);if(i=14)gpsi=data10;i+;if(i=14)i=0;flag=1;if(gps14=r)Uart_Printf(0,DATE : %d%d%d%d-%d%d-%d%dn,gps0-0x30,gps1-0x30,gps2-0x30,gps3-0x30,gps4-0x30,gps5-0x30,gps6-0x30,gps7-0x30);Uart_Printf(0,TIME : %d%d:%d%d:%d%dn,gps8-0x30,gps9-0x30,gps10-0x30,gps11-0x30,gps12-0x30,gps13-0x30);i=0;*/ OSTaskCreate(receive, (void *)0, (OS_STK *)&Recv_StackSTACKSIZE-1, Recv_Prio );OSTaskCreate(show_gps_info, (void *)0, (OS_STK *)&Show_gps_StackSTACKSIZE-1, Show_gps_Prio );OSAddTask_Init(0); OSStart(); / start the OS / never reached /return 0;/main2、接收程序Main.c(与发送只有主函数不同,其他两个函数一样)#include./ucos-ii/includes.h /* uC/OS interface */#include ./ucos-ii/add/osaddition.h#include ./inc/drivers.h#include ./inc/sys/lib.h#include ./src/gui/gui.h#include #include #include ./inc/MCP25101.h#include ./inc/myuart1.h#pragma import(_use_no_semihosting_swi) / ensure no functions that use semihosting /*任务定义*/*OS_STK SYS_Task_StackSTACKSIZE= 0, ; /system task刷新任务堆栈#define SYS_Task_Prio1 void SYS_Task(void *Id);*/*OS_STK task1_StackSTACKSIZE=0, ; /Main_Test_Task堆栈void Task1(void *Id); /Main_Test_Task#define Task1_Prio 12*/*OS_STK task2_StackSTACKSIZE=0, ; /test_Test_Task堆栈void Task2(void *Id); /test_Test_Task#define Task2_Prio 15*/OS_STK Main_StackSTACKSIZE=0, ; /Main_Test_Task堆栈void Main_Task(void *Id); /Main_Test_Task#define Main_Task_Prio 10OS_STK Recv_StackSTACKSIZE=0, ; void receive(void *Id);#define Recv_Prio 15OS_STK Show_gps_StackSTACKSIZE= 0, ; void show_gps_info(void *Id); #define Show_gps_Prio 13/*已经定义的OS任务*#define SYS_Task_Prio1#define Touch_Screen_Task_Prio9#define Main_Task_Prio 12#define Key_Scan_Task_Prio 58#define Lcd_Fresh_prio 59#define Led_Flash_Prio 60int main(void)int n;unsigned int id;int length;BOOL rxRTR, isExt;U8 data18=0,;U8 gps14;U8 i=0,flag=0;ARMTargetInit(); / do target (uHAL based ARM system) initialisation /OSInit(); / needed by uC/OS-II /OSInitUart();init_MCP2510(BandRate_250kbps);/可在该函数内设置成回环模式 /从而只用一台设备完成实验canSetup();Uart_SendByte(0,0xa);/换行Uart_SendByte(0,0xd);/回车for(;)if(n=canPoll()!=-1)/CAN总线收到数据,则发送到串口canRead(n, &id, data1, &length, &rxRTR, &isExt);if(i=13)gpsi=data10;i+;if(i=14)i=0;flag=1;if(flag)Uart_Printf(0,DATE : %d%d%d%d-%d%d-%d%dn,gps0-0x30,gps1-0x30,gps2-0x30,gps3-0x30,gps4-0x30,gps5-0x30,gps6-0x30,gps7-0x30);Uart_Printf(0,TIME : %d%d:%d%d:%d%dn,gps8-0x30,gps9-0x30,gps10-0x30,gps11-0x30,gps12-0x30,gps13-0x30);flag=0;/*OSTaskCreate(Task2, (void *)0, (OS_STK *)&task2_StackSTACKSIZE-1, Task2_Prio);*/OSTaskCreate(Main_Task, (void *)0, (OS_STK *)&Main_StackSTACKSIZE-1, Main_Task_Prio); /*OSTaskCreate(receive, (void *)0, (OS_STK *)&Recv_StackSTACKSIZE-1, Recv_Prio );OSTaskCreate(show_gps_info, (void *)0, (OS_STK *)&Show_gps_StackSTACKSIZE-1, Show_gps_Prio );OSAddTask_Init(0);OSStart(); */ / start the OS /return 0;四、结论将CAN总线与GPS通信相结合,使CAN结点获得的信号能通过总线实时地、可靠地、告诉而准确地进行传输,使得各由计算机控制单元能够通过CAN总线共享所有信息和资源,达到简化布线、减少传感器数量、避免控制功能重复、提高系统可靠性、降低成本、更好地匹配和协调各个控制系统的目的。五、心得体会通过这次课程设计,我们对CAN总线的工作原理及GPS模块有了一定程度的理解,了解到CAN总线可实现多种数据的传输。一次次分析程序、修改程序,使我们深入地理解了很多上课时候的知识点,将平时学到的理论课程在课设期间运用起来。此外,我还学到了团队合作精神的重要性,有不懂的地方,提出来大家一起讨论解决。六、参考文献1. 嵌入式系统设计与实例开发清华大学出版社 2.嵌入式处理器分类与现状3.液晶显示器的基本常识4.嵌入式系统构建 电子工程系CAN总线与GPS模块数据通信课程设计成绩评定表专业:电子信息工程 班级: B11212姓名:马召 杜鹏 杜瑜 卓晓鹏 韩卫雪 吴宇萍 崔园园课题名称CAN总线与GPS模块数据通信设计任务与要求设计要求:1、实现双机CAN总线数据通信2、实现单台实验箱GPS模块信息接收并显示(超级终端或实验箱LCD显示)3、两台实验箱数据通信:一台实验箱通过GPS模块接收数据,通过CAN总线发送,另一台实验箱从CAN总线接收数据并通过超级终端显示4、实现第3步,显示改为实验箱的LCD指导教师评语 建议成绩: 指导教师:课程小组评定评定成绩: 课程负责人: 年 月 日
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 管理文书 > 工作总结


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!