标题:
单片机+直流电机测速+160128中文液晶显示 带proteus仿真及源程序
[打印本页]
作者:
51黑ff
时间:
2016-10-9 00:06
标题:
单片机+直流电机测速+160128中文液晶显示 带proteus仿真及源程序
0.png
(76.4 KB, 下载次数: 98)
下载附件
2016-10-9 00:03 上传
0.png
(57.9 KB, 下载次数: 96)
下载附件
2016-10-9 00:04 上传
仿真工程文件及所有完整程序等资料下载地址:
http://www.51hei.com/bbs/dpj-56304-1.html
源程序:
#include <showfun.h>
#include <stdio.h>
extern char fnLCMInit(); // LCM 初始化
extern void at(unsigned char x,unsigned char y);/*设定文本x,y值*/
extern void cls(); // 清屏
extern void charout(unsigned char *str); //ASCII(8*8) 显示函数
extern void fnSetPos(unsigned char urow, unsigned char ucol); // 设置当前地址
extern uchar dprintf(uchar x,uchar y,char *fmt);// ASCII(8*16) 及 汉字(16*16) 显示函数
extern uchar fnPR12(uchar uCmd); // 写无参数的指令
extern uchar fnPR13(uchar uData); // 写数据
extern unsigned int Adc0832(unsigned char channel);
extern void Line( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bit Mode);
extern void Pixel(unsigned char PointX,unsigned char PointY, bit Mode);
uchar dsp[10]={0,0,0,0,0,0,0,0,0,0,};
char abc[3]={0,0,0,};
uchar key=0;
uint a=100;
uchar n=5;
uchar count=1;
uint k1=0;
uchar GeyKey();
void delay(uchar i);
void control();
main()
{
fnLCMInit();
fnSetPos(0,0);
dprintf(0,0,"直流电机加-减速及测速系统");
dprintf(0,12,"键盘+:步长加速");
dprintf(0,24,"键盘-:步长减速");
dprintf(0,36,"键盘=:顺时针转");
dprintf(0,48,"键盘on/c:逆时针转");
dprintf(0,72,"方向:");
dprintf(0,84,"转速:");
P1_1=0;
TMOD=0x15;
TH1=0x3c;
TL1=0xb0;
TH0=0x00;
TL0=0x00;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{ key=GeyKey();
switch(key)
{ case '1': { a=10;
//sprintf(abc,"%3.2f",a/255.0);
dprintf(0,96," 5 r/min");
//dprintf(0,96,abc);
dprintf(60,96,"r/min");
break; }
case '2': { a=25;dprintf(0,96," 25 r/min"); break; }
case '3': { a=40; dprintf(0,96," 40 r/min"); break; }
case '4': { a=55; dprintf(0,96," 60 r/min"); break; }
case '5': { a=70; dprintf(0,96," 80 r/min"); break; }
case '6': { a=90; dprintf(0,96,"100 r/min"); break; }
case '7': { a=110; dprintf(0,96,"120 r/min"); break; }
case '8': { a=130; dprintf(0,96,"135 r/min"); break; }
case '9': { a=150; dprintf(0,96,"150 r/min"); break; }
case '+': { dprintf(0,72,"方向: 顺时针");
control();
break;
}
case '-': { P1_0=0;
dprintf(0,72,"方向: 逆时针");
control();
break;
}
case '=': {P1_0=1;dprintf(0,72,"方向: 顺时针");break;}
case 'c': {P1_0=0;dprintf(0,72,"方向: 逆时针");break;}
case '/': {dprintf(0,72,"方向: 顺时针");
control();}
default: break;
}
}
}
uchar GeyKey()
{
P1_4=0;
P1_5=1;
P1_6=1;
P1_7=1;
P3_0=1;
P3_1=1;
P3_2=1;
P3_3=1;
_nop_();_nop_();
if(!P3_0)return '7';
if(!P3_1)return '8';
if(!P3_2)return '9';
if(!P3_3)return '/';
P1_4=1;
P1_5=0;
P1_6=1;
P1_7=1;
_nop_();_nop_();
if(!P3_0)return '4';
if(!P3_1)return '5';
if(!P3_2)return '6';
if(!P3_3)return '*';
P1_4=1;
P1_5=1;
P1_6=0;
P1_7=1;
_nop_();_nop_();
if(!P3_0)return '1';
if(!P3_1)return '2';
if(!P3_2)return '3';
if(!P3_3)return '-';
P1_4=1;
P1_5=1;
P1_6=1;
P1_7=0;
_nop_();_nop_();
if(!P3_0)return 'c';
if(!P3_1)return '0';
if(!P3_2)return '=';
if(!P3_3)return '+';
return 0;
}
void delay(uchar i)
{ uchar j,k;
for(;i>0;i--)
for(j=15;j>0;j--)
for(k=11;k>0;k--);
}
void time()interrupt 3
{
TR1=0;
count++;
k1+=TL0;
if(count==51)
{
sprintf(dsp,"%3d",k1);
dprintf(0,108,dsp);
dprintf(60,108,"r/min");
count=1;
k1=0;
}
TH1=0x3c;
TL1=0xb0;
TH0=0x00;
TL0=0x00;
TR1=1;
}
void control()
{
EA=1;
while(1)
{ if(a>=150)
a=150;
if(a<=10)
a=10;
P1_1=0;
delay(160-a);
P1_1=1;
delay(a);
key=GeyKey();
if(key=='-') a-=n;
else
if(key=='+') a+=n;
else
if(key=='=')
{ P1_0=1;
dprintf(0,72,"方向: 顺时针");
}
else
if(key=='c')
{ P1_0=0;
dprintf(0,72,"方向: 逆时针");
}
else
if(key=='*')
{ P1_1=0;
break;
}
else
if(key!=0)
break;
}
EA=0;
}
复制代码
/************************************************************************************/
/* LCM 240128 显示程序 */
/* MCU 型号: Winbond W78E58-24 */
/* 时钟频率: 22.1184 MHz */
/* 接口方式: 直接接口(挂总线) */
/* 开发环境: Keil C51 V6.14 */
/* 开发日期: .06.12- */
/* 程序编写: Youth */
/************************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <intrins.h>
#include <absacc.h>
#include <string.h>
#include <showfun.h>
code uchar const uPowArr[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
// ASCII 字模宽度及高度定义
#define ASC_CHR_WIDTH 8
#define ASC_CHR_HEIGHT 12
#define HZ_CHR_HEIGHT 12
#define HZ_CHR_WIDTH 12
char code MSK1[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
char code MSK2[]={0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
char code ASC_MSK[96*12] = {
// Terminal9; 此字体下对应的点阵为:宽x高=8x12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff, // < 0x20时,打印此字
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ' '
0x00,0x30,0x78,0x78,0x78,0x30,0x30,0x00,0x30,0x30,0x00,0x00,// '!'
0x00,0x66,0x66,0x66,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '"'
0x00,0x6c,0x6c,0xfe,0x6c,0x6c,0x6c,0xfe,0x6c,0x6c,0x00,0x00,// '#'
0x30,0x30,0x7c,0xc0,0xc0,0x78,0x0c,0x0c,0xf8,0x30,0x30,0x00,// '
0x00,0x00,0x00,0xc4,0xcc,0x18,0x30,0x60,0xcc,0x8c,0x00,0x00,// '%'
0x00,0x70,0xd8,0xd8,0x70,0xfa,0xde,0xcc,0xdc,0x76,0x00,0x00,// '&'
0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '''
0x00,0x0c,0x18,0x30,0x60,0x60,0x60,0x30,0x18,0x0c,0x00,0x00,// '('
0x00,0x60,0x30,0x18,0x0c,0x0c,0x0c,0x18,0x30,0x60,0x00,0x00,// ')'
0x00,0x00,0x00,0x66,0x3c,0xff,0x3c,0x66,0x00,0x00,0x00,0x00,// '*'
0x00,0x00,0x00,0x18,0x18,0x7e,0x18,0x18,0x00,0x00,0x00,0x00,// '+'
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0x60,0x00,// ','
0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,// '-'
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0x00,0x00,// '.'
0x00,0x00,0x02,0x06,0x0c,0x18,0x30,0x60,0xc0,0x80,0x00,0x00,// '/'
0x00,0x7c,0xc6,0xce,0xde,0xd6,0xf6,0xe6,0xc6,0x7c,0x00,0x00,// '0'
0x00,0x10,0x30,0xf0,0x30,0x30,0x30,0x30,0x30,0xfc,0x00,0x00,// '1'
0x00,0x78,0xcc,0xcc,0x0c,0x18,0x30,0x60,0xcc,0xfc,0x00,0x00,// '2'
0x00,0x78,0xcc,0x0c,0x0c,0x38,0x0c,0x0c,0xcc,0x78,0x00,0x00,// '3'
0x00,0x0c,0x1c,0x3c,0x6c,0xcc,0xfe,0x0c,0x0c,0x1e,0x00,0x00,// '4'
0x00,0xfc,0xc0,0xc0,0xc0,0xf8,0x0c,0x0c,0xcc,0x78,0x00,0x00,// '5'
0x00,0x38,0x60,0xc0,0xc0,0xf8,0xcc,0xcc,0xcc,0x78,0x00,0x00,// '6'
0x00,0xfe,0xc6,0xc6,0x06,0x0c,0x18,0x30,0x30,0x30,0x00,0x00,// '7'
0x00,0x78,0xcc,0xcc,0xec,0x78,0xdc,0xcc,0xcc,0x78,0x00,0x00,// '8'
0x00,0x78,0xcc,0xcc,0xcc,0x7c,0x18,0x18,0x30,0x70,0x00,0x00,// '9'
0x00,0x00,0x00,0x38,0x38,0x00,0x00,0x38,0x38,0x00,0x00,0x00,// ':'
0x00,0x00,0x00,0x38,0x38,0x00,0x00,0x38,0x38,0x18,0x30,0x00,// ';'
0x00,0x0c,0x18,0x30,0x60,0xc0,0x60,0x30,0x18,0x0c,0x00,0x00,// '<'
0x00,0x00,0x00,0x00,0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,// '='
0x00,0x60,0x30,0x18,0x0c,0x06,0x0c,0x18,0x30,0x60,0x00,0x00,// '>'
0x00,0x78,0xcc,0x0c,0x18,0x30,0x30,0x00,0x30,0x30,0x00,0x00,// '?'
0x00,0x7c,0xc6,0xc6,0xde,0xde,0xde,0xc0,0xc0,0x7c,0x00,0x00,// '@'
0x00,0x30,0x78,0xcc,0xcc,0xcc,0xfc,0xcc,0xcc,0xcc,0x00,0x00,// 'A'
0x00,0xfc,0x66,0x66,0x66,0x7c,0x66,0x66,0x66,0xfc,0x00,0x00,// 'B'
0x00,0x3c,0x66,0xc6,0xc0,0xc0,0xc0,0xc6,0x66,0x3c,0x00,0x00,// 'C'
0x00,0xf8,0x6c,0x66,0x66,0x66,0x66,0x66,0x6c,0xf8,0x00,0x00,// 'D'
0x00,0xfe,0x62,0x60,0x64,0x7c,0x64,0x60,0x62,0xfe,0x00,0x00,// 'E'
0x00,0xfe,0x66,0x62,0x64,0x7c,0x64,0x60,0x60,0xf0,0x00,0x00,// 'F'
0x00,0x3c,0x66,0xc6,0xc0,0xc0,0xce,0xc6,0x66,0x3e,0x00,0x00,// 'G'
0x00,0xcc,0xcc,0xcc,0xcc,0xfc,0xcc,0xcc,0xcc,0xcc,0x00,0x00,// 'H'
0x00,0x78,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x78,0x00,0x00,// 'I'
0x00,0x1e,0x0c,0x0c,0x0c,0x0c,0xcc,0xcc,0xcc,0x78,0x00,0x00,// 'J'
0x00,0xe6,0x66,0x6c,0x6c,0x78,0x6c,0x6c,0x66,0xe6,0x00,0x00,// 'K'
0x00,0xf0,0x60,0x60,0x60,0x60,0x62,0x66,0x66,0xfe,0x00,0x00,// 'L'
0x00,0xc6,0xee,0xfe,0xfe,0xd6,0xc6,0xc6,0xc6,0xc6,0x00,0x00,// 'M'
0x00,0xc6,0xc6,0xe6,0xf6,0xfe,0xde,0xce,0xc6,0xc6,0x00,0x00,// 'N'
0x00,0x38,0x6c,0xc6,0xc6,0xc6,0xc6,0xc6,0x6c,0x38,0x00,0x00,// 'O'
0x00,0xfc,0x66,0x66,0x66,0x7c,0x60,0x60,0x60,0xf0,0x00,0x00,// 'P'
0x00,0x38,0x6c,0xc6,0xc6,0xc6,0xce,0xde,0x7c,0x0c,0x1e,0x00,// 'Q'
0x00,0xfc,0x66,0x66,0x66,0x7c,0x6c,0x66,0x66,0xe6,0x00,0x00,// 'R'
0x00,0x78,0xcc,0xcc,0xc0,0x70,0x18,0xcc,0xcc,0x78,0x00,0x00,// 'S'
0x00,0xfc,0xb4,0x30,0x30,0x30,0x30,0x30,0x30,0x78,0x00,0x00,// 'T'
0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x78,0x00,0x00,// 'U'
0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x78,0x30,0x00,0x00,// 'V'
0x00,0xc6,0xc6,0xc6,0xc6,0xd6,0xd6,0x6c,0x6c,0x6c,0x00,0x00,// 'W'
0x00,0xcc,0xcc,0xcc,0x78,0x30,0x78,0xcc,0xcc,0xcc,0x00,0x00,// 'X'
0x00,0xcc,0xcc,0xcc,0xcc,0x78,0x30,0x30,0x30,0x78,0x00,0x00,// 'Y'
0x00,0xfe,0xce,0x98,0x18,0x30,0x60,0x62,0xc6,0xfe,0x00,0x00,// 'Z'
0x00,0x3c,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3c,0x00,0x00,// '['
0x00,0x00,0x80,0xc0,0x60,0x30,0x18,0x0c,0x06,0x02,0x00,0x00,// '\'
0x00,0x3c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x3c,0x00,0x00,// ']'
0x10,0x38,0x6c,0xc6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '^'
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,// '_'
0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '`'
0x00,0x00,0x00,0x00,0x78,0x0c,0x7c,0xcc,0xcc,0x76,0x00,0x00,// 'a'
0x00,0xe0,0x60,0x60,0x7c,0x66,0x66,0x66,0x66,0xdc,0x00,0x00,// 'b'
0x00,0x00,0x00,0x00,0x78,0xcc,0xc0,0xc0,0xcc,0x78,0x00,0x00,// 'c'
0x00,0x1c,0x0c,0x0c,0x7c,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,// 'd'
0x00,0x00,0x00,0x00,0x78,0xcc,0xfc,0xc0,0xcc,0x78,0x00,0x00,// 'e'
0x00,0x38,0x6c,0x60,0x60,0xf8,0x60,0x60,0x60,0xf0,0x00,0x00,// 'f'
0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0x7c,0x0c,0xcc,0x78,// 'g'
0x00,0xe0,0x60,0x60,0x6c,0x76,0x66,0x66,0x66,0xe6,0x00,0x00,// 'h'
0x00,0x18,0x18,0x00,0x78,0x18,0x18,0x18,0x18,0x7e,0x00,0x00,// 'i'
0x00,0x0c,0x0c,0x00,0x3c,0x0c,0x0c,0x0c,0x0c,0xcc,0xcc,0x78,// 'j'
0x00,0xe0,0x60,0x60,0x66,0x6c,0x78,0x6c,0x66,0xe6,0x00,0x00,// 'k'
0x00,0x78,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7e,0x00,0x00,// 'l'
0x00,0x00,0x00,0x00,0xfc,0xd6,0xd6,0xd6,0xd6,0xc6,0x00,0x00,// 'm'
0x00,0x00,0x00,0x00,0xf8,0xcc,0xcc,0xcc,0xcc,0xcc,0x00,0x00,// 'n'
0x00,0x00,0x00,0x00,0x78,0xcc,0xcc,0xcc,0xcc,0x78,0x00,0x00,// 'o'
0x00,0x00,0x00,0x00,0xdc,0x66,0x66,0x66,0x66,0x7c,0x60,0xf0,// 'p'
0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0x7c,0x0c,0x1e,// 'q'
0x00,0x00,0x00,0x00,0xec,0x6e,0x76,0x60,0x60,0xf0,0x00,0x00,// 'r'
0x00,0x00,0x00,0x00,0x78,0xcc,0x60,0x18,0xcc,0x78,0x00,0x00,// 's'
0x00,0x00,0x20,0x60,0xfc,0x60,0x60,0x60,0x6c,0x38,0x00,0x00,// 't'
0x00,0x00,0x00,0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,// 'u'
0x00,0x00,0x00,0x00,0xcc,0xcc,0xcc,0xcc,0x78,0x30,0x00,0x00,// 'v'
0x00,0x00,0x00,0x00,0xc6,0xc6,0xd6,0xd6,0x6c,0x6c,0x00,0x00,// 'w'
0x00,0x00,0x00,0x00,0xc6,0x6c,0x38,0x38,0x6c,0xc6,0x00,0x00,// 'x'
0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x3c,0x0c,0x18,0xf0,// 'y'
0x00,0x00,0x00,0x00,0xfc,0x8c,0x18,0x60,0xc4,0xfc,0x00,0x00,// 'z'
0x00,0x1c,0x30,0x30,0x60,0xc0,0x60,0x30,0x30,0x1c,0x00,0x00,// '{'
0x00,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x00,0x00,// '|'
0x00,0xe0,0x30,0x30,0x18,0x0c,0x18,0x30,0x30,0xe0,0x00,0x00,// '}'
0x00,0x73,0xda,0xce,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// '~'
};
typedef struct typFNT_GB16 // 汉字字模显示数据结构
{
char Index[2];
char Msk[24];
};
struct typFNT_GB16 code GB_16[] = { // 显示为12*12
"中",0x04,0x00,0x04,0x00,0x7F,0xC0,0x44,0x40,0x44,0x40,0x44,0x40,0x7F,0xC0,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x00,0x00,
"文",0x08,0x00,0x04,0x40,0xFF,0xE0,0x11,0x00,0x11,0x00,0x11,0x00,0x0A,0x00,0x0A,0x00,0x04,0x00,0x1B,0x00,0xE0,0xE0,0x00,0x00,
"测",0x9E,0x20,0x52,0x20,0x12,0xA0,0x96,0xA0,0x56,0xA0,0x56,0xA0,0x56,0xA0,0xD6,0xA0,0x44,0xA0,0x4A,0x20,0x71,0x60,0x00,0x00,
"试",0x80,0xC0,0x40,0xA0,0x5F,0xE0,0x00,0x80,0xC0,0x80,0x4F,0x80,0x44,0x80,0x44,0x80,0x57,0xA0,0x6C,0x60,0x40,0x20,0x00,0x00,
"液",0x81,0x00,0x5F,0xE0,0x25,0x00,0x85,0xC0,0xAA,0x40,0x4E,0xC0,0x5A,0x40,0x49,0x80,0xC8,0x80,0x49,0x40,0x4E,0x20,0x00,0x00,
"晶",0x1F,0x80,0x10,0x80,0x1F,0x80,0x10,0x80,0x1F,0x80,0x00,0x00,0x7B,0xE0,0x4A,0x20,0x7B,0xE0,0x4A,0x20,0x7B,0xE0,0x00,0x00,
"显",0x3F,0x80,0x20,0x80,0x3F,0x80,0x20,0x80,0x3F,0x80,0x00,0x00,0x4A,0x40,0x2A,0x40,0x2A,0x80,0x0B,0x00,0xFF,0xE0,0x00,0x00,
"示",0x00,0x80,0x7F,0xC0,0x00,0x00,0x00,0x00,0xFF,0xE0,0x04,0x00,0x14,0x80,0x24,0x40,0x44,0x20,0x84,0x20,0x1C,0x00,0x00,0x00,
//"及",0x7F,0x80,0x10,0x80,0x11,0x00,0x11,0x00,0x19,0xC0,0x14,0x40,0x14,0x80,0x23,0x00,0x23,0x00,0x4C,0x80,0xB0,0x60,0x00,0x00,
//"的",0x11,0x00,0x21,0x00,0xFB,0xE0,0x8A,0x20,0x8C,0x20,0x8A,0x20,0xF9,0x20,0x89,0x20,0x88,0x20,0xF8,0x20,0x89,0xC0,0x00,0x00,
//"试",0x80,0xC0,0x40,0xA0,0x5F,0xE0,0x00,0x80,0xC0,0x80,0x4F,0x80,0x44,0x80,0x44,0x80,0x57,0xA0,0x6C,0x60,0x40,0x20,0x00,0x00,
//"验",0xF1,0x00,0x11,0x00,0x52,0x80,0x54,0x40,0x5B,0xA0,0xF0,0x00,0x15,0x40,0x35,0x40,0xD5,0x40,0x10,0x80,0x6F,0xE0,0x00,0x00,
//"程",0x37,0xC0,0xE4,0x40,0x24,0x40,0xF7,0xC0,0x20,0x00,0x6F,0xE0,0x71,0x00,0xA7,0xC0,0xA1,0x00,0x21,0x00,0x2F,0xE0,0x00,0x00,
//"序",0x04,0x00,0x7F,0xE0,0x40,0x00,0x5F,0x80,0x45,0x00,0x42,0x00,0x7F,0xE0,0x42,0x40,0x42,0x00,0x82,0x00,0x8E,0x00,0x00,0x00,
"键",0x41,0x00,0x7F,0xC0,0x89,0x40,0xEB,0xE0,0x5D,0x40,0x47,0xC0,0xF5,0x00,0x57,0xE0,0x49,0x00,0x6D,0x00,0x53,0xE0,0x00,0x00,
"盘",0x08,0x00,0x3F,0x80,0x24,0x80,0xFF,0xE0,0x28,0x80,0x25,0x80,0x40,0x00,0xBF,0xC0,0x2A,0x40,0x2A,0x40,0xFF,0xE0,0x00,0x00,
//"字",0x04,0x00,0x7F,0xE0,0xC0,0x20,0x3F,0x80,0x02,0x00,0x04,0x00,0xFF,0xE0,0x04,0x00,0x04,0x00,0x04,0x00,0x1C,0x00,0x00,0x00,
//"可",0x00,0x40,0xFF,0xE0,0x00,0x80,0x7C,0x80,0x44,0x80,0x44,0x80,0x44,0x80,0x7C,0x80,0x44,0x80,0x00,0x80,0x03,0x80,0x00,0x00,
//"以",0x00,0x80,0x48,0x80,0x44,0x80,0x44,0x80,0x40,0x80,0x40,0x80,0x48,0x80,0x50,0x80,0x61,0x40,0x46,0x20,0x18,0x20,0x00,0x00,
"按",0x21,0x00,0x2F,0xE0,0xF8,0x20,0x22,0x00,0x32,0x00,0x6F,0xE0,0xA4,0x40,0x24,0x80,0x23,0x80,0x21,0x40,0xEE,0x20,0x00,0x00,
"点",0x04,0x00,0x07,0xC0,0x04,0x00,0x04,0x00,0x3F,0x80,0x20,0x80,0x20,0x80,0x3F,0x80,0x00,0x00,0x49,0x40,0xC9,0x20,0x00,0x00,
"定",0x04,0x00,0x7F,0xE0,0xC0,0x20,0x00,0x00,0x7F,0xC0,0x04,0x00,0x24,0x00,0x27,0xC0,0x34,0x00,0x4C,0x00,0x83,0xE0,0x00,0x00,
"位",0x24,0x00,0x22,0x00,0x5F,0xE0,0x40,0x00,0xC8,0x80,0x48,0x80,0x44,0x80,0x45,0x00,0x45,0x00,0x41,0x00,0x5F,0xE0,0x00,0x00,
"直",0x04,0x00,0xFF,0xE0,0x04,0x00,0x3F,0x80,0x20,0x80,0x20,0x80,0x3F,0x80,0x20,0x80,0x3F,0x80,0x20,0x80,0xFF,0xE0,0x00,0x00,
"线",0x22,0x80,0x22,0x40,0x52,0x60,0x97,0x80,0xE2,0x60,0x4F,0x80,0xB2,0x40,0xC2,0x80,0x31,0x20,0xC6,0xA0,0x18,0x60,0x00,0x00,
"绘",0x21,0x00,0x21,0x00,0x52,0x80,0x94,0x40,0xEB,0xA0,0x20,0x00,0x5F,0xE0,0xE2,0x00,0x02,0x80,0xF4,0x40,0x8F,0xE0,0x00,0x00,
"制",0x10,0x20,0x54,0x20,0x7E,0xA0,0x90,0xA0,0xFE,0xA0,0x10,0xA0,0x7E,0xA0,0x52,0xA0,0x52,0x20,0x56,0x20,0x10,0xE0,0x00,0x00,
"图",0x7F,0xE0,0x48,0x20,0x5F,0x20,0x6A,0x20,0x44,0x20,0x4A,0x20,0x75,0xA0,0x42,0x20,0x4C,0x20,0x42,0x20,0x7F,0xE0,0x00,0x00,
"片",0x22,0x00,0x22,0x00,0x22,0x00,0x3F,0xE0,0x20,0x00,0x20,0x00,0x3F,0x00,0x21,0x00,0x21,0x00,0x41,0x00,0x81,0x00,0x00,0x00,
"绘",0x21,0x00,0x21,0x00,0x52,0x80,0x94,0x40,0xEB,0xA0,0x20,0x00,0x5F,0xE0,0xE2,0x00,0x02,0x80,0xF4,0x40,0x8F,0xE0,0x00,0x00,
"制",0x10,0x20,0x54,0x20,0x7E,0xA0,0x90,0xA0,0xFE,0xA0,0x10,0xA0,0x7E,0xA0,0x52,0xA0,0x52,0x20,0x56,0x20,0x10,0xE0,0x00,0x00,
"流",0x82,0x00,0x5F,0xE0,0x42,0x00,0x04,0x80,0xAF,0xC0,0x60,0x40,0x2A,0x80,0x4A,0x80,0xCA,0xA0,0x52,0xA0,0x62,0xE0,0x00,0x00,
"电",0x04,0x00,0x04,0x40,0x7F,0xE0,0x44,0x40,0x7F,0xC0,0x44,0x40,0x44,0x40,0x7F,0xC0,0x44,0x00,0x04,0x20,0x03,0xE0,0x00,0x00,
"机",0x20,0x80,0x27,0xC0,0xFC,0x80,0x24,0x80,0x24,0x80,0x74,0x80,0x6C,0x80,0xA4,0x80,0xA4,0xA0,0x28,0xA0,0x30,0xE0,0x00,0x00,
"加",0x20,0x00,0x20,0x00,0xFD,0xE0,0x25,0x20,0x25,0x20,0x25,0x20,0x25,0x20,0x25,0x20,0x45,0x20,0x45,0xE0,0x99,0x20,0x00,0x00,
"减",0x81,0x40,0x41,0x40,0x5F,0xE0,0x11,0x00,0x5F,0x20,0x51,0x20,0x9F,0x40,0x9A,0x80,0xAE,0xA0,0xA9,0x60,0x42,0x20,0x00,0x00,
"速",0x82,0x00,0x5F,0xE0,0x42,0x00,0x0F,0xC0,0xCA,0x40,0x4F,0xC0,0x43,0x00,0x46,0x80,0x5A,0x40,0xA2,0x00,0x9F,0xE0,0x00,0x00,
"及",0x7F,0x80,0x10,0x80,0x11,0x00,0x11,0x00,0x19,0xC0,0x14,0x40,0x14,0x80,0x23,0x00,0x23,0x00,0x4C,0x80,0xB0,0x60,0x00,0x00,
"系",0x03,0xC0,0x7C,0x00,0x08,0x80,0x3F,0x00,0x04,0x00,0x08,0x80,0x3F,0xC0,0x15,0x00,0x24,0x80,0x44,0x40,0x9C,0x20,0x00,0x00,
"统",0x21,0x00,0x27,0xE0,0x51,0x00,0xF2,0x00,0x24,0x40,0x47,0xE0,0xF2,0x80,0x02,0x80,0x32,0xA0,0xC4,0xA0,0x18,0xE0,0x00,0x00,
"步",0x04,0x00,0x27,0xC0,0x24,0x00,0x24,0x00,0xFF,0xE0,0x04,0x00,0x14,0x40,0x24,0x80,0x41,0x00,0x06,0x00,0x78,0x00,0x00,0x00,
"长",0x20,0x80,0x21,0x00,0x22,0x00,0x24,0x00,0x28,0x00,0xFF,0xE0,0x24,0x00,0x22,0x00,0x21,0x00,0x2C,0x80,0x30,0x60,0x00,0x00,
"顺",0x57,0xE0,0x51,0x00,0x57,0xE0,0x54,0x20,0x55,0x20,0x55,0x20,0x55,0x20,0x55,0x20,0x51,0x80,0x92,0x40,0x8C,0x20,0x00,0x00,
"时",0x00,0x80,0xF0,0x80,0x9F,0xE0,0x90,0x80,0x94,0x80,0xF2,0x80,0x92,0x80,0x90,0x80,0xF0,0x80,0x90,0x80,0x03,0x80,0x00,0x00,
"针",0x41,0x00,0x41,0x00,0x79,0x00,0x81,0x00,0xF7,0xE0,0x21,0x00,0xF9,0x00,0x21,0x00,0x29,0x00,0x31,0x00,0x21,0x00,0x00,0x00,
"旋",0x42,0x00,0x23,0xE0,0xF4,0x00,0x4F,0xE0,0x71,0x20,0x55,0x40,0x55,0x00,0x55,0xE0,0x55,0x00,0xB7,0x00,0x89,0xE0,0x00,0x00,
"转",0x21,0x00,0xF9,0x00,0x47,0xE0,0x61,0x00,0xA7,0xE0,0xFA,0x00,0x23,0xC0,0x38,0x40,0xE0,0x80,0x23,0x00,0x20,0x80,0x00,0x00,
"逆",0x84,0x40,0x42,0x80,0x5F,0xE0,0x01,0x00,0xC9,0x40,0x49,0x40,0x4F,0xC0,0x42,0x00,0x44,0x00,0xA8,0x00,0x9F,0xE0,0x00,0x00,
//"旋",0x42,0x00,0x23,0xE0,0xF4,0x00,0x4F,0xE0,0x71,0x20,0x55,0x40,0x55,0x00,0x55,0xE0,0x55,0x00,0xB7,0x00,0x89,0xE0,0x00,0x00,
//"转",0x21,0x00,0xF9,0x00,0x47,0xE0,0x61,0x00,0xA7,0xE0,0xFA,0x00,0x23,0xC0,0x38,0x40,0xE0,0x80,0x23,0x00,0x20,0x80,0x00,0x00,
"方",0x04,0x00,0x02,0x40,0xFF,0xE0,0x08,0x00,0x0F,0x80,0x08,0x80,0x08,0x80,0x10,0x80,0x10,0x80,0x20,0x80,0xC7,0x00,0x00,0x00,
"向",0x04,0x00,0x08,0x40,0x7F,0xE0,0x40,0x40,0x5F,0x40,0x51,0x40,0x51,0x40,0x5F,0x40,0x40,0x40,0x40,0x40,0x41,0xC0,0x00,0x00,
//"时",
//"针",
};
uchar gCurRow,gCurCol; // 图形当前行、列存储,行高16点,列宽8点
uchar tCurRow,tCurCol; // 文本当前行、列存储,行高8点 ,列宽8点
uchar ShowModeSW; // 当前显示模式
uint txthome,grhome;
/******************************************************************************/
uchar fnGetRow();
uchar fnGetCol();
uchar fnST01(); // 状态位STA1,STA0判断(读写指令和读写数据)
uchar fnST2(); // 状态位ST2判断(数据自动读状态)
uchar fnST3(); // 状态位ST3判断(数据自动写状态)
uchar fnST6(); // 状态位ST6判断(屏读/屏拷贝状态)
uchar fnPR1(uchar uCmd,uchar uPar1,uchar uPar2); // 写双参数的指令
uchar fnPR11(uchar uCmd,uchar uPar1); // 写单参数的指令
uchar fnPR12(uchar uCmd); // 写无参数的指令
uchar fnPR13(uchar uData); // 写数据
uchar fnPR2(); // 读数据
void fnSetPos(uchar urow, uchar ucol); // 设置当前地址
void cursor(uchar uRow, uchar uCol); //设置当前显示行、列
void at(unsigned char x,unsigned char y);/*设定文本x,y值*/
void cls(); // 清屏
char fnLCMInit(); // LCM 初始化
void charout(uchar *str); //ASCII(8*8) 显示函数
uchar dprintf(uchar x,uchar y,char *fmt);// ASCII(8*16) 及 汉字(16*16) 显示函数
void OutToLCD(uchar Dat,uchar x,uchar y);//显示辅助函数
void SetShowMode(uchar newShowModeSW);
void Line( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bit Mode);
void Pixel(unsigned char PointX,unsigned char PointY, bit Mode);
uchar fnGetRow(void)
{
return gCurRow;
}
uchar fnGetCol(void)
{
return gCurCol;
}
uchar fnST01(void) // 状态位STA1,STA0判断(读写指令和读写数据)
{
uchar i;
for(i=10;i>0;i--)
{
if((LCMCW & 0x03) == 0x03)
break;
}
return i; // 若返回零,说明错误
}
uchar fnST2(void) // 状态位ST2判断(数据自动读状态)
{
uchar i;
for(i=10;i>0;i--)
{
if((LCMCW & 0x04) == 0x04)
break;
}
return i; // 若返回零,说明错误
}
uchar fnST3(void) // 状态位ST3判断(数据自动写状态)
{
uchar i;
for(i=10;i>0;i--)
{
if((LCMCW & 0x08) == 0x08)
break;
}
return i; // 若返回零,说明错误
}
uchar fnST6(void) // 状态位ST6判断(屏读/屏拷贝状态)
{
uchar i;
for(i=10;i>0;i--)
{
if((LCMCW & 0x40) == 0x40)
break;
}
return i; // 若返回零,说明错误
}
uchar fnPR1(uchar uCmd,uchar uPar1,uchar uPar2) // 写双参数的指令
{
if(fnST01() == 0)
return 1;
LCMDW = uPar1;
if(fnST01() == 0)
return 2;
LCMDW = uPar2;
if(fnST01() == 0)
return 3;
LCMCW = uCmd;
return 0; // 返回0成功
}
uchar fnPR11(uchar uCmd,uchar uPar1) // 写单参数的指令
{
if(fnST01() == 0)
return 1;
LCMDW = uPar1;
if(fnST01() == 0)
return 2;
LCMCW = uCmd;
return 0; // 返回0成功
}
uchar fnPR12(uchar uCmd) // 写无参数的指令
{
if(fnST01() == 0)
return 1;
LCMCW = uCmd;
return 0; // 返回0成功
}
uchar fnPR13(uchar uData) // 写数据
{
if(fnST3() == 0)
return 1;
LCMDW = uData;
return 0; // 返回0成功
}
uchar fnPR2(void) // 读数据
{
if(fnST01() == 0)
return 1;
return LCMDW;
}
void fnSetPos(uchar urow, uchar ucol) //设置当前地址
{
uint iPos;
iPos = urow * 20 + ucol;
fnPR1(LC_ADD_POS,iPos & 0xFF,iPos / 256);
gCurRow = urow;
gCurCol = ucol;
}
void cursor(uchar uRow, uchar uCol) //设置当前显示行、列
{
fnSetPos(uRow * 16, uCol);
}
void at(unsigned char x,unsigned char y)/*设定文本x,y值*/
{
uint iPos; //地址
iPos = x + y* 20;
fnPR1(LC_ADD_POS,iPos&0xff,iPos/256);
tCurRow = x;
tCurCol = y;
}
// 清屏
void cls(void)
{
uint i;
fnPR1(LC_ADD_POS,0x00,0x00); // 置地址指针
fnPR12(LC_AUT_WR); // 自动写
for(i=0;i<0x2000;i++)
{
fnST3();
fnPR13(0x00); // 写数据
}
fnPR12(LC_AUT_OVR); // 自动写结束
fnPR1(LC_ADD_POS,0x00,0x00); // 重置地址指针
gCurRow = 0; // 置地址指针存储变量
gCurCol = 0;
}
// LCM 初始化
char fnLCMInit(void)
{
reset=0;
reset=1;
fnPR1(LC_TXT_STP,0x00,0x00); // 文本显示区首地址
fnPR1(LC_TXT_WID,0x14,0x00); // 文本显示区宽度
fnPR1(LC_GRH_STP,0x00,0x00); // 图形显示区首地址
fnPR1(LC_GRH_WID,0x14,0x00); // 图形显示区宽度
fnPR11(LC_CGR_POS,CGRAMSTART >> 11);
fnPR12(LC_CUR_SHP | 0x01); // 光标形状
fnPR12(LC_MOD_OR); // 显示方式设置
fnPR12(LC_DIS_SW |0x08);
grhome = GRSTART;
txthome = TXTSTART;
return 0;
}
void charout(uchar *str)
{
uchar ch,len,i,uRow,uCol ;
len=strlen(str);
i=0;
uRow = tCurRow;
uCol = tCurRow;
at(uCol,uRow);
while(i<len)
{
ch=str[i]-0x20;
fnPR11(LC_INC_WR,ch);
i++;
}
}
// ASCII及汉字显示函数
uchar dprintf(uchar x,uchar y,char *fmt)
{
char c1,c2,cData;
uchar i=0,j,uLen;
uchar k;
uLen=strlen(fmt);
while(i<uLen)
{
c1 = fmt[i];
c2 = fmt[i+1];
fnSetPos(y,x/8);
if(c1 >= 0)
{
// ASCII
if(c1 < 0x20)
{
switch(c1)
{
case CR:
case LF: // 回车或换行
i++;
x=0;
if(y < 112)y+=HZ_CHR_HEIGHT;
continue;
case BS: // 退格
i++;
if(y>ASC_CHR_WIDTH)y-=ASC_CHR_WIDTH;
cData = 0x00;
break;
}
}
for(j=0;j<ASC_CHR_HEIGHT;j++)
{
if(c1 >= 0x1f)
{
cData= ASC_MSK[(c1-0x1f)*ASC_CHR_HEIGHT+j];
fnSetPos(y+j,x/8);
if((x%8)==0)
{
fnPR12(LC_AUT_WR); // 写数据
fnPR13(cData);
fnPR12(LC_AUT_OVR);
}
else
OutToLCD(cData,x,y+j);
}
fnSetPos(y+j,x/8);
}
if(c1 != BS) // 非退格
x+=ASC_CHR_WIDTH;
}
else
{ // 中文
for(j=0;j<sizeof(GB_16)/sizeof(GB_16[0]);j++)
{
if(c1 == GB_16[j].Index[0] && c2 == GB_16[j].Index[1])
break;
}
for(k=0;k<HZ_CHR_HEIGHT;k++)
{
fnSetPos(y+k,x/8);
if(j < sizeof(GB_16)/sizeof(GB_16[0]))
{
c1=GB_16[j].Msk[k*2];
c2=GB_16[j].Msk[k*2+1];
}
else
c1=c2=0;
if((x%8)==0)
{
fnPR12(LC_AUT_WR);
fnPR13(c1);
fnPR12(LC_AUT_OVR);
}
else
OutToLCD(c1,x,y+k);
if(((x+2+HZ_CHR_WIDTH/2)%8)==0)
{
fnPR12(LC_AUT_WR);
fnPR13(c2);
fnPR12(LC_AUT_OVR);
}
else
OutToLCD(c2,x+2+HZ_CHR_WIDTH/2,y+k);
}
x+=HZ_CHR_WIDTH;
i++;
}
i++;
}
return uLen;
}
void OutToLCD(uchar Dat,uchar x,uchar y)
{
uchar uData1,uData2,ux,a,b;
a=8-(x%8);b=x%8;
fnSetPos(y,x/8);
fnPR12(LC_AUT_RD); // 读数据
uData1=fnPR2();
uData2=fnPR2();
fnPR12(LC_AUT_OVR);
fnSetPos(y,x/8);
uData1&=~MSK1[a];
ux=Dat&MSK2[a];
ux>>=b;
uData1=uData1|ux;
ux=~MSK2[b];
uData2&=ux;
ux=MSK1[b];
ux=Dat&ux;
ux<<=a;
uData2=uData2|ux;
fnPR12(LC_AUT_WR); // 写数据
fnPR13(uData1);
fnPR13(uData2);
fnPR12(LC_AUT_OVR);
}
void SetShowMode(uchar newShowModeSW) //设置为显示模式
{
ShowModeSW=newShowModeSW;
fnPR12(LC_DIS_SW | newShowModeSW);
}
/**********************************
//= 函数原型: Pixel(unsigned char PointX,unsigned char PointY, bit Mode)
//= 功 能: 在指定坐标位置显示一个点
//= 参 数: 坐标,显示点或清除点
//= 返 回 值:
//= 函数性质:私有函数
//= 如果显示屏超过了256*256,请修改这个函数 PointX,PointY的类型
//= Mode 1:显示 0:清除该点
**********************************/
void Pixel(unsigned char PointX,unsigned char PointY, bit Mode)
{
unsigned char StartAddr;
unsigned char dat;
StartAddr=7-(PointX%8);
dat=LC_BIT_OP|StartAddr; //生产位操作命令画点的数据
if(Mode) dat=dat|0x08;
fnSetPos(PointY,PointX/8);
fnPR12(LC_BIT_OP|dat); // 写数据
}
/**********************************
//= 函数原型: void line( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bit Mode)
//= 功 能: 划线函数
//= 参 数: 坐标1,坐标2,显示点或清除点
//= 返 回 值:
//= 函数性质:私有函数
//= 其它:显示点阵不超过255*255
/**********************************/
void line( unsigned char x1,unsigned char y1, unsigned char x2,unsigned char y2, bit Mode)
{
unsigned char x,y;
float k,b;
if( abs(y1-y2) <= abs(x1-x2) ) // |k|<=1
{
k=((float)y2-y1) / ((float)x2-x1) ;
b=y1-k*x1;
if( x1 <= x2 )
{
for(x=x1;x<=x2;x++)
{
y=(uchar)(k*x+b);
Pixel(x, y, Mode);
}
}
else
{
for(x=x2;x<=x1;x++)
{
y=(uchar)(k*x+b);
Pixel(x, y, Mode);
}
}
}
else // abs(y1-y2) > abs(x1-x2) |K|>1
{
k=((float)x2-x1) / ((float)y2-y1) ;
b=x1-k*y1;
if( y1 <= y2 )
{
for(y=y1;y<=y2;y++)
{
x=(uchar)(k*y+b);
Pixel( x , y,Mode );
}
}
else
{
for(y=y2;y<=y1;y++)
{
x=(uchar)(k*y+b);
Pixel( x , y,Mode );
}
}
}
}
复制代码
作者:
Minato_SiXpLuS
时间:
2016-10-9 11:05
51黑有你更精彩!!!
作者:
唯壹
时间:
2016-10-10 10:54
强大!学习了,棒棒哒
作者:
gxnnztw
时间:
2018-4-8 16:34
谢谢楼主!学习中
作者:
宫商角徵羽smile
时间:
2018-4-26 16:55
我的仿真只显示一个速度
作者:
无时崩溃
时间:
2018-4-28 22:25
感谢楼主分享
作者:
肖茂顺
时间:
2019-6-2 14:21
太厉害了,给您个大赞!
作者:
Ichenpuxian
时间:
2019-12-18 11:37
51黑有你更精彩!!!
作者:
LJMEP
时间:
2019-12-18 15:37
学习一下
学习一下
作者:
Doctor夫妇
时间:
2019-12-18 15:39
谢谢分享,学习了
作者:
xin16
时间:
2020-5-9 09:53
这个真的很好
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1