一乐电子

一乐电子百科

 找回密码
 请使用微信账号登录和注册会员

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 5450|回复: 12
收起左侧

[其他综合] 分享智能充电器原理图及程序(来自互联网)

[复制链接]
发表于 2013-4-9 16:07 | 显示全部楼层 |阅读模式
本帖最后由 SengChuary 于 2013-4-9 18:47 编辑

SCH1.jpg

SCH2.jpg
主程序:
  1. #include <reg52.h>

  2. #include <lcd12864.h>//lcd12864相关控制

  3. #include <DS18B20.h>

  4. #include <math.h>



  5. sbit CTRL_UP=P2^0;

  6. sbit CTRL_DOWN=P2^1;



  7. sbit ADCOE=P2^6;

  8. sbit ADCSTART=P2^7;

  9. sbit ADCALE=P2^5;

  10. sbit ADCA=P2^4;

  11. sbit ADCB=P2^3;

  12. sbit POWERKK=P1^4;

  13. #define ADCDATE P0



  14. sbit KEY1=P3^7;

  15. sbit KEY2=P3^5;

  16. sbit KEY3=P3^6;



  17. void InitSys();//初始化系统

  18. void InitInt();//初始化外部中断

  19. void InitTimer();//初始化定时器,串口中断

  20. void SendSerialData();//启动并发送一组串口数据

  21. void StartADC();//选择通道n,开始转换

  22. void ShowAllTime();//显示完整的时间



  23. unsigned char g_myPar[15],g_CurSend;

  24. //g_t10,g_t11,g_t20,g_t21,g_t30,g_t31,g_n,g_U0,g_U1p,g_U1f,g_U2,g_U3,g_Th,g_Tm,g_Ts;参数顺序

  25. bit bSerialSending;

  26. unsigned char g_time[6];

  27. unsigned char g_CurIn;

  28. unsigned char code g_adda[]={0,1,1,0,1};

  29. unsigned char code g_addb[]={1,0,0,0,1};

  30. unsigned char code g_ctrlu[]={1,1,1,0,0};

  31. unsigned char code g_ctrld[]={0,1,0,1,1};

  32. unsigned char g_tt10,g_tt11,g_tt20,g_tt21,g_tt30,g_tt31;

  33. unsigned char CutState;

  34. bit CurTR0,Curctrlu,Curctrld;

  35. float SqrtDuty;

  36. unsigned char g_Percent;



  37. void main()

  38. {

  39. //DelayMs(10);

  40. //Delay4us(10);

  41. InitSys();

  42. DelayMs(1200);

  43. InitLCD();

  44. InitLCDshow(0);

  45. InitInt();//初始化外部中断0

  46. InitTimer();//初始化定时器0,串口中断

  47. bSerialSending = 0;

  48. //     bLinking = 0;



  49. //WriteLCD(0,0x80);

  50. //DspNumber(123);

  51. StartADC();

  52. while(1)

  53. {

  54. if(KEY1==0)//充电



  55. {

  56. TR1 = 0;

  57. CutState = 0;

  58. POWERKK = 1;

  59. InitLCDshow(0);

  60. TR0 = 1;

  61. g_myPar[0]=g_tt10;

  62. g_myPar[1]=g_tt11;

  63. g_myPar[2]=g_tt20;

  64. g_myPar[3]=g_tt21;

  65. g_myPar[4]=g_tt10;

  66. g_myPar[5]=g_tt11;

  67. //SqrtDuty = sqrt((float)g_myPar[1]/(g_myPar[0]+g_myPar[1]));

  68. //Duty=g_myPar[0]*100/(g_myPar[0]+g_myPar[1]);

  69. TR1 = 1;

  70. StartADC();

  71. ShowAllTime();

  72. DelayMs(100);

  73. }

  74. else if(KEY2==0)//放电

  75. {

  76. TR1 = 0;

  77. CutState = 1;

  78. POWERKK = 1;

  79. InitLCDshow(1);

  80. TR0 = 0;

  81. g_CurIn = 0;

  82. CTRL_UP = 1;

  83. CTRL_DOWN = 0;

  84. TR1 = 1;

  85. StartADC();

  86. ShowAllTime();

  87. DelayMs(100);

  88. }

  89. else if(KEY3==0)//维护

  90. {

  91. TR1 = 0;

  92. POWERKK = 0;

  93. CutState = 2;

  94. InitLCDshow(2);

  95. TR0 = 1;

  96. g_myPar[0]=0xff;

  97. g_myPar[1]=0xf0;

  98. g_myPar[2]=0xfe;

  99. g_myPar[3]=0x74;

  100. g_myPar[4]=0xff;

  101. g_myPar[5]=0xf2;

  102. //SqrtDuty = sqrt((float)g_myPar[1]/(g_myPar[0]+g_myPar[1]));

  103. //Duty=g_myPar[0]*100/(g_myPar[0]+g_myPar[1]);

  104. TR1 = 1;

  105. StartADC();

  106. ShowAllTime();

  107. DelayMs(100);

  108. }

  109. }

  110. }



  111. //初始化系统

  112. void InitSys()

  113. {

  114. unsigned char i;



  115. for(i=0;i<6;i++)

  116. {



  117. g_time[i] =;

  118. }

  119. ADCOE = 1;

  120. ADCALE = 0;

  121. ADCSTART = 0;



  122. POWERKK = 1;

  123. g_myPar[0]=0xff;//0x30

  124. g_myPar[1]=0x30;

  125. g_myPar[2]=0xff;

  126. g_myPar[3]=0x30;//0x30

  127. g_myPar[4]=0xff;

  128. g_myPar[5]=0x30;

  129. g_tt10 = 0xff;

  130. g_tt11 = 0x30;

  131. g_tt20 = 0xff;

  132. g_tt21 = 0x30;

  133. /*g_myPar[0] = 0x80;//g_TH1

  134. g_myPar[1] = 0x00;//g_TH2

  135. g_myPar[2] = 0x00;//g_TH3*/

  136. g_myPar[6] = 6;

  137. SqrtDuty = sqrt(0.5);

  138. //Duty=g_myPar[0]*100/(g_myPar[0]+g_myPar[1]);

  139. }



  140. //初始化外部中断

  141. void InitInt()

  142. {

  143. IT0 = 1;// 0/1 低电平/下跳变

  144. PX0 = 1;// 中断优先级

  145. //EX0 = 1;

  146. //EA = 1;

  147. }





  148. //初始化定时器,串口中断

  149. void InitTimer()

  150. {

  151. TMOD = 0x11;// 使用高4位 0/1/2/3  13位/16位/8位自动重载/双8位



  152. TH0 = (65536 - 49235) / 256;

  153. TL0 = (65536 - 49235) % 256;

  154. PT0 = 1;

  155. TR0 = 1;//开启定时器0

  156. ET0 = 1;



  157. TH1 = (65536 - 49235) / 256;

  158. TL1 = (65536 - 49235) % 256;

  159. TR1 = 1;//开启定时器1

  160. ET1 = 1;



  161. TCLK=1;

  162. RCLK=1;



  163. TH2=0xFF;  //19200bps  22.1184MHz的时钟频率

  164. TL2=0xDC;

  165. RCAP2H=0xFF;  //方式1和方式3的波特率=fosc/(32-(65535-(RCAP2H,RCAP2L))

  166. RCAP2L=0xDC;



  167. TR2=1;

  168. //ET2=1;



  169. SCON = 0x50;//串口方式1,允许接收

  170. PCON = 0x00;//关闭波特率加倍



  171. PS = 1;//设置串口中断为高优先级

  172. ES = 1;//开串口中断

  173. //TH1 = 0xfd;//串口通信使用定时器1,设定波特率9600

  174. //TH1 = 0xf3;//串口通信使用定时器1,设定波特率2400



  175. EA = 1;

  176. }



  177. //开始发送串口数据

  178. void SendSerialData()

  179. {

  180. if(!bSerialSending)

  181. {

  182. bSerialSending = 1;

  183. g_CurSend = 0;

  184. SBUF = g_myPar[g_CurSend];

  185. g_CurSend++;

  186. }

  187. }



  188. //开始ADC转换

  189. void StartADC()

  190. {

  191. CurTR0 = TR0;

  192. TR0 = 0;

  193. g_CurIn=0;

  194. ADCA = g_adda[g_CurIn];

  195. ADCB = g_addb[g_CurIn];

  196. CTRL_UP = g_ctrlu[g_CurIn];

  197. CTRL_DOWN = g_ctrld[g_CurIn];

  198. Curctrlu = CTRL_UP;

  199. Curctrld = CTRL_DOWN;

  200. ADCALE = 1;

  201. ADCALE = 0;

  202. ADCSTART = 1;

  203. ADCSTART = 0;

  204. EX0 = 1;



  205. }



  206. //倒序转换

  207. unsigned char Reverse(unsigned char num)

  208. {

  209. unsigned char i,rtTmp;

  210. rtTmp = 0x00;

  211. for(i=0; i<8; i++)

  212. {

  213. rtTmp <<=1;

  214. rtTmp |= num & 0x01;

  215. num >>= 1;

  216. }

  217. return rtTmp;

  218. }



  219. //显示完整的时间

  220. void ShowAllTime()

  221. {

  222. WriteLCD(0,0x98+4);

  223. WriteLCD(1,g_time[0]);//时

  224. WriteLCD(1,g_time[1]);

  225. WriteLCD(1,:);

  226. WriteLCD(1,g_time[2]);//分

  227. WriteLCD(1,g_time[3]);

  228. WriteLCD(1,:);



  229. WriteLCD(1,g_time[4]);

  230. WriteLCD(1,g_time[5]);

  231. }



  232. //外部中断0服务程序

  233. void Int0() interrupt 0

  234. {

  235. g_myPar[7+g_CurIn] = ADCDATE;

  236. g_CurIn++;

  237. if(g_CurIn<5)

  238. {

  239. ADCA = g_adda[g_CurIn];

  240. ADCB = g_addb[g_CurIn];

  241. CTRL_UP = g_ctrlu[g_CurIn];

  242. CTRL_DOWN = g_ctrld[g_CurIn];

  243. ADCALE = 1;

  244. ADCALE = 0;

  245. ADCSTART = 1;

  246. ADCSTART = 0;

  247. }

  248. else

  249. {

  250. TR0 = CurTR0;

  251. EX0 = 0;

  252. CTRL_UP = Curctrlu;

  253. CTRL_DOWN = Curctrld;

  254. }

  255. }



  256. //定时器0中断服务程序

  257. void Timer0() interrupt 1

  258. {

  259. static unsigned char i;

  260. static bit j;

  261. if(j)

  262. {

  263. j = 0;

  264. i++;

  265. if(i>g_myPar[6])

  266. {

  267. i = 0;

  268. CTRL_UP = 1;

  269. CTRL_DOWN = 0;

  270. TH0 = g_myPar[4];

  271. TL0 = g_myPar[5];

  272. }

  273. else

  274. {

  275. CTRL_UP = 1;

  276. CTRL_DOWN = 1;

  277. TH0 = g_myPar[2];

  278. TL0 = g_myPar[3];

  279. }

  280. }

  281. else

  282. {

  283. j = 1;

  284. CTRL_UP = 0;

  285. CTRL_DOWN = 1;

  286. TH0 = g_myPar[0];

  287. TL0 = g_myPar[1];

  288. }

  289. }





  290. //定时器1中断服务程序

  291. void Timer1() interrupt 3

  292. {

  293. static unsigned char i,j;

  294. unsigned char temp_data[2];

  295. unsigned char presence,k;



  296. TH1 = (65536 - 60730) / 256;

  297. TL1 = (65536 - 60730) % 256;

  298. i++;

  299. if(i>24)//时间显示

  300. {

  301. i=0;

  302. g_time[5]++;

  303. g_myPar[14]++;

  304. if(g_time[5] > 0x39)//秒个位

  305. {

  306. g_time[5] = 0x30;

  307. g_time[4]++;

  308. if(g_time[4] > 0x35)//秒十位

  309. {

  310. g_time[4] = 0x30;

  311. g_time[3]++;

  312. g_myPar[14] = 0;

  313. g_myPar[13]++;

  314. if(g_time[3] > 0x39)//分个位

  315. {

  316. g_time[3] = 0x30;

  317. g_time[2]++;

  318. if(g_time[2] > 0x35)//分十位

  319. {

  320. g_time[2] = 0x30;

  321. g_time[1]++;

  322. g_myPar[13] = 0;

  323. g_myPar[12]++;

  324. if(g_time[1] > 0x33)//时个位

  325. {

  326. g_time[1] = 0x30;

  327. g_time[0]++;

  328. if(g_time[0] > 0x39)//时十位

  329. {

  330. g_time[0] = 0x30;

  331. g_myPar[12]=0;

  332. }//时十位

  333. }//时个位

  334. WriteLCD(0,0x98+4);

  335. WriteLCD(1,g_time[0]);

  336. WriteLCD(1,g_time[1]);

  337. }//分十位

  338. WriteLCD(0,0x98+5);

  339. WriteLCD(1,:);

  340. WriteLCD(1,g_time[2]);

  341. }//分个位

  342. WriteLCD(0,0x98+6);

  343. WriteLCD(1,g_time[3]);

  344. }//秒十位

  345. }//秒个位

  346. WriteLCD(0,0x98+7);

  347. WriteLCD(1,g_time[4]);

  348. WriteLCD(1,g_time[5]);



  349. //显示充/放电状态

  350. j++;

  351. switch(j)



  352. {

  353. case 1:

  354. WriteLCD(0,0x98+2);

  355. WriteLCD(1, );

  356. WriteLCD(1, );

  357. WriteLCD(1, );

  358. StartADC();

  359. break;

  360. case 2:

  361. WriteLCD(0,0x98+2);

  362. WriteLCD(1,.);

  363. break;

  364. case 3:

  365. WriteLCD(0,0x98+2);

  366. WriteLCD(1,.);

  367. WriteLCD(1,.);

  368. break;

  369. case 4:

  370. WriteLCD(0,0x98+3);

  371. WriteLCD(1,.);

  372. j = 0;

  373. break;

  374. default:

  375. j = 0;

  376. }



  377. presence = Init_DS18B20();

  378. if(presence==0)

  379. {

  380. WriteOneChar(0xCC); //跳过ROM匹配操作

  381. Delay4us(10);

  382. WriteOneChar(0x44); //启动温度转换

  383. }

  384. presence = Init_DS18B20();

  385. if(presence==0)

  386. {

  387. WriteOneChar(0xCC); //跳过ROM匹配操作

  388. Delay4us(10);

  389. WriteOneChar(0xBE); //读取温度寄存器

  390. Delay4us(10);

  391. temp_data[0] = ReadOneChar(); //温度低8位

  392. Delay4us(10);

  393. temp_data[1] = ReadOneChar(); //温度高8位

  394. if(presence==0)

  395. {

  396. if(temp_data[1]==0xff) presence=1;

  397. }

  398. }



  399. if(g_CurIn == 5)

  400. {

  401. for(k=0;k<5;k++)

  402. {

  403. g_myPar[7+k] = Reverse(g_myPar[7+k]);

  404. }



  405. g_Percent = g_myPar[7+2]*1.56-48;//(U1f-4.8)/10*100

  406. if(g_Percent>100) g_Percent = 0;

  407. if(CutState==0)//充电模式

  408. {

  409. g_tt10 = (65536-5*(105-g_Percent))/256;

  410. g_tt11 = (65536-5*(105-g_Percent))%256;

  411. g_tt20 = (65536-5*(5+g_Percent))/256;

  412. g_tt21 = (65536-5*(5+g_Percent))%256;



  413. g_myPar[0]=g_tt10;

  414. g_myPar[1]=g_tt11;

  415. g_myPar[2]=g_tt20;

  416. g_myPar[3]=g_tt21;

  417. g_myPar[4]=g_tt10;

  418. g_myPar[5]=g_tt11;

  419. }

  420. SqrtDuty = sqrt(1-g_Percent/100.0);

  421. //Duty=g_myPar[0]*100/(g_myPar[0]+g_myPar[1]);

  422. g_CurIn = 0;

  423. }



  424. if(CutState==2)//维护

  425. {

  426. WriteLCD(0,0x90);

  427. DspNumber(g_myPar[7+2]*156);//电池电压

  428. WriteLCD(1,V);

  429. //g_Percent = g_myPar[4+2]*1.56-48;

  430. DspPercent(g_Percent);

  431. if(presence==0)

  432. {

  433. WriteLCD(0,0x90+5);

  434. DspTemp(temp_data[1],temp_data[0]);

  435. }

  436. }

  437. else if(CutState==1)//放电

  438. {

  439. //显示参数g_U0,g_U1p,g_U1f,g_U2,g_U3,

  440. WriteLCD(0,0x90);

  441. DspNumber(g_myPar[7+2]*156);//电池电压

  442. WriteLCD(1,V);

  443. //g_Percent = g_myPar[4+2]*1.56-48;

  444. DspPercent(g_Percent);

  445. WriteLCD(0,0x88+4);

  446. WriteLCD(1,:);

  447. DspNumber((g_myPar[7+2]-g_myPar[7])*31);//放电电流

  448. if(presence==0)

  449. {

  450. WriteLCD(0,0x90+5);

  451. DspTemp(temp_data[1],temp_data[0]);

  452. }

  453. }

  454. else//充电

  455. {

  456. //显示参数g_U0,g_U1p,g_U1f,g_U2,g_U3,

  457. WriteLCD(0,0x80);

  458. DspNumber(g_myPar[7+2]*156);//电池电压

  459. WriteLCD(1,V);

  460. //g_Percent = g_myPar[4+2]*1.56-48;

  461. DspPercent(g_Percent);

  462. WriteLCD(0,0x90+4);

  463. WriteLCD(1,:);

  464. DspNumber(((g_myPar[7+4]-g_myPar[7+3])*78)*SqrtDuty);//充电电流

  465. WriteLCD(0,0x88+4);

  466. WriteLCD(1,:);

  467. DspNumber(g_myPar[7+4]*156*SqrtDuty);//充电电压

  468. if(presence==0)

  469. {

  470. WriteLCD(0,0x80+5);

  471. DspTemp(temp_data[1],temp_data[0]);

  472. }

  473. }

  474. }





  475. }



  476. //串口中断服务程序

  477. void Serial() interrupt 4

  478. {

  479. if(RI)

  480. {

  481. RI = 0;

  482. bSerialSending = 0;

  483. if(SBUF == 5)

  484. {

  485. SBUF = 6;



  486. }

  487. else if(SBUF == 6)

  488. {

  489. SendSerialData();

  490. }

  491. else

  492. {

  493. SBUF = 0xff;

  494. }

  495. }

  496. else

  497. {

  498. TI = 0;

  499. if(bSerialSending)

  500. {

  501. if(g_CurSend<15)

  502. {

  503. SBUF = g_myPar[g_CurSend];

  504. g_CurSend++;



  505. }

  506. else

  507. {

  508. bSerialSending = 0;

  509. }

  510. }

  511. }

  512. }
