找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 21385|回复: 44
收起左侧

我也DIY电动车里程表

  [复制链接]
ID:85764 发表于 2015-7-18 15:42 | 显示全部楼层 |阅读模式
前段时间看见坛里发了电动车里程表的帖子,一时间有了一股冲动劲,自己也想DIY一个装在自己的电动车上增加一点实用的功能,经过两个星期的软件编程和硬件制作,哈哈终于完成了。高兴呀!!!现在把我制作过程的图片一起分享一下。
121230203788a613d1cdc6e3e4.jpg



液晶模块(cog12864)
1212302041496e6ed61ac29faf.jpg

12123020419ea48e81c7d85dd5.jpg


PCB制作
1212302041c5ee4b3743733252.jpg


121230204132f7e743f420938b.jpg


12123020417df28496eebbee50.jpg

1212302041d7f46c7ca0e484ae.jpg

1212302041bb6b57481270fb6c.jpg



仪表开始改装
12123020418a4a800c28ef4845.jpg


12123020475480d1eeb7ff9054.jpg


121230204121d505c991efd2ad.jpg



1212302041f580418aa772306c.jpg


1212302042de49f7ec7be5af26.jpg


1212302041fa8e1b5aac8c62da.jpg




48伏转12伏
1212302042a22ff0ed5cf5b6b1.jpg



组装仪表
121230204200bfae4a7a5da7a0.jpg


1212302042ffaacafeb4638a9c.jpg


121230204261f19282a969d168.jpg


12123020429fbf85f3e2777e89.jpg


1212302042d62c6562441e420e.jpg


12123020425388274162e43fe4.jpg


1212302042e597ebaef1d1ed5e.jpg


12123020421883475ac3bb3896.jpg


1212302042f028e1b3c08e0085.jpg

源代码: 表MC.rar (6.65 KB, 下载次数: 159)

hex.rar

7.78 KB, 下载次数: 115, 下载积分: 黑币 -5

里程表1.rar

22.86 KB, 下载次数: 148, 下载积分: 黑币 -5

里程表电路图.rar

11.57 KB, 下载次数: 217, 下载积分: 黑币 -5

评分

参与人数 3威望 +5 黑币 +24 收起 理由
zhaok2013 + 12 共享资料的黑币奖励!
qwa123 + 5 + 5 共享资料的积分奖励!
w835228863 + 7 赞一个!

查看全部评分

回复

使用道具 举报

