内容发布更新时间 : 2024/11/15 4:33:03星期一 下面是文章的全部内容请认真阅读。
单片机设计实训
0x3e,0x86,0x86,0x06,0xfe,0x04,0x00,0x00,/*图4*/ /*94*/ 0x00,0x00,0x00,0x7f,0x33,0x33,0xff,0xff,
0x00,0x00,0x00,0xc7,0x1c,0x00,0xc7,0xcc, 0x1b,0x1b,0x33,0xf3,0xc3,0x00,0x00,0x00,
0x30,0x01,0x07,0x1c,0xf8,0x00,0x00,0x00,/*形5*/ /*98*/ 0x00,0x00,0x01,0x01,0x01,0x19,0x1f,0x18, 0x00,0x00,0x80,0xf0,0xfc,0x80,0xfc,0x0c, 0x1f,0x08,0x12,0x76,0xc4,0x00,0x00,0x00,
0xf8,0x08,0x4c,0x67,0x23,0x01,0x00,0x00,/*点6*/ /*9c*/ 0x00,0x00,0x00,0xfd,0x67,0x68,0x79,0x6f, 0x00,0x00,0x60,0x60,0xff,0xe0,0xb0,0xfc, 0x6d,0x7b,0x67,0x60,0x60,0x40,0x00,0x00,
0xb0,0xfc,0xff,0x30,0x30,0x30,0x00,0x00,/*阵7*/ /*a0*/ 0x00,0x10,0x30,0x70,0xb0,0x10,0x10,0x10, 0x00,0x00,0x18,0x24,0x46,0x42,0x02,0x06, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xf0,
0x06,0x0c,0x00,0x08,0x10,0x60,0x22,0x7e,/*12 8*/ /*a4*/ 0x00,0x00,0x38,0x62,0x42,0x42,0x62,0x36, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63, 0x18,0x1c,0x26,0x46,0x42,0x42,0x43,0x3e,
0x32,0x34,0x18,0x08,0x1c,0x24,0x26,0x47,/*8x 9*/ /*a8*/ 0x00,0x00,0x06,0x08,0x10,0x20,0x20,0x60, 0x00,0x00,0x00,0x04,0x0c,0x14,0x14,0x24, 0x5e,0x62,0x42,0x43,0x43,0x42,0x62,0x3c,
0x24,0x44,0x44,0x7f,0x04,0x04,0x04,0x04,/*64 10*/ /*ac*/ 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55, 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55, 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,
0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,/*....11*/ /*b0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,/*全黑12*/ /*b4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*全白13*/ /*b8*/ 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
14
单片机设计实训
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*上边14*/ /*bc*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,/*下边15*/ /*c0*/ 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*左边16*/ /*c4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,/*右边17*/ /*c8*/ 0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*左上18*/ /*cc*/ 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xff,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,/*右上19*/ /*d0*/ 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,/*左下20*/ /*d4*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xff /*右下21*/ };
void r_st(uchar w);
void wdata(bit cd_flag,uchar d); /*数据写操作*/ void dmod(uchar x0,uchar x1,uchar c); void smod(uchar x1,uchar c); void nmod(uchar c);
/* 使用寄存0 组 */
#pragma REGISTERBANK(0) void soft_10ms()
15
单片机设计实训
{
register int i;
for(i=0;i<711;i++); }
/* 初始化 */ void initcomm(void) {
IE=0;
P0=0xff; P1=0xff; P2=0xff; P3=0xff;
TMOD=0x11; TH0 = 0; TL0 = 0; TR0 = 1; ET0 = 1; EA = 1; }
/* 初始化 lcd240128 */ void initlcd(void) {
dmod(0x00,0x00,0x40); /*文本显示区域首地址*/
dmod(0x1e,0x00,0x41); /*文本显示宽度和一行显示字节数*/ dmod(0x00,0x08,0x42); /*图形显示区域首地址*/
dmod(0x1e,0x00,0x43); /*图形显示宽度,一行显示所占字节*/
dmod(0x03,0x00,0x22); /*cgram首地址 00011 100000000 000 = 1c00h*/ nmod(0xa7); /*光标形状设置*/
nmod(0x80); /*显示方式:逻辑“或”合成*/
nmod(0x9c); /*显示开关设置,开文本和图形显示*/ }
/* lcd 清0*/ void clear(void) {
dmod(0x00,0x00,0x24); /*显示存储器首地址*/ nmod(0xb0); /*自动写方式*/ for (i = 0;i<=0x2000;i++) {
r_st(3); /*等待自动写状态*/
16
单片机设计实训
wdata(0,0); }
nmod(0xb2); /*自动写结束*/ }
/**************************************************** 读状态字
cd_flag = 1 读命令通到。 = 0 读数据通到。
w = 0 指令读,写状态, 返回1 准备好 返回0 忙。 w = 1 数据读,写状态, 返回1 准备好 返回0 忙。 w = 2 数据自动读状态, 返回1 准备好 返回0 忙。 w = 3 数据自动写状态, 返回1 准备好 返回0 忙。 w = 5 控制运行检测可能性,返回1 准备好 返回0 忙。 w = 6 屏读/栲贝出错状态, 返回1 正确 返回0 出错。
w = 7 闪烁状态检测, 返回1 正常显示 返回0 关显示。 ******************************************************/ void r_st (uchar w) {
uchar data i = 0; uchar data c; cd = 1;
lcdbus = 0xff; ce = 0; while(--i) {
rd = 0; c = lcdbus; rd = 1; ce = 1;
if ((w==1)&&((c&3)==3)) return;
if((w==3)&&(c&8)) return; } }
void wdata(bit cd_flag,uchar d) /*数据写操作*/ {
cd = cd_flag; lcdbus = d; ce = 0;
17
单片机设计实训
wr = 0; wr = 1; ce = 1; cd = 0; }
/*双参数指令*/
void dmod(uchar x0,uchar x1,uchar c) {
r_st(1); wdata(0,x0); r_st(1); wdata(0,x1); r_st(1); wdata(1,c); }
/*单参数指令*/
void smod(uchar x1,uchar c) {
r_st(1); wdata(0,x1); r_st(1); wdata(1,c); }
/*无参数指令*/ void nmod(uchar c) {
r_st(1); wdata(1,c); }
/************************************************************* 建立CGRAM 函数(图形方式) *p 汉字库字符首地址
*************************************************************/ void cgram(uchar code *p) {
dmod(0x00,0x1c,0x24);
18