|
本帖最后由 doujiang 于 2013-8-9 21:49 编辑
自己写的老陈VFD显示程序,串口波特率115200
头文件- #ifndef _drv_vfd128x64_h_
- #define _drv_vfd128x64_h_
- #include <string.h>
- #include "common.h"//包含延时函数头文件
- #include "drv_usart1.h"
- #define bigfont 0x11//字体控制命令宏定义
- #define smallfont 0x10
- extern void Vfd128x64_Clear_All();//清屏
- extern void Vfd128x64_Show_All();//所有点显示
- extern void Vfd128x64_Show_Num(unsigned char font,unsigned char x,unsigned char y,unsigned int sdata);//4位数字显示
- extern void Vfd128x64_Show_str(unsigned char font,unsigned char x,unsigned char y,unsigned char *str);//字符串显示
- #endif
- C文件
- #include "drv_vfd128x64.h"
- static unsigned char Calculate_Xor(unsigned char *dat, unsigned char len)//使用的老陈写的校验子程序,校验方法为按位异或(从控制命令、数据长度、坐标、数据)
- {
- unsigned char calc_xor = 0;
- unsigned char i = 0;
- for (i = 0; i < len; i++)
- {
- calc_xor ^= *dat;
- dat++;
- }
- return (calc_xor);
- }
- void Vfd128x64_Show_All()//显示所有点
- {
- SendData(0x20);
- SendData(0xFF);
- SendData(0x00);
- SendData(0XFF);
- SendData(0X03);
- }
- void Vfd128x64_Clear_All()//清屏
- {
- SendData(0x20);
- SendData(0x00);
- SendData(0x00);
- SendData(0X00);
- SendData(0X03);
- }
- void Vfd128x64_Show_Num(unsigned char font,unsigned char x,unsigned char y,unsigned int sdata)//font=bigfont or smallfont,sdata为4位数
- {
- unsigned char i=0,sxor=0;
- unsigned char temp[8];
- temp[0]=font;
- temp[1]=0x06;
- temp[2]=x;
- temp[3]=y;
- temp[4]=sdata/1000+0x30;
- temp[5]=sdata%1000/100+0x30;
- temp[6]=sdata%100/10+0x30;
- temp[7]=sdata%10+0x30;
- sxor=Calculate_Xor(temp,8);
- Delayus(30);
- SendData(0x20);
- for(i=0; i<8; i++)
- {
- SendData(temp[i]);
- }
- SendData(sxor);
- SendData(0x03);
- }
- void Vfd128x64_Show_str(unsigned char font,unsigned char x,unsigned char y,unsigned char *str)//font为smallfont时不能显示汉字
- {
- unsigned char slen=0,scom=0,sxor=0;
- scom=font;
- slen=strlen(str);
- sxor=Calculate_Xor(str,slen)^scom^(slen+2)^x^y;
- Delayus(30);
- SendData(0x20);
- SendData(scom);
- SendData(slen+2);
- SendData(x);
- SendData(y);
- while(*str!='\0')
- {
- SendData(*str++);
- }
- SendData(sxor);
- SendData(0x03);
- }
复制代码 感谢老陈的指导
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!
|