ID:85764 发表于 2015-7-18 15:46 | 显示全部楼层
  1. #include <STC12C56.H>
  2. #include <intrins.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. uchar mia,fen,shi,s1num,s;
  6. uchar dyshu,a3,b3,c3,f2,g2,js1,mc1,m1,count;
  7. uint dc1,DY,n,mc2;
  8. unsigned long zc1,zj,dj;
  9. bit flag,flag2,flag4,flg1;
  10. float  sz[3];

  11. sbit si          =  P1^0;
  12. sbit scl  =  P1^1;
  13. sbit ao   =  P1^2;  
  14. sbit res  =  P1^3;

  15. sbit SDA  =  P2^5;  
  16. sbit SCL  =  P2^4;

  17. sbit s1   =  P2^1;
  18. unsigned char code num[] = {
  19. 0x00,0xF0,0x08,0x04,0x04,0x04,0x08,0xF0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,/*"0",0*/

  20. 0x00,0x00,0x08,0x08,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,/*"1",1*/

  21. 0x00,0x30,0x08,0x04,0x04,0x04,0x88,0x70,0x00,0x30,0x28,0x24,0x22,0x21,0x20,0x20,/*"2",2*/

  22. 0x00,0x10,0x08,0x84,0x84,0x84,0x48,0x30,0x00,0x08,0x10,0x20,0x20,0x20,0x11,0x0E,/*"3",3*/

  23. 0x00,0x00,0x80,0x60,0x18,0x04,0xFC,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x3F,0x04,/*"4",4*/

  24. 0x00,0xFC,0x84,0x44,0x44,0x44,0x84,0x04,0x00,0x09,0x10,0x20,0x20,0x20,0x10,0x0F,/*"5",5*/

  25. 0x00,0xF0,0x88,0x44,0x44,0x44,0x88,0x10,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,/*"6",6*/

  26. 0x00,0x04,0x04,0x04,0x84,0x64,0x14,0x0C,0x00,0x00,0x00,0x3C,0x03,0x00,0x00,0x00,/*"7",7*/

  27. 0x00,0x30,0x48,0x84,0x84,0x84,0x48,0x30,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x0E,/*"8",8*/

  28. 0x00,0xF0,0x08,0x04,0x04,0x04,0x08,0xF0,0x00,0x08,0x11,0x22,0x22,0x22,0x11,0x0F,/*"9",9*/

  29. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",10*/

  30. 0x00,0x00,0x80,0x40,0x40,0x40,0x80,0x00,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,/*"o",11*/

  31. 0x00,0xFC,0x00,0x00,0x80,0x40,0x20,0x00,0x00,0x3F,0x02,0x05,0x08,0x10,0x20,0x00,/*"k",12*/

  32. 0x00,0xC0,0x40,0x40,0x80,0x40,0x40,0x80,0x00,0x3F,0x00,0x00,0x3F,0x00,0x00,0x3F,/*"m",13*/

  33. 0x00,0x00,0x00,0x00,0xC0,0x30,0x0C,0x00,0x00,0x30,0x0C,0x03,0x00,0x00,0x00,0x00,/*"/",14*/

  34. 0x00,0xFC,0x80,0x40,0x40,0x40,0x80,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x3F,0x00,/*"h",15*/

  35. 0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00,/*":",16*/

  36. 0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,/*"v",17*/

  37. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,/*".",18*/

  38. };

  39. unsigned char code num1[] = {
  40. 0x40,0x20,0xE2,0x04,0x00,0x40,0x20,0x9C,0x82,0x82,0xBE,0x20,0x20,0x00,0x00,0x00,
  41. 0x00,0x00,0x1F,0x08,0x24,0x20,0x11,0x0A,0x04,0x0A,0x11,0x30,0x20,0x20,0x20,0x00,/*"设",0*/

  42. 0x00,0x00,0x00,0x4C,0x54,0x54,0xFA,0xAA,0xAE,0xAA,0x2A,0x26,0x00,0x00,0x00,0x00,
  43. 0x00,0x20,0x20,0x20,0x20,0x3F,0x2A,0x2A,0x20,0x1F,0x10,0x10,0x10,0x10,0x00,0x00,/*"置",1*/

  44. 0x00,0xF8,0x48,0x44,0xFC,0x00,0xA0,0x20,0x20,0x20,0xFE,0x10,0x10,0x10,0x00,0x00,
  45. 0x00,0x0F,0x04,0x04,0x0F,0x00,0x00,0x01,0x10,0x20,0x3F,0x00,0x00,0x00,0x00,0x00,/*"时",2*/

  46. 0x00,0x00,0x80,0x40,0x20,0x18,0x02,0x82,0x84,0x88,0x10,0x20,0x60,0x40,0x40,0x00,
  47. 0x01,0x21,0x20,0x11,0x09,0x05,0x13,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,/*"分",3*/

  48. 0x00,0x00,0x00,0xFC,0x04,0xA4,0xA4,0x7A,0x52,0x52,0x42,0x02,0xFE,0x00,0x00,0x00,
  49. 0x40,0x20,0x18,0x07,0x00,0x06,0x0A,0x09,0x09,0x07,0x20,0x40,0x3F,0x00,0x00,0x00,/*"周",4*/

  50. 0x00,0x80,0x80,0x80,0x80,0xFE,0xA0,0x50,0x48,0x46,0x40,0x40,0x40,0x00,0x00,0x00,
  51. 0x00,0x00,0x00,0x00,0x00,0x3F,0x10,0x09,0x02,0x04,0x08,0x18,0x10,0x10,0x00,0x00,/*"长",5*/

  52. 0x00,0x00,0xF8,0x24,0xFC,0x00,0x80,0x90,0x10,0xF9,0x82,0x40,0x30,0x00,0x00,0x00,
  53. 0x10,0x0C,0x03,0x09,0x1F,0x00,0x04,0x03,0x10,0x3F,0x00,0x01,0x02,0x04,0x04,0x00,/*"脉",6*/

  54. 0x00,0x00,0x08,0x90,0x40,0x00,0xE0,0x20,0x20,0xFF,0x90,0x90,0xD0,0x30,0x00,0x00,
  55. 0x00,0x04,0x06,0x01,0x00,0x00,0x00,0x01,0x01,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,/*"冲",7*/

  56. 0x00,0x00,0x10,0x08,0x04,0xF7,0xAC,0xAA,0x8A,0xFA,0x02,0x02,0x00,0x00,0x00,0x00,
  57. 0x00,0x10,0x10,0x48,0x44,0x27,0x2A,0x12,0x1A,0x26,0x20,0x60,0x40,0x40,0x40,0x00,/*"复",8*/

  58. 0x00,0x80,0x40,0xE0,0x1C,0x00,0x40,0x40,0x42,0x24,0xA0,0x20,0x20,0x00,0x00,0x00,
  59. 0x01,0x00,0x00,0x3F,0x00,0x10,0x10,0x13,0x10,0x0C,0x0B,0x08,0x08,0x08,0x00,0x00,/*"位",9*/

  60. 0x00,0x00,0x00,0x70,0x92,0xAC,0xA8,0xF8,0xAC,0x8A,0x69,0x18,0x00,0x00,0x00,0x00,
  61. 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,/*"单",10*/

  62. 0x00,0x00,0x00,0x00,0xE2,0x24,0x10,0x98,0x94,0xD3,0x30,0x00,0x00,0x00,0x00,0x00,
  63. 0x00,0x1C,0x00,0x00,0x0D,0x11,0x21,0x24,0x28,0x20,0x28,0x32,0x02,0x04,0x00,0x00,/*"总",11*/

  64. 0x40,0x40,0x20,0xE4,0x08,0x00,0x00,0xFC,0x2A,0xAA,0xB2,0x4E,0x20,0x00,0x00,0x00,
  65. 0x00,0x08,0x09,0x0E,0x08,0x08,0x10,0x17,0x12,0x22,0x20,0x21,0x22,0x20,0x20,0x00,/*"退",12*/

  66. 0x00,0x00,0x00,0xF0,0x80,0x80,0x80,0xFE,0x40,0x40,0x40,0xF0,0x00,0x00,0x00,0x00,
  67. 0x00,0x00,0x00,0x1C,0x10,0x10,0x10,0x1F,0x08,0x08,0x08,0x3C,0x00,0x00,0x00,0x00,/*"出",13*/

  68. 0x00,0x00,0x98,0x48,0x28,0x48,0x95,0x46,0x24,0x14,0x84,0x24,0x4C,0x40,0x00,0x00,
  69. 0x00,0x04,0x04,0x04,0x7A,0x41,0x40,0x3D,0x21,0x21,0x21,0x79,0x00,0x00,0x00,0x00,/*"密",14*/

  70. 0x00,0x00,0x08,0xC8,0xB8,0x84,0x04,0x80,0x74,0x04,0xA2,0x9E,0x80,0x80,0x00,0x00,
  71. 0x04,0x02,0x01,0x07,0x02,0x03,0x04,0x05,0x05,0x05,0x02,0x12,0x20,0x1F,0x00,0x00,/*"码",15*/

  72. //0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73. //0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  74. //0x40,0xC0,0x40,0x40,0x40,0x60,0x1C,0x03,0x1C,0x60,0x40,0x40,0x40,0xC0,0x40,0x00,
  75. //0x00,0x00,0x41,0x39,0x26,0x10,0x10,0x08,0x08,0x10,0x26,0x39,0x41,0x00,0x00,0x00,/*"☆",17*/

  76. };

  77. unsigned char code num2[] = {
  78. 0x00,0x00,0xC0,0xF0,0xF8,0x3C,0x1E,0x0E,0x0E,0x1C,0x7C,0xF8,0xE0,0x80,0x00,0x00,
  79. 0x00,0xFC,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xF0,0x00,
  80. 0x00,0x7F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0x1F,0x00,
  81. 0x00,0x00,0x07,0x1F,0x3F,0x78,0x70,0xE0,0xE0,0x70,0x7C,0x3F,0x0F,0x03,0x00,0x00,/*"0",0*/

  82. 0x00,0x00,0x00,0xC0,0xE0,0xE0,0xE0,0xF8,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
  83. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
  84. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
  85. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,/*"1",1*/

  86. 0x00,0x00,0x80,0xF0,0xF8,0x3C,0x1E,0x0E,0x0E,0x1E,0x3C,0xF8,0xF0,0xC0,0x00,0x00,
  87. 0x00,0x00,0x07,0x07,0x07,0x00,0x00,0x00,0x00,0x80,0xE0,0xFF,0x7F,0x0F,0x00,0x00,
  88. 0x00,0x00,0x00,0x00,0x80,0xE0,0xF0,0x7C,0x3E,0x0F,0x07,0x01,0x00,0x00,0x00,0x00,
  89. 0x00,0xE0,0xF8,0xFE,0xFF,0xE7,0xE1,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0x00,0x00,/*"2",2*/

  90. 0x00,0x00,0xC0,0xF0,0xF8,0x3C,0x0E,0x0E,0x0E,0x1E,0x3C,0xF8,0xF0,0x80,0x00,0x00,
  91. 0x00,0x00,0x03,0x03,0x03,0x00,0x00,0x80,0xC0,0xC0,0xF0,0x7F,0x3F,0x07,0x00,0x00,
  92. 0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x01,0x01,0x03,0x07,0xFE,0xFC,0xF0,0x00,0x00,
  93. 0x00,0x01,0x0F,0x3F,0x7C,0x70,0xF0,0xE0,0xE0,0x70,0x78,0x3F,0x1F,0x07,0x00,0x00,/*"3",3*/

  94. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xF8,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,
  95. 0x00,0x00,0x00,0x80,0xE0,0xF8,0x3F,0x0F,0x01,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
  96. 0x00,0xF0,0xFC,0xFF,0xCF,0xC1,0xC0,0xC0,0xC0,0xFF,0xFF,0xFF,0xC0,0xC0,0xC0,0x00,
  97. 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,0xFF,0xFF,0x01,0x01,0x01,0x00,/*"4",4*/

  98. 0x00,0x00,0x00,0xFE,0xFE,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x00,0x00,
  99. 0x00,0x00,0xF0,0xFF,0xFF,0xE0,0x60,0x70,0x70,0x70,0xF0,0xE0,0xC0,0x00,0x00,0x00,
  100. 0x00,0x80,0x83,0x83,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,
  101. 0x00,0x01,0x0F,0x3F,0x7C,0x70,0xE0,0xE0,0xE0,0x70,0x7C,0x3F,0x0F,0x03,0x00,0x00,/*"5",5*/

  102. 0x00,0x00,0x00,0xC0,0xF0,0xF8,0x3C,0x1E,0x0E,0x0E,0x1E,0xFC,0xF8,0xE0,0x00,0x00,
  103. 0x00,0x00,0xFE,0xFF,0xFF,0xC1,0xE0,0x70,0x70,0x70,0xF0,0xE0,0xC0,0x00,0x00,0x00,
  104. 0x00,0x00,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,
  105. 0x00,0x00,0x01,0x0F,0x3F,0x7C,0x70,0xE0,0xE0,0xE0,0x78,0x3F,0x1F,0x07,0x00,0x00,/*"6",6*/

  106. 0x00,0x00,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0xFE,0xFE,0x3E,0x00,0x00,
  107. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xFF,0x7F,0x07,0x00,0x00,0x00,
  108. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFE,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,
  109. 0x00,0x00,0x00,0x00,0x00,0xC0,0xFC,0xFF,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,/*"7",7*/

  110. 0x00,0x00,0xC0,0xF0,0xF8,0x1C,0x0E,0x0E,0x0E,0x1E,0x3C,0xF8,0xF0,0x80,0x00,0x00,
  111. 0x00,0x00,0x1F,0x3F,0xFF,0xE0,0xC0,0x80,0x80,0xC0,0xE0,0x7F,0x3F,0x0F,0x00,0x00,
  112. 0x00,0xC0,0xF8,0xFE,0x1E,0x07,0x03,0x01,0x03,0x03,0x07,0xFE,0xFC,0xF8,0x00,0x00,
  113. 0x00,0x01,0x0F,0x3F,0x7E,0x70,0xE0,0xE0,0xE0,0xF0,0x78,0x7F,0x1F,0x0F,0x00,0x00,/*"8",8*/

  114. 0x00,0x00,0xC0,0xF0,0xF8,0x3C,0x0E,0x0E,0x0E,0x1C,0x7C,0xF8,0xE0,0x00,0x00,0x00,
  115. 0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFE,0x00,0x00,
  116. 0x00,0x00,0x03,0x07,0x1F,0x1E,0x1C,0x38,0x1C,0x1C,0x07,0xFF,0xFF,0x7F,0x00,0x00,
  117. 0x00,0x00,0x0E,0x3E,0x7E,0x70,0xE0,0xE0,0x70,0x78,0x3F,0x1F,0x07,0x00,0x00,0x00,/*"9",9*/

  118. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  119. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  120. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  121. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  122. };

  123. unsigned char code num3[] = {
  124. 0xFE,0x02,0x13,0x3B,0x13,0x02,0x02,0x02,0x02,0x82,0xC2,0xE2,0x82,0x82,0x42,0x22,
  125. 0x02,0x02,0x02,0x13,0x13,0x13,0x02,0xFE,0x1F,0x10,0x10,0x10,0x10,0x10,0x10,0x12,
  126. 0x11,0x10,0x10,0x13,0x11,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,/*"未命名文件",0*/
  127. };


  128. unsigned char code num4[] = {

  129. 0x00,0xC0,0xF8,0x3C,0x0E,0x03,0x03,0x03,0x03,0x06,0x3C,0xF8,0xC0,0x00,
  130. 0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,
  131. 0x00,0x01,0x0F,0x1E,0x38,0x60,0x60,0x60,0x60,0x30,0x1E,0x0F,0x01,0x00,/*"0",0*/

  132. 0x00,0x00,0x00,0x30,0x30,0x38,0xFC,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
  133. 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
  134. 0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,/*"1",1*/

  135. 0x00,0xF0,0xFC,0x0E,0x07,0x03,0x03,0x03,0x03,0x0E,0xFC,0xF8,0x00,0x00,
  136. 0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x1E,0x07,0x03,0x00,0x00,
  137. 0x00,0x70,0x7C,0x7E,0x6F,0x63,0x60,0x60,0x60,0x60,0x60,0x60,0x00,0x00,/*"2",2*/

  138. 0x00,0x70,0x7C,0x0E,0x07,0x03,0x03,0x03,0x03,0x06,0xFC,0xF8,0x00,0x00,
  139. 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x1E,0x3F,0xF3,0xE1,0x00,0x00,
  140. 0x00,0x07,0x1F,0x38,0x70,0x60,0x60,0x60,0x70,0x38,0x1F,0x07,0x00,0x00,/*"3",3*/

  141. 0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0x3C,0x0F,0xFF,0xFF,0x00,0x00,0x00,
  142. 0x00,0xC0,0xF0,0xBC,0x8F,0x83,0x80,0x80,0x80,0xFF,0xFF,0x80,0x80,0x00,
  143. 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x7F,0x7F,0x01,0x01,0x00,/*"4",4*/

  144. 0x00,0x00,0xC0,0xFF,0x3F,0x83,0x83,0x83,0x83,0x03,0x03,0x03,0x00,0x00,
  145. 0x00,0x00,0x0F,0x0F,0x07,0x03,0x01,0x01,0x01,0x07,0xFE,0xF8,0x00,0x00,
  146. 0x00,0x0E,0x3E,0x70,0xE0,0xC0,0xC0,0xC0,0x60,0x78,0x1F,0x07,0x00,0x00,/*"5",5*/

  147. 0x00,0x00,0x80,0xF8,0x7C,0x0E,0x07,0x03,0x03,0x03,0x06,0x1E,0x18,0x00,
  148. 0x00,0x00,0xFF,0xFF,0x0C,0x06,0x03,0x03,0x03,0x07,0x0E,0xFC,0xF0,0x00,
  149. 0x00,0x00,0x01,0x0F,0x3C,0x30,0x60,0x60,0x60,0x70,0x38,0x1F,0x07,0x00,/*"6",6*/

  150. 0x00,0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0xF3,0xFF,0x0F,0x00,0x00,
  151. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xFF,0x1F,0x00,0x00,0x00,0x00,
  152. 0x00,0x00,0x00,0x00,0x00,0x60,0x7E,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,/*"7",7*/

  153. 0x00,0x00,0xF8,0xFE,0x06,0x03,0x03,0x03,0x06,0xFE,0xF8,0x00,0x00,0x00,
  154. 0x00,0xC0,0xF1,0x3B,0x1E,0x0C,0x0C,0x0C,0x1E,0x3B,0xF1,0xC0,0x00,0x00,
  155. 0x00,0x0F,0x1F,0x38,0x70,0x60,0x60,0x60,0x70,0x38,0x1F,0x0F,0x00,0x00,/*"8",8*/

  156. 0x00,0xF0,0xFC,0x0E,0x07,0x03,0x03,0x03,0x06,0x0E,0xF8,0xE0,0x00,0x00,
  157. 0x00,0x07,0x0F,0x1C,0x30,0x30,0x30,0x30,0x18,0x0C,0xFF,0xFF,0x00,0x00,
  158. 0x00,0x0C,0x3C,0x30,0x60,0x60,0x60,0x70,0x38,0x1F,0x0F,0x00,0x00,0x00,/*"9",9*/

  159. } ;

  160. ///////////////////////////////////////////////////////////////////////////

  161. void delay2(uint z)
  162. {
  163.         uint y;
  164.         for(z;z>0;z--)
  165.                 for(y=440;y>0;y--);
  166. }

  167. void Wait2us()   //误差 0us
  168. {
  169.    uchar a;
  170.    for(a=8;a>0;a--);
  171. }

  172. void Wait4us()   //误差 0us
  173. {
  174.     Wait2us();
  175.         Wait2us();
  176. }

  177. ///////////////////////////////////////////////////////////////////////////           液晶
  178. void write_com(uchar w_command)
  179.      {
  180.           uchar counter_8;
  181.           ao=0;                           //指令
  182.           for(counter_8=0;counter_8!=8;counter_8++)
  183.               {
  184.                   scl=1;
  185.                    Wait2us();
  186.                   w_command<<=1;      //取8次,溢出在CY
  187.                   si=CY;
  188.                 Wait2us();
  189.                   scl=0;
  190.                   }                  
  191.                   scl=1;
  192.                   Wait2us();
  193.                   si=1;       
  194.          }
  195.                               
  196. void write_date(uchar w_data)                 //2写数据
  197.       {
  198.            uchar counter_8;         
  199.               ao=1;
  200.              for(counter_8=0;counter_8!=8;counter_8++)
  201.               {
  202.                   scl=1;
  203.                    Wait2us();
  204.                   w_data<<=1;               //取8次,溢出 在CY
  205.                   si=CY;
  206.           Wait2us();
  207.                   scl=0;
  208.                   }                  
  209.                   scl=1;
  210.                   Wait2us();
  211.                   si=1;
  212.             }

  213. void LcmClear( void )
  214. {
  215.     uchar i,j;
  216.         for(i=0;i<8;i++)
  217.         {
  218.                 write_com(0xB0|i); //Set Page Address as ComTable
  219.                 write_com(0x10); //Set Column Address = 0
  220.                 write_com(0x00); //Colum from 1 -> 129 auto add
  221.                 for(j=0;j<132;j++)
  222.                     write_date( 0 );
  223.         }
  224. }

  225. void LcmPutChar(uchar col,uchar page,uchar p)  //这里我不用x y做参数,是更贴切一些,实际上就是列值(横坐标)0-127,页值(纵坐标)0-7
  226. {
  227. uchar i;
  228. uint x;
  229.    x=p*16;
  230. write_com(page|0xB0); //Set Page Address
  231. write_com( (col>>4) | 0x10); //Set Column Address High Byte
  232. write_com( col&0x0F ); //Low Byte Colum from 1 -> 129auto add
  233. for(i=0;i<8;i++)
  234. {
  235.     write_date( num[x] );       
  236.     x++;
  237. }
  238. page++; //下半字符page+1
  239. write_com(page|0xB0); //Set Page Address
  240. write_com( (col>>4) | 0x10); //Set Column Address HighByte
  241. write_com( col&0x0F ); //Low Byte Colum from 1 ->129 auto add
  242. for(i=0;i<8;i++)
  243. {
  244.          write_date( num[x] );       
  245.      x++;
  246. }
  247. page--; //写完一个字符page还原
  248. }

  249. void LcmPutChar1(uchar col,uchar page,uchar p)    //这里我不用x y做参数,是更贴切一些,实际上就是列值(横坐标)0-127,页值(纵坐标)0-7
  250. {
  251. uchar i;
  252. uint x;
  253. x=p*64;
  254. write_com(page|0xB0); //Set Page Address
  255. write_com( (col>>4) | 0x10); //Set Column Address High Byte
  256. write_com( col&0x0F ); //Low Byte Colum from 1 -> 129auto add
  257. for(i=0;i<16;i++)
  258. {
  259. write_date( num2[x] );
  260. x++;
  261. }
  262. page++; //下半字符page+1
  263. write_com(page|0xB0); //Set Page Address
  264. write_com( (col>>4) | 0x10); //Set Column Address HighByte
  265. write_com( col&0x0F ); //Low Byte Colum from 1 ->129 auto add
  266. for(i=0;i<16;i++)
  267. {
  268. write_date( num2[x] );
  269. x++;
  270. }
  271. page++; //下半字符page+1
  272. write_com(page|0xB0); //Set Page Address
  273. write_com( (col>>4) | 0x10); //Set Column Address HighByte
  274. write_com( col&0x0F ); //Low Byte Colum from 1 ->129 auto add
  275. for(i=0;i<16;i++)
  276. {
  277. write_date( num2[x] );
  278. x++;
  279. }
  280. page++; //下半字符page+1
  281. write_com(page|0xB0); //Set Page Address
  282. write_com( (col>>4) | 0x10); //Set Column Address HighByte
  283. write_com( col&0x0F ); //Low Byte Colum from 1 ->129 auto add
  284. for(i=0;i<16;i++)
  285. {
  286. write_date( num2[x] );
  287. x++;
  288. }
  289. page-=3; //写完一个字符page还原
  290. }  

  291. void LcmPutChar2(uchar col,uchar page,uchar p)   //这里我不用x y做参数,是更贴切一些,实际上就是列值(横坐标)0-127,页值(纵坐标)0-7
  292. {
  293. uchar i;
  294. uint x;
  295.    x=p*32;
  296. write_com(page|0xB0); //Set Page Address
  297. write_com( (col>>4) | 0x10); //Set Column Address High Byte
  298. write_com( col&0x0F ); //Low Byte Colum from 1 -> 129auto add
  299. for(i=0;i<16;i++)
  300. {       
  301.      write_date( num1[x] );               
  302.     x++;
  303. }
  304. page++; //下半字符page+1
  305. write_com(page|0xB0); //Set Page Address
  306. write_com( (col>>4) | 0x10); //Set Column Address HighByte
  307. write_com( col&0x0F ); //Low Byte Colum from 1 ->129 auto add
  308. for(i=0;i<16;i++)
  309. {
  310.          write_date( num1[x] );       
  311.      x++;
  312. }
  313. page--; //写完一个字符page还原
  314. }

  315. void LcmPutChar3(uchar col,uchar page,uchar p)    //这里我不用x y做参数,是更贴切一些,实际上就是列值(横坐标)0-127,页值(纵坐标)0-7
  316. {
  317. uchar i;
  318. write_com(page|0xB0); //Set Page Address
  319. write_com( (col>>4) | 0x10); //Set Column Address High Byte
  320. write_com( col&0x0F ); //Low Byte Colum from 1 -> 129auto add
  321. for(i=0;i<24;i++)
  322. {       
  323.      write_date( num3[p] );               
  324.     p++;
  325. }
  326. page++; //下半字符page+1
  327. write_com(page|0xB0); //Set Page Address
  328. write_com( (col>>4) | 0x10); //Set Column Address HighByte
  329. write_com( col&0x0F ); //Low Byte Colum from 1 ->129 auto add
  330. for(i=0;i<24;i++)
  331. {
  332.          write_date( num3[p] );       
  333.      p++;
  334. }
  335. page--; //写完一个字符page还原
  336. }

  337. void LcmPutChar4(uchar col,uchar page,uchar p)    //这里我不用x y做参数,是更贴切一些,实际上就是列值(横坐标)0-127,页值(纵坐标)0-7
  338. {
  339. uchar i;
  340. uint x;
  341. x=p*42;
  342. write_com(page|0xB0); //Set Page Address
  343. write_com( (col>>4) | 0x10); //Set Column Address High Byte
  344. write_com( col&0x0F ); //Low Byte Colum from 1 -> 129auto add
  345. for(i=0;i<14;i++)
  346. {
  347. write_date( num4[x] );
  348. x++;
  349. }
  350. page++; //下半字符page+1
  351. write_com(page|0xB0); //Set Page Address
  352. write_com( (col>>4) | 0x10); //Set Column Address HighByte
  353. write_com( col&0x0F ); //Low Byte Colum from 1 ->129 auto add
  354. for(i=0;i<14;i++)
  355. {
  356. write_date( num4[x] );
  357. x++;
  358. }
  359. page++; //下半字符page+1
  360. write_com(page|0xB0); //Set Page Address
  361. write_com( (col>>4) | 0x10); //Set Column Address HighByte
  362. write_com( col&0x0F ); //Low Byte Colum from 1 ->129 auto add
  363. for(i=0;i<14;i++)
  364. {
  365. write_date( num4[x] );
  366. x++;
  367. }
  368. page-=2; //写完一个字符page还原
  369. }  

  370. //////////////////////////////////////////////////////////////////////////////           DS1307

  371. void I2C_start(void)
  372. {
  373.         SDA=1;
  374.         SCL=1;
  375.         Wait4us();
  376.         SDA=0;
  377.         Wait4us();
  378.         SCL=0;
  379. }

  380. void I2C_stop(void)
  381. {
  382.         SDA=0;
  383.         SCL=1;
  384.         Wait4us();
  385.         SDA=1;
  386.         Wait4us();
  387.         SCL=0;
  388. }

  389. void I2C_send_noack(void)
  390. {
  391.         SDA=1;
  392.         SCL=1;
  393.         Wait4us();
  394.         SCL=0;
  395. }

  396. unsigned char I2C_write_byte(unsigned char IIC_data)
  397. {
  398.         unsigned char i;
  399.         for(i=0;i<8;i++)
  400.         {
  401.                 Wait4us();                                                                 
  402.                 IIC_data=IIC_data<<1;
  403.                 F0=SDA=CY;
  404.                 SCL=1;
  405.                 if(F0!=SDA)
  406.                 {
  407.                         SCL=0;        return 0;
  408.                 }
  409.                 Wait4us();
  410.                 SCL=0;
  411.         }
  412.         SDA=1;
  413.         Wait4us();
  414.         SCL=1;
  415.         Wait4us();
  416.         if(SDA==1)
  417.         {
  418.                 SCL=0;        return 0;
  419.         }
  420.         else
  421.         {
  422.                 SCL=0;        return 1;
  423.         }
  424. }

  425. unsigned char I2C_read_byte(void)
  426. {
  427.   unsigned char i,dat;
  428.   dat=0;
  429.   SDA=1;
  430.   for (i=0;i<8;i++)
  431.         {
  432.                 Wait4us();
  433.                 dat=dat<<1;
  434.                 SCL=1;
  435.                 Wait4us();
  436.                 if(SDA==1)
  437.                     dat++;
  438.                 SCL=0;
  439.         }
  440. return (dat);
  441. }

  442. void Write1307(unsigned char add,unsigned char dat)
  443. {
  444.         unsigned char temp;
  445.         temp=dat/10;
  446.         temp<<=4;
  447.         temp=dat%10+temp;
  448.         I2C_start();
  449.         I2C_write_byte(0xd0);
  450.         I2C_write_byte(add);
  451.         I2C_write_byte(temp);
  452.         I2C_stop();

  453. }

  454. /***********************************************************************/
  455. unsigned char Read1307(unsigned char add)
  456. {
  457.         unsigned char temp,dat;
  458.         I2C_start();
  459.         I2C_write_byte(0xd0);          
  460.         I2C_write_byte(add);         
  461.         I2C_start();         
  462.         I2C_write_byte(0xd1);
  463.         dat=I2C_read_byte();         
  464.         I2C_send_noack();
  465.         I2C_stop();

  466.         temp=dat/16;
  467.         dat=dat%16;
  468.         dat=dat+temp*10;
  469.         return (dat);
  470. }

  471. uint get_AD(uchar channel)         // AD转换程序
  472. {
  473.     ADC_DATA=0;
  474.     channel&=0x07;                //0000,0111 清0高5位
  475.         delay2(1);  
  476.     ADC_CONTR=0xE0;               //1110,0000 清 ADC_FLAG, ADC_START 位和低 3 位
  477.     ADC_CONTR|=channel;           //选择 A/D 当前通道
  478.     delay2(1);                      //使输入电压达到稳定
  479.     ADC_CONTR|=0x08;              //0000,1000 令 ADCS = 1, 启动A/D转换,  
  480.     while (1)                       //等待A/D转换结束
  481.     {
  482.          if (ADC_CONTR&0x10)       //0001,0000 测试A/D转换结束否
  483.             break;
  484.     }
  485.     ADC_CONTR &= 0xE7;              //1111,0111 清 ADC_FLAG 位, 关闭A/D转换,  
  486.     return (ADC_DATA<<2|ADC_LOW2); //返回 A/D 10 位转换结果

  487. }

  488. void key_scan()
  489. {
  490.   bit flg;
  491.           if(flg1==1)
  492.           {
  493.                 if(s1num==0)
  494.                 {
  495.                   if(s1==0)
  496.                   {
  497.                           delay2(10);
  498.                            if(s1==0)
  499.                          {
  500.                          s1num++;
  501.                          while(!s1);
  502.                          }                 
  503.                   }
  504.                 }
  505.      }
  506. /*************************************************/
  507.           if(s1num==1)
  508.            {   
  509.                      fen=Read1307(0x01);
  510.                      LcmPutChar2(15,4,2);
  511.                   LcmPutChar2(32,4,3);
  512.                   LcmPutChar(68,4,fen/10);
  513.                   LcmPutChar(78,4,fen%10);
  514.                   if(s1==0)
  515.                   {
  516.                           delay2(10);
  517.                         if(s1==0)
  518.                         {
  519.                                 m1=0;
  520.                           while(!s1)
  521.                           {
  522.                                    if(m1>=20)
  523.                                          {
  524.                                                  flg=1;
  525.                                                  while(!s1)
  526.                                                 {
  527.                                                    fen++;
  528.                                                    if(fen==60)
  529.                                                            fen=0;
  530.                                                LcmPutChar(68,4,fen/10);
  531.                                            LcmPutChar(78,4,fen%10);
  532.                                                    delay2(900);
  533.                                                 }
  534.                                          }
  535.                                 }       
  536.                           if(flg==0)
  537.                                         s1num++;
  538.                           }
  539.                    }
  540.                   if (flg==1)
  541.                   {
  542.                          flg=0;
  543.                     Write1307(0x00,0);//写入秒
  544.                         Write1307(0x01,fen);//写入分
  545.                   }                                       
  546.                 }
  547. /*****************************************/
  548.            if(s1num==2)
  549.            {
  550.                      shi=Read1307(0x02);       
  551.                      LcmPutChar2(15,4,2);
  552.                   LcmPutChar2(32,4,2);
  553.                     LcmPutChar(68,4,shi/10);
  554.                   LcmPutChar(78,4,shi%10);
  555.                   if(s1==0)
  556.                   {
  557.                           delay2(10);
  558.                         if(s1==0)
  559.                         {
  560.                                 m1=0;
  561.                           while(!s1)
  562.                           {
  563.                                    if(m1>=20)
  564.                                          {
  565.                                                  flg=1;
  566.                                                  while(!s1)
  567.                                                 {
  568.                                                    shi++;
  569.                                                    if(shi==24)
  570.                                                         shi=0;
  571.                                                LcmPutChar(68,4,shi/10);
  572.                                            LcmPutChar(78,4,shi%10);
  573.                                                       delay2(900);       
  574.                                                 }
  575.                                          }
  576.                                 }       
  577.                           if(flg==0)
  578.                                  s1num++;
  579.                           }
  580.                    }
  581.                   if (flg==1)
  582.                   {
  583.                           flg=0;
  584.                         Write1307(0x00,0);//写入秒
  585.                         Write1307(0x02,shi);//写入时
  586.                    }                                       
  587.                 }
  588. /**********************************************/
  589.                 if(s1num==3)
  590.                    {
  591.                           a3=Read1307(0x08);
  592.                           b3=Read1307(0x09);
  593.                           c3=Read1307(0x0a);
  594.                              LcmPutChar2(15,4,4);
  595.                           LcmPutChar2(32,4,5);
  596.                           LcmPutChar(68,4,a3);
  597.                           LcmPutChar(78,4,b3);
  598.                           LcmPutChar(88,4,c3);
  599.                           js1=(a3*100)+(b3*10)+c3;
  600.                           if(s1==0)
  601.                       {
  602.                                   delay2(10);
  603.                                 if(s1==0)
  604.                                 {
  605.                                         m1=0;
  606.                                   while(!s1)
  607.                                   {
  608.                                            if(m1>=20)
  609.                                                  {
  610.                                                          flg=1;
  611.                                                          while(!s1)
  612.                                                         {
  613.                                                            js1++;
  614.                                                                 if(js1==151)
  615.                                                             js1=100;
  616.                                                        LcmPutChar(68,4,js1/100);
  617.                                                    LcmPutChar(78,4,js1%100/10);
  618.                                                            LcmPutChar(88,4,js1%10);
  619.                                                               delay2(900);
  620.                                                         }
  621.                                                  }
  622.                                         }       
  623.                                   if(flg==0)
  624.                                                 s1num++;
  625.                               }
  626.                        }
  627.                           if (flg==1)
  628.                           {
  629.                                   flg=0;
  630.                                 Write1307(0x08,js1/100);
  631.                             Write1307(0x09,js1%100/10);
  632.                                 Write1307(0x0a,js1%10);       
  633.                            }                                       
  634.                         }
  635. /*********************************************/
  636.                 if(s1num==4)
  637.                    {
  638.                           f2=Read1307(0x19);
  639.                           g2=Read1307(0x1a);
  640.                              LcmPutChar2(15,4,6);
  641.                           LcmPutChar2(32,4,7);
  642.                           LcmPutChar(88,4,10);
  643.                           LcmPutChar(68,4,f2);
  644.                           LcmPutChar(78,4,g2);
  645.                           mc1=(f2*10)+g2;
  646.                           if(s1==0)
  647.                           {
  648.                                   delay2(10);
  649.                                 if(s1==0)
  650.                                 {
  651.                                    m1=0;
  652.                                   while(!s1)
  653.                                   {
  654.                                            if(m1>=20)
  655.                                                  {
  656.                                                          flg=1;
  657.                                                          while(!s1)
  658.                                                         {
  659.                                                            mc1++;
  660.                                                            if(mc1==41)
  661.                                                                mc1=15;
  662.                                                        LcmPutChar(68,4,mc1/10);
  663.                                                            LcmPutChar(78,4,mc1%10);
  664.                                                               delay2(900);
  665.                                                         }
  666.                                                  }
  667.                                         }       
  668.                                   if(flg==0)
  669.                                                 s1num++;
  670.                                   }
  671.                            }
  672.                           if (flg==1)
  673.                           {
  674.                                   flg=0;
  675.                                 Write1307(0x19,mc1/10);
  676.                                 Write1307(0x1a,mc1%10);       
  677.                            }
  678.                          }
  679. /*****************************************/
  680.                  if(s1num==5)
  681.                    {
  682.                              LcmPutChar2(15,4,8);
  683.                           LcmPutChar2(32,4,9);
  684.                           LcmPutChar(68,4,10);
  685.                           LcmPutChar(78,4,10);
  686.                            if(s1==0)
  687.                       {
  688.                                   delay2(10);
  689.                                 if(s1==0)
  690.                                 {
  691.                                         m1=0;
  692.                                   while(!s1)
  693.                                   {
  694.                                            if(m1>=20)
  695.                                                  {
  696.                                                          flg=1;
  697.                                                     Write1307(0x00,0);//写入秒
  698.                                                         Write1307(0x01,0);//写入分
  699.                                                         Write1307(0x02,0);//写入时
  700.                                                         Write1307(0x03,0);//写入星期
  701.                                                         Write1307(0x04,0);//写入日期
  702.                                                         Write1307(0x05,0);//写入月
  703.                                                         Write1307(0x06,0);//写入年
  704.                                                     Write1307(0x07,10);       
  705.                                                         /*************************/
  706.                                                         Write1307(0x14,0);
  707.                                                         Write1307(0x15,0);
  708.                                                     Write1307(0x16,0);
  709.                                                         Write1307(0x17,0);
  710.                                                         /*************************/
  711.                                                         Write1307(0x0c,1);
  712.                                                         Write1307(0x0d,2);
  713.                                                     Write1307(0x0e,0);
  714.                                                         Write1307(0x0f,0);               
  715.                                                         Write1307(0x10,0);
  716.                                                         Write1307(0x11,0);
  717.                                                         /*************************/
  718.                                                         Write1307(0x08,1);
  719.                                                     Write1307(0x09,3);
  720.                                                         Write1307(0x0a,0);         
  721.                                                         /*************************/
  722.                                                     Write1307(0x19,2);
  723.                                                         Write1307(0x1a,8);

  724.                                                         LcmPutChar(68,4,11);
  725.                                             LcmPutChar(78,4,12);
  726.                                                         while(!s1);
  727.                                                  }
  728.                                         }       
  729.                                   if(flg==0)
  730.                                                 s1num++;
  731.                               }
  732.                        }
  733.                            flg=0;         
  734.                    }
  735. /***************************************/
  736.              if(s1num==6)
  737.                    {
  738.                              LcmPutChar2(15,4,12);
  739.                           LcmPutChar2(32,4,13);
  740.                           LcmPutChar(68,4,10);
  741.                           LcmPutChar(78,4,10);
  742.                          if(s1==0)
  743.                           {
  744.                                   delay2(10);
  745.                                 if(s1==0)
  746.                                 {
  747.                                         m1=0;
  748.                                   while(!s1)
  749.                                    {
  750.                                            if(m1>=20)
  751.                                                  {
  752.                                                           flg=1;
  753.                                                          flag4=0;
  754.                                                             LcmPutChar(68,4,11);
  755.                                              LcmPutChar(78,4,12);
  756.                                                          while(!s1);
  757.                                                  }
  758.                                         }       
  759.                                   if(flg==0)
  760.                                      {
  761.                                            s1num=0;
  762.                                            flg1=0;
  763.                                           // LcmPutChar2(15,4,16);
  764.                                   // LcmPutChar2(32,4,16);
  765.                                           }
  766.                                   }
  767.                            }
  768.                    }                                  
  769. }

  770. void key1_scan()
  771. {
  772.         if(s1==0)
  773.         {
  774.            delay2(10);
  775.                 if(s1==0)
  776.                  {
  777.                         flag4=1;
  778.                         LcmPutChar2(40,1,0);
  779.                         LcmPutChar2(70,1,1);
  780.                         LcmPutChar2(15,4,14);
  781.                         LcmPutChar2(32,4,15);
  782.                         while(!s1);
  783.                   }
  784.          }
  785.          while(flag4!=0)
  786.            {
  787.                   if(flg1==0)
  788.                         {
  789.                              LcmPutChar2(15,4,14);
  790.                           LcmPutChar2(32,4,15);
  791.                           if(s1==0)
  792.                           {
  793.                                   delay2(10);
  794.                                 if(s1==0)
  795.                                 {
  796.                                         m1=0;
  797.                                   while(!s1)
  798.                                   {
  799.                                            if(m1>=20)
  800.                                                  {
  801.                                                          flg1=1;
  802.                                                          LcmPutChar(68,4,11);
  803.                                                     LcmPutChar(78,4,12);
  804.                                                         while(!s1);
  805.                                                  }
  806.                                         }       
  807.                                   if(flg1==0)
  808.                                    {
  809.                                             flg1=1;
  810.                                           s1num=6;
  811.                                    }
  812.                                   }
  813.                            }
  814.                         }
  815.                   key_scan();
  816.            }
  817. }

  818. void dc_clear()
  819. {
  820.         if(s1==0)
  821.         {
  822.                 delay2(20);
  823.                 if(s1==0)
  824.                 {
  825.                         m1=0;
  826.                    while(!s1)
  827.                    {
  828.                          if(m1>=20)
  829.                          {
  830.                                 dc1=0;
  831.                                 dj=0;
  832.                                 delay2(1);
  833.                                 Write1307(0x14,0);
  834.                                 delay2(1);
  835.                                 Write1307(0x15,0);
  836.                                 delay2(1);
  837.                             Write1307(0x16,0);
  838.                                 delay2(1);
  839.                                 Write1307(0x17,0);
  840.                                 delay2(1);
  841.                                 break;
  842.                          }
  843.                    }                   
  844.                 }
  845.         }
  846. }

  847. //////////////////////////////////////////////////////////////////////////

  848. void sys_init()
  849. {
  850.        
  851. //        P1M0=0x8f;
  852. //        P1M1=0x8f;
  853.         AUXR&=0xBF;
  854.     TMOD=0X15;//设T0,T1为计数
  855.         TL0=0xff;
  856.         TH0=0xff;
  857.         TH1=0x3c;
  858.         TL1=0xb0;
  859.         EA=1;
  860.         TR0=1;
  861.         TR1=1;

  862.         ET0=1;
  863.         ET1=1;
  864. }

  865. void lcd_init ()          //3初始化
  866.           {
  867.            res=0;           //1复位       
  868.            delay2(100);
  869.            res=1;
  870.            delay2(300);
  871.            write_com(0xe2);           //复位指令  E2H
  872.            delay2(100);
  873.            write_com(0x40);           // 显示起始行设置  40H-7FH
  874.            write_com(0xa0);    // 列驱动方向设置          A0H/A1H
  875.            write_com(0xc8);    // 行驱动输出顺序设置        C0H/C8H       
  876.            write_com(0xa6);    // 正/负向显示设置          A6H/A7H
  877.            write_com(0xa3);    // LCD偏压设置          A2H/A3H       
  878.            write_com(0x25);    // V0 电压电阻比率设置  20H~27H       
  879.            delay2(30);
  880.            write_com(0x81);    //  对比度设置  
  881.            write_com(0x05);    //  对比度数值  (00H-3FH)
  882.            write_com(0x2c);           // 电源控制器设置  升压电路启动
  883.            delay2(50);
  884.            write_com(0x2e);    //升压电路启动  电压调节器启动
  885.            delay2(50);
  886.            write_com(0x2f);           //升压电路启动  电压调节器启动 电压跟随器启动
  887.            delay2(50);                              
  888.                 
  889.             write_com(0xf8);                   // 倍压电路设置  (00H/01H/03H)                  
  890.             write_com(0x00);           //  倍压级2X、3X、4X
  891.                 write_com(0xa4);           //  正常显示
  892.             write_com(0xaf);            //  打开显示开关
  893. }
  894.           
  895. void xshi_init()
  896. {
  897.         unsigned long b1,c1;
  898.         uint  d1,e1,b2,c2;
  899.     uchar f1,g1,d2,e2;
  900.         LcmPutChar(83,0,16);         //时钟标记
  901.         LcmPutChar(104,0,16);
  902. //        LcmPutChar(68,0,8);
  903. //        LcmPutChar(76,0,8);
  904. //        LcmPutChar(89,0,8);
  905. //        LcmPutChar(97,0,8);
  906. //        LcmPutChar(110,0,8);
  907. //        LcmPutChar(118,0,8);
  908.         ////////////////////////////////////////
  909.         LcmPutChar3(8,3,0);                  //电池标记
  910.         LcmPutChar(19,0,18);
  911. //        LcmPutChar(2,0,2);
  912. //        LcmPutChar(10,0,2);
  913. //        LcmPutChar(23,0,9);
  914.         LcmPutChar(35,0,17);                  
  915.     ///////////////////////////////////////////
  916.         LcmPutChar(94,4,12);         //速度标记
  917.         LcmPutChar(102,4,13);
  918.         LcmPutChar(110,4,14);
  919.         LcmPutChar(118,4,15);
  920.         LcmPutChar(75,4,18);
  921. //        LcmPutChar1(40,2,8);         //改
  922. //        LcmPutChar1(58,2,8);         //改
  923. //        LcmPutChar4(78,3,8);
  924.     ////////////////////////////////////////////////////
  925.         LcmPutChar(107,6,18);
  926.         LcmPutChar2(75,6,10);                 //单程标记
  927. //        LcmPutChar(90,6,0);
  928. //        LcmPutChar(98,6,0);
  929. //        LcmPutChar(111,6,0);
  930. //        LcmPutChar(119,6,0);
  931. //////////////////////////////////////////////////////
  932.         LcmPutChar(49,6,18);
  933. //        LcmPutChar(16,6,0);
  934. //        LcmPutChar(24,6,0);                 //总程标记
  935. //        LcmPutChar(32,6,0);
  936. //        LcmPutChar(40,6,0);
  937.         LcmPutChar2(0,6,11);

  938. //        LcmPutChar(53,6,0);
  939. //        LcmPutChar(61,6,0);

  940.         a3=Read1307(0x08);
  941.         b3=Read1307(0x09);
  942.         c3=Read1307(0x0a);

  943.         b1=Read1307(0x0c);
  944.         c1=Read1307(0x0d);
  945.     d1=Read1307(0x0e);
  946.     e1=Read1307(0x0f);
  947.     f1=Read1307(0x10);
  948.         g1=Read1307(0x11);

  949.         b2=Read1307(0x14);
  950.         c2=Read1307(0x15);
  951.         d2=Read1307(0x16);
  952.         e2=Read1307(0x17);

  953.         f2=Read1307(0x19);
  954.         g2=Read1307(0x1a);

  955.         zc1=(b1*100000)+(c1*10000)+(d1*1000)+(e1*100)+(f1*10)+g1;
  956.         dc1=(b2*1000)+(c2*100)+(d2*10)+e2;
  957.         js1=(a3*100)+(b3*10)+c3;
  958.         mc1=(f2*10)+g2;
  959. }         

  960. void display1307()
  961. {
  962.           mia=Read1307(0x00);
  963.     fen=Read1307(0x01);
  964.     shi=Read1307(0x02);
  965.         if(shi/10)
  966.         LcmPutChar(68,0,shi/10);
  967.         else
  968.         LcmPutChar(68,0,10);
  969.         LcmPutChar(76,0,shi%10);
  970.         LcmPutChar(89,0,fen/10);
  971.         LcmPutChar(97,0,fen%10);
  972.         LcmPutChar(110,0,mia/10);
  973.         LcmPutChar(118,0,mia%10);
  974. }

  975. void display_LC()
  976. {       
  977.    unsigned long zc ;       
  978.    uchar b,c,d,e,f,g,b4,c4,d4,e4;
  979.    uint dc;
  980. /**************************/
  981.     if(zc>=1000000)
  982.               zc=0;
  983.         if(dc>=10000)
  984.          dc=0;
  985.         zc=zc1+(zj*(js1*0.001));       
  986.         b=zc/100000;
  987.         c=zc%100000/10000;
  988.         d=zc%10000/1000;
  989.         e=zc%1000/100;
  990.         f=zc%100/10;
  991.         g=zc%10;

  992. /***********************/
  993.    
  994.         dc=dc1+(dj*(js1*0.001));
  995.         b4=dc%10000/1000;
  996.         c4=dc%1000/100;
  997.         d4=dc%100/10;
  998.         e4=dc%10;

  999.      if((m1>=20)&&(n>=5))
  1000.           {       
  1001.                 m1=0;
  1002.                 Write1307(0x0c,0);
  1003.                 delay2(1);
  1004.                 Write1307(0x0d,0);
  1005.                 delay2(1);
  1006.             Write1307(0x0e,0);
  1007.                  delay2(1);
  1008.                 Write1307(0x0f,0);
  1009.                  delay2(1);               
  1010.                 Write1307(0x10,0);
  1011.                  delay2(1);
  1012.                 Write1307(0x11,0);
  1013.                  delay2(1);       

  1014.                 Write1307(0x0c,b);
  1015.                 delay2(1);
  1016.                 Write1307(0x0d,c);
  1017.                 delay2(1);
  1018.             Write1307(0x0e,d);
  1019.                  delay2(1);
  1020.                 Write1307(0x0f,e);
  1021.                  delay2(1);               
  1022.                 Write1307(0x10,f);
  1023.                  delay2(1);
  1024.                 Write1307(0x11,g);
  1025.                  delay2(1);       

  1026.                 Write1307(0x14,0);
  1027.                 delay2(1);
  1028.                 Write1307(0x15,0);
  1029.                 delay2(1);
  1030.             Write1307(0x16,0);
  1031.                  delay2(1);
  1032.                 Write1307(0x17,0);
  1033.                  delay2(1);               
  1034.                 Write1307(0x14,b4);
  1035.                 delay2(1);
  1036.                 Write1307(0x15,c4);
  1037.                 delay2(1);
  1038.             Write1307(0x16,d4);
  1039.                  delay2(1);
  1040.                 Write1307(0x17,e4);
  1041.                  delay2(1);               
  1042.       }

  1043.         if(b!=0)
  1044.         {
  1045.                   LcmPutChar(16,6,b);
  1046.                 LcmPutChar(24,6,c);
  1047.                 LcmPutChar(32,6,d);
  1048.                 LcmPutChar(40,6,e);
  1049.                 LcmPutChar(53,6,f);
  1050.                 LcmPutChar(61,6,g);
  1051.         }
  1052.         else
  1053.           {
  1054.            LcmPutChar(16,6,10);
  1055.           
  1056.                 if(c!=0)
  1057.                 {
  1058.                     LcmPutChar(24,6,c);
  1059.                         LcmPutChar(32,6,d);
  1060.                         LcmPutChar(40,6,e);
  1061.                         LcmPutChar(53,6,f);
  1062.                         LcmPutChar(61,6,g);
  1063.                 }
  1064.                 else
  1065.                 {
  1066.                         LcmPutChar(24,6,10);
  1067.                
  1068.                         if(d!=0)
  1069.                         {
  1070.                           LcmPutChar(32,6,d);
  1071.                           LcmPutChar(40,6,e);
  1072.                           LcmPutChar(53,6,f);
  1073.                           LcmPutChar(61,6,g);
  1074.                         }
  1075.                         else
  1076.                                 LcmPutChar(32,6,10);
  1077.                                 LcmPutChar(40,6,e);
  1078.                                 LcmPutChar(53,6,f);
  1079.                                 LcmPutChar(61,6,g);
  1080.                   }
  1081.          }
  1082.         if(b4!=0)
  1083.         LcmPutChar(90,6,b4);
  1084.         else
  1085.         LcmPutChar(90,6,10);
  1086.         LcmPutChar(98,6,c4);
  1087.         LcmPutChar(111,6,d4);
  1088.         LcmPutChar(119,6,e4);
  1089. }

  1090.   void display_shudu()
  1091. {
  1092.         float m;
  1093.                    if(flag==1)
  1094.                 {
  1095.                     flag=0;       
  1096.                 //        m=((js1*1.0)/mc1)*mc2*3.6/10;
  1097.                         m=((js1*1.0)/mc1)*mc2*7.2/10;
  1098.                         sz[s]=m;
  1099.                         count=0;
  1100.                         mc2=0;
  1101.                         s++;
  1102.                 }
  1103.                 if(s>=3)
  1104.                 {
  1105.                         s=0;
  1106.                         m=sz[0]+sz[1]+sz[2];
  1107.                         m=m/3;
  1108.                          n=(int)m;
  1109.                         sz[0]=0;
  1110.                         sz[1]=0;
  1111.                         sz[2]=0;
  1112.                     if(n/100)
  1113.                         LcmPutChar1(40,2,n%1000/100);
  1114.                         else
  1115.                         LcmPutChar1(40,2,10);
  1116.                     LcmPutChar1(58,2,n%100/10);
  1117.                     LcmPutChar4(78,3,n%10);
  1118.                     if(n>=5)
  1119.                             flag2=1;
  1120.                         if(n<=5)
  1121.                                 flag2=0;
  1122.                         if(flag2==0)
  1123.                                 m=0;
  1124.                  }
  1125. }

  1126. void display_DY()
  1127. {
  1128.         DY=get_AD(7);
  1129.         if(dyshu>=40)
  1130.         {
  1131.                 dyshu=0;
  1132.                 LcmPutChar(2,0,DY/100);
  1133.                 LcmPutChar(10,0,DY%100/10);
  1134.                 LcmPutChar(23,0,DY%10);
  1135.         }
  1136.          dc_clear();
  1137. }         

  1138. void main()
  1139.      {         
  1140.              
  1141.                   lcd_init();
  1142.                  delay2(200);
  1143.              LcmClear();
  1144.                  sys_init();
  1145.                  key1_scan();
  1146.                  LcmClear();
  1147.                  xshi_init();
  1148.              while(1)
  1149.              {                
  1150.                         display1307();
  1151.                         display_LC();
  1152.                         display_shudu();
  1153.                     display_DY();         
  1154.                    }
  1155.           }
  1156.                
  1157. void T0_time()interrupt 1//总程中断计数
  1158. {
  1159.     uchar mc;
  1160.         TH0=0xff;
  1161.         TL0=0xff;
  1162.            mc++;
  1163.            mc2++;
  1164.         if(mc>=mc1)
  1165.         {       
  1166.                 mc=0;
  1167.             zj++;
  1168.             dj++;
  1169.     }
  1170. }

  1171. void timer0() interrupt 3
  1172. {
  1173.         TH1=0x3c;
  1174.         TL1=0xb0;
  1175.         count++;
  1176.         if(count==10)
  1177.            flag=1;
  1178.     m1++;
  1179.         dyshu++;                               
  1180. }