复制代码
18B20程序:
  1. #include <DS18B20.h>



  2. //unsigned char data temp_data[2];



  3. //DS18B20初始化

  4. unsigned char Init_DS18B20(void)

  5. {

  6. bit presence;

  7. DQ = 0; //单片机发出低电平复位信号

  8. Delay4us(120); //延时>480us

  9. DQ = 1; //释放数据线

  10. Delay4us(16); //延时>64us,等待应答





  11. presence = DQ; //接收应答信号

  12. Delay4us(100); //延时>400us,等待数据线出现高电平

  13. DQ = 1; //释放数据线



  14. return (presence); //返回presence信号

  15. }

  16. //读一个字节数据

  17. unsigned char ReadOneChar(void)

  18. {

  19. unsigned char i = 0;

  20. unsigned char dat = 0;



  21. DQ = 1;

  22. for (i = 0; i < 8; i++)

  23. //一个字节8个bit

  24. {

  25. DQ = 0; //给低脉冲信号

  26. dat >>= 1;

  27. DQ = 1; //释放总线

  28. _nop_();

  29. _nop_();

  30. if (DQ)

  31. //读总线电平状态

  32. dat |= 0x80;

  33. //最高位置1

  34. Delay4us(15); //延时>45us

  35. DQ = 1; //释放总线,表示此次读操作完成

  36. }



  37. return (dat); //返回所读得数据

  38. }



  39. //写一个字节数据

  40. void WriteOneChar(unsigned char dat)

  41. {

  42. unsigned char i = 0;

  43. for (i = 0; i < 8; i++)

  44. //一个字节8个bit

  45. {

  46. DQ = 0; //给低脉冲信号

  47. Delay4us(1); //延时<15us

  48. dat >>= 1; //数据右移一位,最低位移入CY

  49. DQ = CY; //写1bit数据

  50. Delay4us(15); //延时>45us

  51. DQ = 1; //释放总线,表示此次写操作完成

  52. }

  53. }

  54. /*//温度数据转换子程序

  55. void Temperature_conver()

  56. {

  57. unsigned char minus = 0;

  58. if (temp_data[1] > 127)

  59. //温度为负值

  60. {

  61. temp_data[0] = (~temp_data[0]) + 1; //取反加一,将补码变成原码

  62. if ((~temp_data[0]) >= 0xff)

  63. temp_data[1] = (~temp_data[1]) + 1;

  64. else

  65. temp_data[1] = ~temp_data[1];

  66. minus = 1; //温度为负值标志

  67. }



  68. }*/
