单片机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 175|回复: 2
收起左侧

12864怎么将无字符改为有字符型,示波器制作

[复制链接]
zbcx 发表于 2019-5-22 01:46 来自手机 | 显示全部楼层 |阅读模式
请问下边这个程序可以改成有字符型12864输出吗,怎么改,解决办法,非常感谢╰(*︶`*)╯


#include <reg51.h>
#include <math.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define lcdcol_add 0x40
#define page_add 0xb8
sbit bx_adjust=P3^2; //函数发生器定义
sbit pl_adjust=P3^3; //中断输入接口
uchar bxxz=0,pl=0,delay_time=0,kk,pp; //为函数发生模块提供中间变量
uchar *which_bx,*which_bx2; //选择哪一种波形
uint pl_num;
/************* 12864LCD引脚定义 *************/
sbit LCD_RS = P3^7; //寄存器选择输入
sbit LCD_RW = P3^6; //液晶读/写控制
sbit LCD_EN = P3^5; //液晶使能控制
sbit LCD_RST = P3^4; //液晶复位端口
sbit LCD_CS1 = P3^0; //右半屏控制
sbit LCD_CS2 = P3^1; //左半屏控制
uchar code pinglv[64]={
0x40,0x7C,0x40,0xFF,0x48,0x6C,0x4A,0xF2,
0x12,0x1A,0xD6,0x12,0x12,0xFB,0x12,0x00,
0x00,0x14,0xA4,0x44,0x04,0x24,0xB5,0x6E,
0x24,0x94,0x04,0x44,0xA6,0x14,0x00,0x00,
0x08,0x87,0x40,0x2F,0x10,0x0F,0x80,0x8F,
0x40,0x20,0x1F,0x20,0x40,0xCF,0x00,0x00,
0x08,0x09,0x08,0x08,0x09,0x09,0x09,0xFF,
0x09,0x09,0x0B,0x08,0x08,0x0D,0x08,0x00 };
uchar code hanshu[64]=
{0x00,0xF0,0x00,0x22,0x42,0x82,0x02,0xF2,
0x12,0x8A,0x46,0x62,0x00,0xF0,0x00,0x00,
0x10,0x92,0x54,0x30,0xFF,0x50,0x94,0x32,
0xD8,0x17,0x10,0x10,0xF0,0x18,0x10,0x00,
0x00,0xFF,0x40,0x48,0x44,0x52,0x60,0x5F,
0x40,0x42,0x44,0x4C,0x40,0xFF,0x00,0x00,
0x02,0x82,0x4E,0x33,0x22,0x52,0x8E,0x40,
0x23,0x14,0x08,0x16,0x61,0xC0,0x40,0x00 };
uchar code zx[64]={
0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0xFE,
0x82,0x82,0x82,0xC2,0x83,0x02,0x00,0x00,
0x02,0xE2,0x22,0x22,0x3E,0x08,0x08,0x88,
0x49,0x3A,0x08,0x08,0x88,0x0C,0x08,0x00,
0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,
0x40,0x40,0x40,0x40,0x40,0x60,0x40,0x00,
0x00,0x43,0x82,0x42,0x3E,0x00,0x20,0x31,
0x29,0x25,0x23,0x21,0x30,0x60,0x00,0x00 };
uchar code jc[64]={
0x10,0x28,0xE7,0x24,0x24,0x24,0x00,0xFE,
0x92,0x92,0xF2,0x92,0x92,0xDF,0x82,0x00,
0x40,0x40,0x40,0x7E,0x40,0x40,0x40,0x7F,
0x44,0x44,0x46,0x44,0x40,0x60,0x40,0x00,
0x01,0x01,0x3F,0x11,0x49,0x25,0x18,0x07,
0xFC,0x44,0x47,0x44,0x44,0xFE,0x04,0x00,
0x00,0x00,0xFF,0x40,0x50,0x48,0x44,0x43,
0x44,0x48,0x58,0x40,0xFF,0x00,0x00,0x00, };
uchar code fb[64]={
0x10,0x10,0x10,0x10,0x10,0xF1,0x92,0x96,
0x90,0x90,0x90,0xD0,0x90,0x18,0x10,0x00,
0x20,0x42,0x04,0x0C,0x80,0xF8,0x88,0x88,
0x88,0xFF,0x88,0x88,0xA8,0x18,0x00,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,
0x40,0x80,0x40,0x3F,0x00,0x00,0x00,0x00,
0x04,0x04,0xFE,0x41,0x30,0x8F,0x40,0x22,

0x14,0x08,0x14,0x22,0x41,0xC0,0x40,0x00, };
uchar code sj[64]={
0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,
0x84,0x84,0x84,0xC4,0x86,0x04,0x00,0x00,
0x20,0x10,0x08,0xF4,0x93,0x92,0x92,0xF2,
0x9A,0x96,0x92,0x90,0xF8,0x10,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x30,0x20,0x00,
0x80,0x40,0x20,0x1F,0x04,0x04,0x04,0x7F,
0x04,0x04,0x44,0x84,0x7F,0x00,0x00,0x00, };
uchar code table[]={
0x3E,0x51,0x49,0x45,0x3E, // -0-
0x00,0x42,0x7F,0x40,0x00, // -1-
0x62,0x51,0x49,0x49,0x46, // -2-
0x21,0x41,0x49,0x4D,0x33, // -3-
0x18,0x14,0x12,0x7F,0x10, // -4-
0x27,0x45,0x45,0x45,0x39, // -5-
0x3C,0x4A,0x49,0x49,0x31, // -6-
0x01,0x71,0x09,0x05,0x03, // -7-
0x36,0x49,0x49,0x49,0x36, // -8-
0x46,0x49,0x49,0x29,0x1E, // -9-
0x7F,0x08,0x08,0x08,0x7F, // -H
0x61,0x51,0x49,0x45,0x43, // -Z-
0x1F,0x20,0x40,0x20,0x1F, // -V-
0x7F,0x09,0x09,0x09,0x06, // -P-
0x00,0x36,0x36,0x00,0x00, // -:-
0x00,0x60,0x60,0x00,0x00, // -.-
};
uchar code sinx[64]={ //以下为波形代码
128,114,102,90,78,66,55,45,36,28,20,14,9,5,2,1,1,1, 3,7,11,17,24,32,41,50,61,72,84,96,108,121,133,146, 158,170,182,193,204,213,222,230,237,243,247,251,253, 254,254,252,249,245,240,234,226,218,209,199,188,176, 167,158,145,135};
uchar code juchi[64]={
255,251,247,243,239,235,231,227,223,219,215,210,206,202, 198,194,190,186,182,178,174,170,166,162,158,154,150,146, 142,138,134,130,125,121,117,113,109,105,101,97,93,89,85, 81,77,73,69,61,57,53,49,45,40,36,32,28,24,20,16,12,8,4,0 };
uchar code fangbo[64]={
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,
};
uchar code sanjiao[64]={
0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136, 144,152,160,168,176,184,192,200,208,216,224,232,240,248, 248,240,232,224,216,208,200,192,184,176,168,160,152,144, 136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,0 };
void lcd_delay(uint t)
{
unsigned int i,j;
for(i=0;i<t;i++);
for(j=0;j<10;j++);
}
void bx_delay() //延时1ms
{
int a,b;
for(a=1;a>0;a--)
for(b=122;b>0;b--);
}
void lcd_busy()
{
uchar dat,DATA;
LCD_RW = 1;
LCD_RS = 0;
do
{
DATA=0x00;
LCD_EN=1;
lcd_delay(2);
dat=DATA;
LCD_EN=0;
dat=0x80&dat;
}
while(!(dat==0x00));
}
void lcd_wcmd(uchar cmd) // cmd 命令字节
{
lcd_busy(); // 等待不忙
LCD_RS = 0;
LCD_RW = 0;
P0 = cmd; //把命令写入
lcd_delay(2);
LCD_EN = 1;
lcd_delay(2);
LCD_EN = 0;
}
void lcd_wdat(uchar dat) // 写数据到LCD
{
lcd_busy();
LCD_RS = 1;
LCD_RW = 0;
P0 = dat;
lcd_delay(2);
LCD_EN = 1;
lcd_delay(2);
LCD_EN = 0; }
void lcd_init() //LCD的初始化
{
lcd_delay(100);
LCD_CS1=1;

LCD_CS2=1;
lcd_delay(100);
lcd_wcmd(0x3e);
lcd_wcmd(0xb8); //页地址
lcd_wcmd(0xc0); //行地址
lcd_wcmd(0x3f);
lcd_wcmd(0x40); //列地址
}
void clr_screen() //清屏操作
{
uchar j,k;
LCD_CS1=0;LCD_CS2=0;
lcd_wcmd(0xb8);
lcd_wcmd(0x40);
for(k=0;k<8;k++)
{
lcd_wcmd(page_add+k);
for(j=0;j<64;j++)
{
lcd_wcmd(lcdcol_add+j);
lcd_wdat(0x00);
}
}
}
void select(uchar x) //选择左半屏还是右半屏
{
switch(x)
{
case 1:LCD_CS1=0;LCD_CS2=1;break; //左屏,
case 2:LCD_CS1=1;LCD_CS2=0;break; //右屏,
default :LCD_CS2=0;LCD_CS1=0;
}
}
void setpos(uchar row , uchar col) //选择行,列,
{
lcd_wcmd(0xb8+row);

lcd_wcmd(0x40+col); }
void disp1(uchar code *hz) //显示汉字上半区,两个
{
uchar n;
for(n=0;n<32;n++)
lcd_wdat(*(hz+n)); }
void disp2(uchar code *hz) //显示汉字下半区 ,
{
uchar m;
for(m=32;m<64;m++)
lcd_wdat(*(hz+m)); }
void disp_pl(uint dat) //显示频率
{
uchar mm,z;
select(1);
setpos(6,0);
mm=dat/100;
mm=5*mm;
for(z=mm;z<mm+5;z++)
lcd_wdat(table[z]);
mm=(dat%100)/10;
mm=5*mm;
for(z=mm;z<5+mm;z++)
lcd_wdat(table[z]);
mm=dat%10;
mm=5*mm;
for(z=mm;z<5+mm;z++)
lcd_wdat(table[z]);
for(z=50;z<60;z++)
lcd_wdat(table[z]);

}
void clc_pl() //清除频率显示
{
uchar mm;
select(1);
setpos(6,0);
for(mm=0;mm<32;mm++)
{
lcd_wdat(0x00);
}
}
void disp_vpp(float dat) //显示峰峰值
{
uchar mm,z,mmm;
select(1);
setpos(7,0);
for(mm=60;mm<75;mm++)
{
lcd_wdat(table[mm]);
}
mmm=dat*10;
mm=mmm/10;
mm=5*mm;
for(z=mm;z<5+mm;z++)
lcd_wdat(table[z]);
for(z=75;z<80;z++)
lcd_wdat(table[z]);
mm=mmm%10;
mm=5*mm;
for(z=mm;z<5+mm;z++)
lcd_wdat(table[z]);
}
void disp_xy() //显示坐标轴
{
uchar y,x;
select(1);

for(y=0;y<8;y++)
{
setpos(y,32);
lcd_wdat(0xff);
}
setpos(3,32);
for(x=0;x<32;x++)
{
lcd_wdat(0x80);
}
select(2);
setpos(3,0);
for(x=0;x<64;x++)
{
lcd_wdat(0x80);
}
}
void disp_wave(uchar *wave) //显示波形
{
uchar xz_page,xz;
uint xz_bit;
select(1);
for(xz=32;xz<64;xz++)
{
xz_page=7-(wave[xz]/4)/8;
xz_bit=7-(wave[xz]/4)%8;
xz_bit=pow(2,xz_bit);
setpos(xz_page,xz);
lcd_wdat(xz_bit);
}
select(2);
for(xz=0;xz<64;xz++)
{
xz_page=7-(wave[xz]/4)/8;
xz_bit=7-(wave[xz]/4)%8;
xz_bit=pow(2,xz_bit);
setpos(xz_page,xz);
lcd_wdat(xz_bit);

}
}
void disp_china() //显示中文提示符
{
uchar i=0;
lcd_init();
clr_screen();
select(1);
setpos(0,0);
disp1(&hanshu);
setpos(1,0);
disp2(&hanshu);
setpos(4,0);
disp1(&pinglv);
setpos(5,0);
disp2(&pinglv); }
void disp_hslx(uchar *dat) //显示函数类型:三角/方波/锯齿波/正弦
{
select(1);
setpos(2,0);
disp1(dat);
setpos(3,0);
disp2(dat); }
void bx_init() //函数发生模块的初始化
{
EA=1;
IT0=1; //下降沿触发
EX0=1;
IT1=1;
EX1=1;
}
void main()
{

lcd_init();
clr_screen();
which_bx=&sinx[0];
disp_china();
disp_hslx(zx);
disp_pl(400);
disp_vpp(4.2);
disp_xy();
disp_wave(which_bx);
bx_init();
while(1)
{
delay_time=pl; //pl=0时,12mhz下,为400hz的波形。循环一次的时间为0.00025ms
P2=*(which_bx+kk);
kk++;
if(kk==64)
kk=0;
while(delay_time)
delay_time--;
}
}
void int0() interrupt 0 //波形选择中断服务程序
{
EX0=0;
bx_delay();
bxxz++;
if(bxxz==4)
bxxz=0;
switch(bxxz)
{
case 0 :which_bx=&sinx[0]; which_bx2=&zx[0];break;
case 1 :which_bx=&sanjiao[0];which_bx2=&sj[0];break;
case 2 :which_bx=&fangbo[0];which_bx2=&fb[0];break;
case 3 :which_bx=&juchi[0];which_bx2=&jc[0];break;

}
bx_delay();
clr_screen();
disp_china();
disp_pl(400/pl);
disp_vpp(4.2);
disp_hslx(which_bx2);
disp_xy();
disp_wave(which_bx);
while(!bx_adjust);
EX0=1;
}
void int1() interrupt 2 //频率选择
{
EX1=0;
bx_delay();
pp++;
if(pp==49)
pp=0;
switch(pp)
{
case 1 :pl=1;break;
case 2 :pl=2;break;
case 3 :pl=3;break;
case 4 :pl=4;break;
case 5 :pl=5;break;
case 6 :pl=6;break;
case 7 :pl=7; break;
case 8: pl=8;break;
case 9: pl=9;break;
case 10:pl=10;break;
case 11:pl=11;break;
case 12:pl=12;break;
case 13:pl=13;break;
case 14:pl=14;break;

case 15:pl=15;break;
case 16:pl=16;break;
case 17:pl=17;break;
case 18:pl=18;break;
case 19:pl=19;break;
case 20:pl=20;break;
case 21:pl=21;break;
case 22:pl=22;break;
case 23:pl=23;break;
case 24:pl=24;break;
case 25:pl=25;break;
case 26:pl=26;break;
case 27:pl=27;break;
case 28:pl=28;break;
case 29:pl=29;break;
case 30:pl=30;break;
case 31:pl=31;break;
case 32:pl=32;break;
case 33:pl=33;break;
case 34:pl=34;break;
case 35:pl=35;break;
case 36:pl=36;break;
case 37:pl=37;break;
case 38:pl=38;break;
case 39:pl=39;break;
case 40:pl=42;break;
case 41:pl=44;break;
case 42:pl=46;break;
case 43:pl=48;break;
case 44:pl=50;break;
case 45:pl=52;break;
case 46:pl=54;break;
case 47:pl=56;break;
case 48:pl=58;break;
case 49:pl=60;break;
default:pl=0;break;
}
bx_delay();

pl_num=1/((0.000036+0.000006*pl)*64);
clc_pl();
disp_pl(pl_num);
while(!pl_adjust);
EX1=1;
}
回复

使用道具 举报

来51学习 发表于 2019-5-22 11:28 | 显示全部楼层
你好!
1、所有和显示有关的程序都要改写程序
2、你这个是信号发生器,不是示波器
回复

使用道具 举报

gsr64 发表于 2019-5-22 17:31 | 显示全部楼层
数值型数据直接输给12864会显示乱码,只有把数值数据转换成相应的字符型数据输给12864相应的行和列才能在此位置显示出相应的字符,如下面的字符表,先给出12864相应的行列位置,再给12864输入第一行的数据,就会在此位置显示0;以此类推,要显示1就输入第二行的数据。另外利用ASCII码字库或国标汉字字库查表更加方便,ASCII码只要将数值型数据+0x30就会显示相应的数字符或英文字母。
uchar code table[]={
0x3E,0x51,0x49,0x45,0x3E, // -0-
0x00,0x42,0x7F,0x40,0x00, // -1-
0x62,0x51,0x49,0x49,0x46, // -2-
0x21,0x41,0x49,0x4D,0x33, // -3-
0x18,0x14,0x12,0x7F,0x10, // -4-
0x27,0x45,0x45,0x45,0x39, // -5-
0x3C,0x4A,0x49,0x49,0x31, // -6-
0x01,0x71,0x09,0x05,0x03, // -7-
0x36,0x49,0x49,0x49,0x36, // -8-
0x46,0x49,0x49,0x29,0x1E, // -9-
0x7F,0x08,0x08,0x08,0x7F, // -H
0x61,0x51,0x49,0x45,0x43, // -Z-
0x1F,0x20,0x40,0x20,0x1F, // -V-
0x7F,0x09,0x09,0x09,0x06, // -P-
0x00,0x36,0x36,0x00,0x00, // -:-
0x00,0x60,0x60,0x00,0x00, // -.-
回复

使用道具 举报

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

本版积分规则

QQ|手机版|小黑屋|单片机论坛 |51Hei单片机16群 联系QQ:125739409;技术交流QQ群7344883

Powered by 单片机教程网

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