复制代码
回复

使用道具 举报

ID:86421 发表于 2015-7-21 22:57 | 显示全部楼层
这么多行代码,很累的呀.学习了
回复

使用道具 举报

ID:34763 发表于 2015-7-30 15:18 | 显示全部楼层
有成品没有?
回复

使用道具 举报

ID:87991 发表于 2015-8-9 18:32 | 显示全部楼层
单片机由谁供电?
回复

使用道具 举报

ID:88378 发表于 2015-8-15 15:07 | 显示全部楼层
太人材了!大赞是必须的!
回复

使用道具 举报

ID:87193 发表于 2015-9-9 10:34 | 显示全部楼层
代码这么多,楼主自己写的吗,真厉害,学习了
回复

使用道具 举报

ID:61140 发表于 2015-10-13 06:10 | 显示全部楼层
太牛了,服了
回复

使用道具 举报

ID:36525 发表于 2015-10-13 23:05 | 显示全部楼层
高手、、、、、、、
回复

使用道具 举报

ID:86796 发表于 2015-11-19 21:43 | 显示全部楼层
这个不错,建议应该去申请个实用新型,然后放到淘宝上,哈哈
回复

使用道具 举报

ID:97969 发表于 2015-12-2 10:15 | 显示全部楼层
也想做个,特来看看
回复