复制代码
LCD12864程序:
  1. #include <lcd12864.h>//lcd12864相关控制



  2. unsigned char code date[3][64]={" 0.000V  0%  0.0"

  3. "充电电流: 0.000A"

  4. "充电电压: 0.000V"

  5. "充电... 00:00:00",

  6. "正在测试电池性能"

  7. " 0.000V  0%  0.0"

  8. "放电电流: 0.000A"

  9. "放电... 00:00:00",

  10. "正在维护电池    "

  11. " 0.000V  0%  0.0"

  12. "电池健康度   0% "

  13. "维护... 00:00:00"};

  14. //毫秒延时

  15. void Delay4us(unsigned char us)

  16. {

  17. while(us--);

  18. }



  19. //毫秒延时

  20. void DelayMs(unsigned int ms)

  21. {

  22. unsigned char i;

  23. while(ms--)

  24. {

  25. for(i=228; i>0; i--);

  26. }

  27. }



  28. //初始化LCD显示

  29. void InitLCDshow(unsigned char n)

  30. {

  31. unsigned char i;

  32. WriteLCD(0,0x80); for(i=0;i<16;i++)  WriteLCD(1,date[n][i]);

  33. WriteLCD(0,0x90); for(i=0;i<16;i++)  WriteLCD(1,date[n][i+16]);

  34. WriteLCD(0,0x88); for(i=0;i<16;i++)  WriteLCD(1,date[n][i+32]);

  35. WriteLCD(0,0x98); for(i=0;i<16;i++)  WriteLCD(1,date[n][i+48]);

  36. }



  37. //发送一个字节

  38. void SendByteLCD(unsigned char bbyte)

  39. {

  40. unsigned char i;

  41. for(i=0;i<8;i++)

  42. {

  43. SID=bbyte&0x80; //取出最高位

  44. SCLK=1;

  45. SCLK=0;

  46. bbyte<<=1; //左移

  47. }

  48. }



  49. //写指令或数据

  50. //#pragma disable

  51. void WriteLCD(unsigned char cmd, unsigned char num)//reentrant

  52. {

  53. if(cmd==0)

  54. {

  55. //start_num=0xf8;  //写指令

  56. SendByteLCD(0xf8);     //发送起始信号



  57. }

  58. else

  59. {

  60. //start_num=0xfa;  //写数据

  61. SendByteLCD(0xfa);     //发送起始信号

  62. }

  63. DelayMs(5);                        //延时是必须的

  64. SendByteLCD(num & 0xf0);        //发送高四位

  65. DelayMs(1);                        //延时是必须的

  66. SendByteLCD((num<<4) & 0xf0);              //发送低四位

  67. DelayMs(1);                        //延时是必须的

  68. }



  69. //显示一个数

  70. void DspNumber(unsigned int num)

  71. {

  72. unsigned char i,dsp[5];

  73. for(i=0;i<4;i++)

  74. {

  75. dsp[i] = num % 10;

  76. dsp[i] += 0x30;

  77. num /= 10;

  78. }

  79. if(num)

  80. {

  81. dsp[4] = num + 0x30;

  82. }

  83. else

  84. {

  85. dsp[4] = ;

  86. }

  87. WriteLCD(1,dsp[4]);

  88. WriteLCD(1,dsp[3]);

  89. WriteLCD(1,.);

  90. WriteLCD(1,dsp[2]);

  91. WriteLCD(1,dsp[1]);

  92. WriteLCD(1,dsp[0]);

  93. }





  94. void DspPercent(unsigned char per)

  95. {

  96. unsigned char i;

  97. i = per / 100;

  98. per %= 100;

  99. i += 0x30;

  100. if(i==)i= ;

  101. WriteLCD(1,i);

  102. i = per / 10;

  103. per %= 10;

  104. i += 0x30;

  105. if(i==)i= ;

  106. WriteLCD(1,i);

  107. per += 0x30;

  108. WriteLCD(1,per);

  109. }

  110. //显示温度

  111. void DspTemp(unsigned char num1,unsigned char num2)

  112. {

  113. unsigned char i;

  114. num1 = num1<<4 | num2>>4;

  115. num2 &= 0x0f;

  116. num2 /= 1.6;

  117. i = num1 / 100;



  118. num1 %= 100;

  119. WriteLCD(1, \%);

  120. if(i)

  121. {

  122. WriteLCD(1, i+0x30);

  123. i = num1 / 10;

  124. num1 %= 10;

  125. WriteLCD(1, i+0x30);

  126. WriteLCD(1, num1+0x30);

  127. }

  128. else

  129. {

  130. WriteLCD(1, );

  131. i = num1 / 10;

  132. num1 %= 10;

  133. if(i)

  134. {

  135. WriteLCD(1, i+0x30);

  136. }

  137. else

  138. {

  139. WriteLCD(1, );

  140. }

  141. WriteLCD(1, num1+0x30);

  142. }

  143. WriteLCD(1, .);

  144. WriteLCD(1, num2+0x30);

  145. /*    i = (num >> 4) + 0x30;

  146. if(i>9)i+=7;

  147. WriteLCD(1, i);

  148. i = (num & 0x0f) + 0x30;

  149. if(i>9)i+=7;

  150. WriteLCD(1,i);*/

  151. }



  152. //初始化LCD

  153. void InitLCD(void)

  154. {

  155. //PSB=0; ;     //串口驱动模式

  156. DelayMs(10); //启动等待,等LCM讲入工作状态



  157. RESET=0; DelayMs(1); RESET=1; // 复位LCD

  158. CS=1;

  159. WriteLCD(0,0x30);  //8 位介面,基本指令集

  160. WriteLCD(0,0x0c);  //显示打开,光标关,反白关

  161. WriteLCD(0,0x01);  //清屏,将DDRAM的地址计数器归零

  162. }
复制代码
发表于 2013-4-9 18:02 | 显示全部楼层
占位 慢慢看、、、
发表于 2013-4-9 20:16 | 显示全部楼层
好东西,下来学习学习
发表于 2013-4-10 07:56 | 显示全部楼层
像12V铅酸电池脉冲充电器,还带负脉冲放电!
发表于 2013-4-10 08:11 | 显示全部楼层
你这个是畜电池的,我这个是锂电池的,差远了!
发表于 2013-5-4 22:48 | 显示全部楼层
楼主这个程序能不能打个包啊。。复制有乱码
发表于 2013-5-5 08:22 | 显示全部楼层
程序是应该打个包。。。。。我手机上的看起来全是乱码。
发表于 2013-5-21 19:25 | 显示全部楼层
mark
发表于 2013-6-15 11:40 | 显示全部楼层
非常感谢楼主的分享!
发表于 2013-6-18 14:24 | 显示全部楼层
屌一乐 既然共享还不与人方便。什么玩意!

本版积分规则

QQ|一淘宝店|手机版|商店|电子DIY套件|一乐电子 ( 粤ICP备09076165号 ) 公安备案粤公网安备 44522102000183号

GMT+8, 2024-4-28 01:06 , Processed in 0.052812 second(s), 37 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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