极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 54119|回复: 23

自制基于arduino的GPS地图导航系统2.0

[复制链接]
发表于 2013-6-18 11:54:40 | 显示全部楼层 |阅读模式
本帖最后由 davidce 于 2014-3-12 23:01 编辑

这是"自制基于arduino的GPS地图导航系统"(http://www.geek-workshop.com/thread-1846-1-2.html)的升级版,主要算法类似。自制基于arduino的GPS地图导航系统3.0 在这里查看



屏幕采用oled RGB 96*64 ,使用三轴磁阻获取罗盘信息(受周围磁场干扰较大),使用SD卡存储地图数据,使用TinyGPS处理GPS数据。

oled RGB 96*64 使用的是lm095cg-096064

接线方法和代码如下:
  1. //OLED LM095CG-096064 - UNO
  2. //E/RD#(12) - VCC
  3. //R/W#(13) - GND
  4. //D/C#(14) - A0
  5. //RES#(15) - A1
  6. //CS#(16) - A2
  7. //D7(4) - 7
  8. //D6(5) - 6
  9. //D5(6) - 5
  10. //D4(7) - 4
  11. //D3(8) - 3
  12. //D2(9) - 2
  13. //D1(10) - 9
  14. //D0(11) - 8

  15. /***********************************************************/
  16. //oled pin define
  17. /***********************************************************/
  18. #define CS A2
  19. #define DC A0
  20. #define RES A1
  21. /***********************************************************/
  22. // special defines for the dataport
  23. /***********************************************************/
  24. #define DATAPORT1 PORTD
  25. #define DATAPIN1 PIND
  26. #define DATADDR1 DDRD

  27. #define DATAPORT2 PORTB
  28. #define DATAPIN2 PINB
  29. #define DATADDR2 DDRB

  30. #define DATA1_MASK 0xFC  // top 6 bits
  31. #define DATA2_MASK 0x03  // bottom 2 bits

复制代码
函数:
  1. /* write by davidce
  2. [email protected]
  3. 2013.6.10
  4. v1.0
  5. */

  6. //********************************************
  7. //low level function
  8. //********************************************
  9. /**********************************************
  10. * // Write Command
  11. **********************************************/
  12. static void write_command(unsigned char Command_value)
  13. {
  14.   digitalWrite(CS, LOW);
  15.   digitalWrite(DC, LOW);
  16.   DATAPORT2 = (DATAPORT2 & DATA1_MASK) |
  17.     (Command_value & DATA2_MASK);
  18.   DATAPORT1 = (DATAPORT1 & DATA2_MASK) |
  19.     (Command_value & DATA1_MASK); // top 6 bits
  20.   digitalWrite(CS, HIGH);
  21. }
  22. /**********************************************
  23. * // Write Data
  24. **********************************************/
  25. static void write_Data(unsigned char Data_value)
  26. {
  27.   digitalWrite(CS, LOW);
  28.   digitalWrite(DC, HIGH);
  29.   DATAPORT2 = (DATAPORT2 & DATA1_MASK) |
  30.     (Data_value & DATA2_MASK);
  31.   DATAPORT1 = (DATAPORT1 & DATA2_MASK) |
  32.     (Data_value & DATA1_MASK); // top 6 bits
  33.   digitalWrite(CS, HIGH);
  34. }
  35. /********************************************
  36. * // Draw Picture
  37. ********************************************/
  38. static void drawPicFromFlash(uint8_t x0,uint8_t y0,uint8_t w,uint8_t h,const PROGMEM char *c)                                               
  39. {
  40.   digitalWrite(DC, LOW);  //solve a bug of write_command defore write_data
  41.   write_command(0x15); //set column address
  42.   write_command(x0); //column address start 00
  43.   write_command(x0+w-1); //column address end 95
  44.   write_command(0x75); //set row address
  45.   write_command(y0); //row address start 00
  46.   write_command(y0+h-1); //row address end 63

  47.   unsigned char k,i;
  48.   for(k=0;k<h;k++)
  49.   {
  50.     for(i=0;i<w;i++)
  51.     {       
  52.       write_Data(pgm_read_byte(c++));
  53.       write_Data(pgm_read_byte(c++));
  54.     }
  55.   }
  56. }
  57. /********************************************
  58. * // Fill color
  59. ********************************************/
  60. static void fill_color (uint8_t startx,uint8_t endx,uint8_t starty,uint8_t endy,unsigned char dat1,unsigned char dat2)                                               
  61. {
  62.   digitalWrite(DC, LOW);  //solve a bug of write_command defore write_data
  63.   write_command(0x15); //set column address
  64.   write_command(startx); //column address start 00
  65.   write_command(endx-1); //column address end 95
  66.   write_command(0x75); //set row address
  67.   write_command(starty); //row address start 00
  68.   write_command(endy-1); //row address end 63
  69.   unsigned char k,i;
  70.   for(k=starty;k<endy;k++)
  71.   {
  72.     for(i=startx;i<endx;i++)
  73.     {       
  74.       write_Data(dat1);
  75.       write_Data(dat2);
  76.     }
  77.   }
  78. }
  79. /********************************************
  80. * // DrawRectangle
  81. ********************************************/
  82. static void drawRectangle(unsigned char startx,unsigned char starty,
  83. unsigned char endx,unsigned char endy,
  84. unsigned char BcolorR,unsigned char BcolorB,unsigned char BcolorG,
  85. unsigned char FcolorR,unsigned char FcolorB,unsigned char FcolorG,
  86. boolean isFill)
  87. {
  88.   digitalWrite(DC, LOW);  //solve a bug of write_command defore write_data
  89.   write_command(0x26);
  90.   if(isFill)
  91.   {
  92.     write_command(0x01);
  93.   }
  94.   else
  95.   {
  96.     write_command(0x00);
  97.   }
  98.   write_command(0x22);
  99.   write_command(startx);
  100.   write_command(starty);
  101.   write_command(endx);
  102.   write_command(endy);
  103.   write_command(BcolorR);
  104.   write_command(BcolorB);
  105.   write_command(BcolorG);
  106.   write_command(FcolorR);
  107.   write_command(FcolorB);
  108.   write_command(FcolorG);
  109. }
  110. /********************************************
  111. * // cover color format from 888 to 565
  112. ********************************************/
  113. static uint16_t Color565(uint8_t r, uint8_t g, uint8_t b) {
  114.   uint16_t c;
  115.   c = r >> 3;
  116.   c <<= 6;
  117.   c |= g >> 2;
  118.   c <<= 5;
  119.   c |= b >> 3;
  120.   return c;
  121. }
  122. /********************************************
  123. * // DrawLine
  124. ********************************************/
  125. static void drawLine(unsigned char startx,unsigned char starty,
  126. unsigned char endx,unsigned char endy,
  127. unsigned char colorR,unsigned char colorB,unsigned char colorG)
  128. {
  129.   digitalWrite(DC, LOW);  //solve a bug of write_command
  130.   write_command(0x21);
  131.   write_command(startx);
  132.   write_command(starty);
  133.   write_command(endx);
  134.   write_command(endy);
  135.   write_command(colorR);
  136.   write_command(colorB);
  137.   write_command(colorG);
  138. }
  139. /***************************************************/
  140. //oled Initial
  141. /***************************************************/
  142. static void Initial_SSD1330ZB()
  143. {
  144.   write_command(0xfd); // command lock
  145.   write_command(0x12);
  146.   write_command(0xae); // display off
  147.   write_command(0xa4); // Normal Display mode
  148.   write_command(0x15); //set column address
  149.   write_command(0x00); //column address start 00
  150.   write_command(0x5f); //column address end 95
  151.   write_command(0x75); //set row address
  152.   write_command(0x00); //row address start 00
  153.   write_command(0x3f); //row address end 63
  154.   write_command(0x87); //master current control
  155.   write_command(0x0A);
  156.   write_command(0x81); //Set Contrast for Color A
  157.   write_command(0x85); //91
  158.   write_command(0x82); //Set Contrast for Color B
  159.   write_command(0x56); //50
  160.   write_command(0x83); //Set Contrast for Color C
  161.   write_command(0x7f); //7d
  162.   write_command(0x8a);  // set scond pre-change speed of Color A
  163.   write_command(0x64);
  164.   write_command(0x8b);  // set scond pre-change speed of Color B
  165.   write_command(0x78);
  166.   write_command(0x8c);  // set scond pre-change speed of Color C
  167.   write_command(0x64);
  168.   write_command(0xa0); //set re-map & data format
  169.   write_command(0x72); //Horizontal address increment
  170.   write_command(0xa1); //set display start line
  171.   write_command(0x00); //start 00 line
  172.   write_command(0xa2); //set display offset
  173.   write_command(0x00);
  174.   write_command(0xa8); //set multiplex ratio
  175.   write_command(0x3f); //64MUX
  176.   write_command(0xb0); //set power save
  177.   write_command(0x1a);
  178.   write_command(0xb1);
  179.   write_command(0xf1); // Phase 2 period Phase 1 period
  180.   write_command(0xb3); // Set Display Clock Divide Ratio/ Oscillator Frequency
  181.   write_command(0xd0);
  182.   write_command(0xbb); // set pre-charge
  183.   write_command(0x3e);
  184.   write_command(0xbe); //set Vcomh
  185.   write_command(0x3e);
  186.   write_command(0xad); //Select external VCC supply at Display ON
  187.   write_command(0x8e); //Select External VP voltage supply
  188.   write_command(0xaf); //display on
  189. }
  190. //********************************************
  191. //high level function
  192. //********************************************
  193. /********************************************
  194. * // DrawPixel
  195. ********************************************/
  196. static void drawPixel(unsigned char px,unsigned char py,
  197. unsigned char colorR,unsigned char colorB,unsigned char colorG)
  198. {
  199.   drawLine(px,py,px,py,colorR,colorB,colorG);
  200. }
  201. /********************************************
  202. * // draw a character
  203. ********************************************/
  204. static void drawChar(uint8_t x, uint8_t y, char c,uint8_t colorR,uint8_t colorB,uint8_t colorG,uint8_t size) {
  205.   uint8_t tempx,tempy;
  206.   uint8_t i,j;
  207.   for (i =0; i<5; i++ ) {
  208.     uint8_t line = pgm_read_byte(font+(c*5)+i);
  209.     for (j = 0; j<8; j++) {
  210.       if (line & 0x1) {
  211.         if (size == 1) // default size
  212.           drawPixel(x+i, y+j, colorR,colorB,colorG);
  213.         else {  // big size
  214.           tempx= x+i*size;
  215.           tempy= y+j*size;
  216.           drawRectangle(tempx,tempy,tempx + size,tempy + size, colorR,colorB,colorG,colorR,colorB,colorG,true);
  217.         }
  218.       }
  219.       line >>= 1;
  220.     }
  221.   }
  222. }
  223. /********************************************
  224. * // DrawString
  225. ********************************************/
  226. static void drawString(uint8_t x, uint8_t y, char *c,uint8_t colorR,uint8_t colorB,uint8_t colorG,uint8_t size) {
  227.   if(size>0)
  228.   {
  229.     while (c[0] != 0) {
  230.       drawChar(x, y, c[0], colorR,colorB,colorG, size);
  231.       x += size*6;
  232.       c++;
  233.     }
  234.   }
  235. }
  236. /********************************************
  237. * // DrawCircleHelper
  238. ********************************************/
  239. static void drawCircleHelper(uint8_t x0, uint8_t y0,
  240. uint8_t r, uint8_t cornername,
  241. uint8_t colorR,uint8_t colorB,uint8_t colorG) {
  242.   int16_t f = 1 - r;
  243.   int16_t ddF_x = 1;
  244.   int16_t ddF_y = -2 * r;
  245.   int16_t x = 0;
  246.   int16_t y = r;
  247.   while (x<y) {
  248.     if (f >= 0) {
  249.       y--;
  250.       ddF_y += 2;
  251.       f += ddF_y;
  252.     }
  253.     x++;
  254.     ddF_x += 2;
  255.     f += ddF_x;
  256.     if (cornername & 0x4) {
  257.       drawPixel(x0 + x, y0 + y,  colorR,colorB,colorG);
  258.       drawPixel(x0 + y, y0 + x,  colorR,colorB,colorG);
  259.     }
  260.     if (cornername & 0x2) {
  261.       drawPixel(x0 + x, y0 - y,  colorR,colorB,colorG);
  262.       drawPixel(x0 + y, y0 - x,  colorR,colorB,colorG);
  263.     }
  264.     if (cornername & 0x8) {
  265.       drawPixel(x0 - y, y0 + x,  colorR,colorB,colorG);
  266.       drawPixel(x0 - x, y0 + y,  colorR,colorB,colorG);
  267.     }
  268.     if (cornername & 0x1) {
  269.       drawPixel(x0 - y, y0 - x,  colorR,colorB,colorG);
  270.       drawPixel(x0 - x, y0 - y,  colorR,colorB,colorG);
  271.     }
  272.   }
  273. }
  274. /********************************************
  275. * // DrawCircle
  276. ********************************************/
  277. static void drawCircle(uint8_t x0, uint8_t y0,
  278. uint8_t r,
  279. uint8_t colorR,uint8_t colorB,uint8_t colorG)
  280. {
  281.   drawCircleHelper(x0, y0, r, 0xF, colorR,colorB,colorG);
  282.   drawPixel(x0, y0+r, colorR,colorB,colorG);
  283.   drawPixel(x0, y0-r, colorR,colorB,colorG);
  284.   drawPixel(x0+r, y0, colorR,colorB,colorG);
  285.   drawPixel(x0-r, y0, colorR,colorB,colorG);
  286. }
  287. /********************************************
  288. * // drawTriangle
  289. ********************************************/
  290. static void drawTriangle(uint8_t x0, uint8_t y0,
  291. uint8_t x1, uint8_t y1,
  292. uint8_t x2, uint8_t y2,
  293. unsigned char colorR,unsigned char colorB,unsigned char colorG)
  294. {
  295.   drawLine(x0, y0, x1, y1, colorR,colorB,colorG);
  296.   drawLine(x1, y1, x2, y2, colorR,colorB,colorG);
  297.   drawLine(x2, y2, x0, y0, colorR,colorB,colorG);
  298. }
  299. /********************************************
  300. * // init color OLED
  301. ********************************************/
  302. static void initOLED()
  303. {
  304.   pinMode(CS, OUTPUT);
  305.   pinMode(DC, OUTPUT);
  306.   pinMode(RES, OUTPUT);
  307.   //set pin output mode
  308.   DATADDR2 |= DATA2_MASK;
  309.   DATADDR1 |= DATA1_MASK;
  310.   //reset oled model
  311.   digitalWrite(RES, LOW);
  312.   delay(50);
  313.   digitalWrite(RES, HIGH);
  314.   delay(50);
  315.   Initial_SSD1330ZB();

  316.   fill_color(0,96,0,64,0x00,0x00);
  317. }

复制代码
代码仅供参考。
感谢 czad 赠送的atmge328p的贴片板和好人做到底的geek精神!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-6-18 12:25:54 | 显示全部楼层
真精致,楼主手太巧了
回复 支持 反对

使用道具 举报

发表于 2013-6-18 13:56:55 | 显示全部楼层
手巧+1 很精致
回复 支持 反对

使用道具 举报

发表于 2013-6-18 19:50:48 | 显示全部楼层
LZ 真是手巧
回复 支持 反对

使用道具 举报

发表于 2013-6-19 21:52:48 | 显示全部楼层
显示模块换了,效果比之前的好很多了
回复 支持 反对

使用道具 举报

发表于 2013-7-9 20:26:55 | 显示全部楼层
楼主太强大了!膜拜!请问TinyGPS库在哪里能找到?对我来说找了好久这东东还只是停在传说中!
回复 支持 反对

使用道具 举报

发表于 2013-9-15 00:07:08 来自手机 | 显示全部楼层
为什么看不到代码呢?
回复 支持 反对

使用道具 举报

发表于 2013-9-28 16:41:22 | 显示全部楼层
pgm_read_byte(font+(c*5)+i);    font 没定义啊
回复 支持 反对

使用道具 举报

发表于 2013-9-28 17:00:57 来自手机 | 显示全部楼层
做得很漂亮啊
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-9-28 19:33:42 | 显示全部楼层
lxk7280 发表于 2013-9-28 16:41
pgm_read_byte(font+(c*5)+i);    font 没定义啊

font 是字库,glcdfont.c 文件定义,可在网上找到
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-9-28 19:47:25 | 显示全部楼层
fangtaonj 发表于 2013-7-9 20:26
楼主太强大了!膜拜!请问TinyGPS库在哪里能找到?对我来说找了好久这东东还只是停在传说中!

很容易搜到的
回复 支持 反对

使用道具 举报

发表于 2013-10-10 15:05:22 | 显示全部楼层
我最近也想用TFT屏做一个GPS导航仪,希望楼主能不吝赐教!QQ:247843921,加下好友吧!
回复 支持 反对

使用道具 举报

发表于 2013-10-14 15:47:55 | 显示全部楼层
我最近也想做一个这个    楼主可以留个邮箱讨论下吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-10-14 15:50:30 | 显示全部楼层
在这就可以一起讨论,坛里的高手不少
回复 支持 反对

使用道具 举报

发表于 2013-10-22 23:32:42 | 显示全部楼层
楼主可以写一点你制作过程的资料吗
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 20:53 , Processed in 0.048760 second(s), 29 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表