【单片机】LED16*16点阵显示实验

【单片机】LED16*16点阵显示实验

  • 一、操作目的
  • 二、操作内容
  • 三、接线图
  • 四、程序清单
  • 五、代码详解

一、操作目的

  • 利用单片机并行控制LED点阵显示。
  • 掌握单片机与LED点阵块之间接口电路设计及编程。
  • 利用取模软件建立标准字库,编制程序实现点阵循环左移显示汉字。

二、操作内容

根据提供I/O地址、功能,由不同I/O口分别提供字形代码送行,列扫描信号送列扫描行,凡字形代码位“1”、列扫描信号“0”该点点亮,否则熄灭,通过逐列扫描,循环点亮字形或曲线。

三、接线图

【单片机】LED16*16点阵显示实验_第1张图片

四、程序清单

   ORG 0000H
	LJMP START
	ORG 2D80H
	XPA	EQU	0FF28H			;L-SAO-1,CTL-MODE:BING XIN KO
	XPB	EQU	0FF29H			;L-SAO-2
;---------------------------------------------------------------
	XPC	EQU	0FF2AH			;H-CODE-2
	XPCTL	EQU	0FF2BH
START:		MOV DPTR,#XPCTL		;THIS IS A PROGRAM OF L-MOVE-WORD
	MOV A,#80H
	MOVX @DPTR,A			;WR-CTL
	CALL OFFLED			;OFFLED
	CLR 00H
	MOV R6,#28H
	MOV R7,#0FFH
;----------------------------------------
X0:	  		MOV R0,#00H			;ONE-WORD-FIRST-NUM
X1:  		CALL DEL1				;QI
	INC R0					;RL-1-BIT
	mov a,r0
	anl a,#0fh
	cjne a,#00h,l2
	mov a,#10h
	add a,r0
	mov r0,a
l2:   		CJNE R0,#00H,X1
		SJMP X0
;---------------------------------------------------------------
DISPW:	    PUSH 00H				;DISP-ONE-WORD
		MOV R1,#01H			;L-NUM
		CLR C
DISP1:		MOV A,R0				;BH1
	MOV DPTR,#TAB
	MOVC A,@A+DPTR
	MOV DPTR,#XPC
	MOVX @DPTR,A
;-------------------------------------------
	mov a,#10h
	add a,r0
	MOV DPTR,#TAB
	MOVC A,@A+DPTR
	MOV P1,A
	INC R0						;BH2
;-------------------------------------------
	mov a,r0
	anl a,#0fh
	cjne a,#00h,l1
	mov a,#10h
	add a,r0
	mov r0,a
	clr c						;!!!!!
l1:			MOV DPL,R6					;XPA/XPB
	MOV DPH,R7
	MOV A,R1					;L0----L7
	CPL A
	MOVX @DPTR,A
	mov r3,#80h
	djnz r3,$
	CALL OFFLED
	MOV A,R1
	RLC A
	MOV R1,A
	JNC DISP1
	JB 00H,EXIT
;----------------------------------
	SETB 00H
	CLR C
	MOV R1,#01H
	MOV R6,#29H
	MOV R7,#0FFH
		AJMP DISP1
EXIT:		MOV R6,#28H
	MOV R7,#0ffH
	CLR 00H
	POP 00H
	RET
;---------------------------------------------------------------
DEL1:		MOV R2,#05H
DELY:		PUSH 02H
DEL2:		PUSH 02H
DEL3:		PUSH 02H
DEL4:		DJNZ R2,DEL4
	CALL DISPW
	POP 02H
	DJNZ R2,DEL3
	POP 02H
	DJNZ R2,DEL2
	POP 02H
	DJNZ R2,DELY
	RET
;---------------------------------------------------------
OFFLED:   MOV DPTR,#XPA
	MOV A,#0FFH
	MOVX @DPTR,A
	MOV DPTR,#XPB
	MOVX @DPTR,A	
	RET

五、代码详解

#include 
#include 
#include 

#define uchar unsigned char

#define com8255 XBYTE[0xff2b] //宏定义口地址
#define pa8255 XBYTE[0xff28]
#define pb8255 XBYTE[0xff29]
#define pc8255 XBYTE[0xff2a]

/*--  文字:  张  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
/*--  0x01,0x00,0xF9,0x08,0x09,0x08,0x09,0x10,0x09,0x20,0x79,0x40,0x41,0x00,0x47,0xFE,
 0x41,0x40,0x79,0x20,0x09,0x20,0x09,0x10,0x09,0x08,0x09,0x44,0x51,0x82,0x21,0x00   --*/

/*--  文字:  三  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
/*--  0x00,0x00,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00   --*/

uchar code zhang[35] = {0x01,0x00,0xF9,0x08,0x09,0x08,0x09,0x10,0x09,0x20,0x79,0x40,0x41,0x00,0x47,0xFE, 0x41,0x40,0x79,0x20,0x09,0x20,0x09,0x10,0x09,0x08,0x09,0x44,0x51,0x82,0x21,0x00};
uchar code san[35] = {0x00,0x00,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00};

void main(void)
{
	com8255 = 0x80; //控制口赋值

	while (1)
	{
		unsigned int i = 0, j = 0, k = 0, nn = 0;
		unsigned int x = 0, y = 0;

		unsigned int tag = 0;
		//张
		while (1)
		{
			for (i = 0; i < 32; i = i + 2)
			{
				x = 0, y = 0;
				j = 1 << (15 - i / 2);
				pc8255 = j >> 8;
				P1 = j - ((j >> 8) << 8);

				k = ((zhang[i]) << 8) + (zhang[i + 1]);
				for (nn = 0; nn < 8; nn++)
				{
					if (k >> nn & 1)
						x = (x << 1) + 1;
					else
						x = x << 1;
				}
				for (nn = 8; nn < 16; nn++)
				{
					if (k >> nn & 1)
						y = (y << 1) + 1;
					else
						y = y << 1;
				}

				pb8255 = ~x;
				pa8255 = ~y;
			}
			tag++;
			if (tag == 50)
				break;
		}
		tag = 0;

		//三
		while (1)
		{
			for (i = 0; i < 32; i = i + 2)
			{
				x = 0, y = 0;
				j = 1 << (15 - i / 2);
				pc8255 = j >> 8;
				P1 = j - ((j >> 8) << 8);

				k = ((san[i]) << 8) + (san[i + 1]);
				for (nn = 0; nn < 8; nn++)
				{
					if (k >> nn & 1)
						x = (x << 1) + 1;
					else
						x = x << 1;
				}
				for (nn = 8; nn < 16; nn++)
				{
					if (k >> nn & 1)
						y = (y << 1) + 1;
					else
						y = y << 1;
				}

				pb8255 = ~x;
				pa8255 = ~y;
			}
			tag++;
			if (tag == 50)
				break;
		}
		tag = 0;
	}
}

你可能感兴趣的:(单片机)