使用道具 举报

ID:97969 发表于 2015-12-2 10:18 | 显示全部楼层
来看看,顶下帖
回复

使用道具 举报

ID:96682 发表于 2015-12-3 10:35 | 显示全部楼层
费了超多币,一口气一网打尽总算把 LZ 的倾情奉献收入囊中了。
回复

使用道具 举报

ID:97969 发表于 2015-12-4 19:26 | 显示全部楼层
特来看看,想做个呢,谢谢分享
回复

使用道具 举报

ID:98452 发表于 2015-12-5 16:07 | 显示全部楼层
不错,哪天我也来弄一个,还在学习中。
回复

使用道具 举报

ID:99987 发表于 2015-12-26 12:03 | 显示全部楼层
真牛,很不错!
回复

使用道具 举报

ID:111454 发表于 2016-3-30 17:24 | 显示全部楼层
大神啊!最近我也在做这个电动车里程表,想把指针式换成液晶式的,一筹莫展。是直接测控制器出来的信号在控制吗?
回复

使用道具 举报

ID:52135 发表于 2016-4-16 21:49 来自手机 | 显示全部楼层
时代光环
回复

使用道具 举报

ID:148088 发表于 2016-11-15 17:53 | 显示全部楼层
楼主历害,我也想DIY一个电动车仪表
回复

