amobbs.com 阿莫电子技术论坛

标题: 老陈VFD 显示程序(串口发送) [打印本页]

作者: doujiang    时间: 2013-8-9 21:42
标题: 老陈VFD 显示程序(串口发送)
本帖最后由 doujiang 于 2013-8-9 21:49 编辑

自己写的老陈VFD显示程序,串口波特率115200

头文件
  1. #ifndef _drv_vfd128x64_h_
  2. #define _drv_vfd128x64_h_

  3. #include <string.h>
  4. #include "common.h"//包含延时函数头文件
  5. #include "drv_usart1.h"

  6. #define bigfont 0x11//字体控制命令宏定义
  7. #define smallfont 0x10

  8. extern void Vfd128x64_Clear_All();//清屏
  9. extern void Vfd128x64_Show_All();//所有点显示
  10. extern void Vfd128x64_Show_Num(unsigned char font,unsigned char x,unsigned char y,unsigned int sdata);//4位数字显示
  11. extern void Vfd128x64_Show_str(unsigned char font,unsigned char x,unsigned char y,unsigned char *str);//字符串显示

  12. #endif
  13. C文件
  14. #include "drv_vfd128x64.h"
  15. static unsigned char Calculate_Xor(unsigned char *dat, unsigned char len)//使用的老陈写的校验子程序,校验方法为按位异或(从控制命令、数据长度、坐标、数据)
  16. {
  17.         unsigned char calc_xor = 0;
  18.         unsigned char i = 0;

  19.         for (i = 0; i < len; i++)
  20.         {
  21.                 calc_xor ^= *dat;
  22.                 dat++;
  23.         }
  24.         return (calc_xor);
  25. }
  26. void Vfd128x64_Show_All()//显示所有点
  27. {
  28.     SendData(0x20);
  29.     SendData(0xFF);
  30.     SendData(0x00);
  31.     SendData(0XFF);
  32.     SendData(0X03);
  33. }

  34. void Vfd128x64_Clear_All()//清屏
  35. {
  36.     SendData(0x20);
  37.     SendData(0x00);
  38.     SendData(0x00);
  39.     SendData(0X00);
  40.     SendData(0X03);
  41. }

  42. void Vfd128x64_Show_Num(unsigned char font,unsigned char x,unsigned char y,unsigned int sdata)//font=bigfont or smallfont,sdata为4位数
  43. {
  44.     unsigned char i=0,sxor=0;
  45.     unsigned char temp[8];
  46.     temp[0]=font;
  47.     temp[1]=0x06;
  48.     temp[2]=x;
  49.     temp[3]=y;
  50.     temp[4]=sdata/1000+0x30;
  51.     temp[5]=sdata%1000/100+0x30;
  52.     temp[6]=sdata%100/10+0x30;
  53.     temp[7]=sdata%10+0x30;
  54.     sxor=Calculate_Xor(temp,8);
  55.     Delayus(30);
  56.     SendData(0x20);
  57.     for(i=0; i<8; i++)
  58.     {
  59.         SendData(temp[i]);
  60.     }
  61.     SendData(sxor);
  62.     SendData(0x03);
  63. }

  64. void Vfd128x64_Show_str(unsigned char font,unsigned char x,unsigned char y,unsigned char *str)//font为smallfont时不能显示汉字
  65. {
  66.         unsigned char slen=0,scom=0,sxor=0;
  67.         scom=font;
  68.         slen=strlen(str);
  69.         sxor=Calculate_Xor(str,slen)^scom^(slen+2)^x^y;
  70.         Delayus(30);
  71.         SendData(0x20);
  72.         SendData(scom);
  73.         SendData(slen+2);
  74.         SendData(x);
  75.         SendData(y);
  76.         while(*str!='\0')
  77.         {
  78.                 SendData(*str++);
  79.         }
  80.         SendData(sxor);
  81.         SendData(0x03);
  82. }
复制代码
感谢老陈的指导
[attach]130949[/attach]
作者: 工科男生    时间: 2013-8-10 00:41
准备做一个的,顶一下
作者: tlsmf    时间: 2013-11-8 16:56
支持            
作者: jimmyyjh    时间: 2013-11-27 00:22
抽空再研究一下~
作者: zyicc    时间: 2014-4-24 22:48
能不能用串口软件发




欢迎光临 amobbs.com 阿莫电子技术论坛 (https://www.amobbs.com/) Powered by Discuz! X3.4