使用道具 举报

ID:84250 发表于 2017-1-4 12:24 | 显示全部楼层
楼主还行哈没写了1000行代码,不过没看到电量显示,最好能转换成续航里程就好了
回复

使用道具 举报

ID:154108 发表于 2017-1-4 22:40 | 显示全部楼层
超级人才~~
回复

使用道具 举报

ID:172773 发表于 2017-3-19 15:40 | 显示全部楼层
下载不了啊
回复

使用道具 举报

ID:166914 发表于 2017-3-19 20:13 | 显示全部楼层
楼主真是厉害
回复

使用道具 举报

ID:161831 发表于 2017-3-21 07:38 | 显示全部楼层
楼主牛人啊!
回复

使用道具 举报

ID:172773 发表于 2017-3-26 13:47 | 显示全部楼层
差点滴积分
回复

使用道具 举报

ID:221702 发表于 2017-7-23 03:39 | 显示全部楼层
感谢分享,有用啊
回复

使用道具 举报

ID:202586 发表于 2017-8-11 14:49 | 显示全部楼层
太厉害了  佩服佩服
回复

使用道具 举报

ID:134692 发表于 2017-8-23 12:05 | 显示全部楼层
楼主牛人啊
回复

使用道具 举报

ID:217335 发表于 2017-8-23 13:17 | 显示全部楼层
厉害了我的哥~~~~~~
回复

使用道具 举报

ID:229427 发表于 2017-8-26 11:08 | 显示全部楼层
人才
回复

使用道具 举报

ID:202586 发表于 2018-4-24 17:31 | 显示全部楼层
谢谢 楼主分享   先学习下谢谢
回复

使用道具 举报

ID:398800 发表于 2018-9-16 21:57 | 显示全部楼层
打算搞 学习下
回复

使用道具 举报

ID:428030 发表于 2018-11-21 11:24 | 显示全部楼层
我也一直想把我的电动车里程表改了呢,原装的里程不准。
回复

使用道具 举报

ID:428030 发表于 2018-11-21 11:26 | 显示全部楼层
楼主能不能留个Q或者其他联系方式啊?
回复

使用道具 举报

ID:395259 发表于 2018-11-21 11:55 | 显示全部楼层
太好了,好东西
回复

使用道具 举报

ID:65956 发表于 2018-11-27 08:41 | 显示全部楼层
强人,不错,说干就干,顶上
回复

使用道具 举报

ID:486881 发表于 2019-3-8 14:42 | 显示全部楼层
第一眼看到就决定要弄一弄了,楼主有没有联系方式,想请教一下
回复

使用道具 举报

ID:486881 发表于 2019-3-8 14:46 | 显示全部楼层
楼主是用霍尔模块检测车轮的转数吗?
回复

使用道具 举报

ID:419910 发表于 2019-7-1 17:38 来自手机 | 显示全部楼层
续航里程准么?
回复

使用道具 举报

ID:474595 发表于 2021-12-12 10:18 | 显示全部楼层
楼主真是太牛了
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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