1.首先在Proteus下选择我们需要的元件,AT89C51、74LS138、MATRIX-8*8-GREEN(在这里使用绿色的点阵)。在Proteus 6.9中8*8的点阵总共有四种颜色,分别为MATRIX-8*8-GREEN,MATRIX-8*8-BLUE,MATRIX-8*8-ORANGE ,MATRIX-8*8-RED。
在这里请牢记:红色的为上列选下行选;其它颜色的为上行选下列选!而所有的点阵都是高电平选中列,低电平选中行!也就是说如果某一个点所处的行信号为低,列信号为高,则该点被点亮!此结论是我们编程的基础。
2.在选择完以上三个元件后,我们开始布线,具体如下图:
这里P2是列选,P3连接38译码器后作为行选。
选择38译码器的原因:38译码器每次可输出相应一个I/O口的低电平,正好与点阵屏的低电平选中行相对,并且节省了I/O口,大大方便了我们的编程和以后的扩展。
3.下面让我们把它点亮,先看一个简单的程序:
(将奇数行偶数列的点点亮,效果如下图)
下面是源代码薯配裤:
/************8*8LED点阵屏显示*****************/
#include<reg51.h>
void delay(int z) //延时函数
{
int x,y
for(x=0x<zx++)
for(y=0y<110y++)
}
void main()
{
while(1)
{
P3=0 //行选,选择第一行
P2=0x55//列选,即该行显示的数据
delay(5) //延时
/*****下同*****/
P3=2//第三行
P2=0x55
delay(5)
P3=4//第五行
P2=0x55
delay(5)
P3=6 //第七行
P2=0x55
delay(5)
}
}
上面的程序实现了将此8*8点阵的奇数行偶数列的点点亮的功能。重点让我们看while循环内,首先是行选P3=0,此时38译码器的输入端为000,则输出端为01111111,即B0端为低电平,此时选中了点阵屏的第一行,接着列选我们给P2口赋0x55,即01010101,此时又选中了偶数列,紧接着延时。然后分别对第三、五、七行进行相同的列选。这样就点亮了此点阵屏奇数行偶数列交叉的点。
完成这个程序,我们会发现其实点阵屏的原理是如此简单,和数码管的动态显示非常相似,只不过换了一种方式而已。
对不起啦,我传了三次图片都没传上,郁闷哪!希望你能理解哈!数简 不过卖物我有传一份WORD文档在我的空间里面
ORG 00H你参考一下这个吧,兄弟没有原理图这个程序没办法给你解释清楚的,还唤森销有不加C程序能运行
START:MOV A,#00H 清除屏幕
MOV P0,A
MOV P2,A
CALL DIS 调用显示子程序
CALL DELAY 调用延时子程序
CALL MOVE 调用左移子程序
JMP START
DIS: MOV R2,#04H 每个画面2个字,8个字分4次显示
MOV 20H,#00 取码指针暂存地址20H初值为00
D4: MOV R4,#00H74LS154扫描指针初值
MOV R1,#0FFH 每幕停留的时间
D5: MOV R6,#32 每幕两个字,32个数据码
MOV R0,20H 取码指针存入R0
D2: CALL READ1 调用取码子程序
INC R4 扫描下一列
DJNZ R6,D2 显示1幕?
MOV R4,#00 清除74LS154扫描指针为00
DJNZ R1,D5 每幕停留时间到了?
MOV 20H,R0 保留取码指针存入20H地址
DJNZ R2,D4 2幕显示完毕了?
RET
MOVE:
MOV 20H,#00 取码指针暂存地址20H初值和游为00
MOV R4,#00H 74LS154扫描指针初值
M1: MOV R1,#0FFH每幕停留时间
M2: MOV R6,#32 每幕两个字,32个数据码
MOV R0,20H 取码指针存入R0
M3: CALL READ1 调用春肆取码子程序
INC R4 扫描下一列
DJNZ R6,M3 显示1幕?
MOV R4,#00 清除74LS154扫描指针为00
DJNZ R1,M2 每幕停留时间到了?
MOV A,20H 取码指针载入A
ADD A,#08H 加8
MOV 20H,A 再存入20H地址取码指针
XRL A,#128 8个字是否都左移完毕了
JNZ M1
RET
READ1:MOV A,R4 扫描指针载入A
MOV P1,A 输出至P1扫描列
MOV A,R0 取码指针载入A
MOV DPTR,#TABLE 数据指针指到TABLE
MOVC A,@A+DPTR 到TABLE取上半部的数据码
MOV P0,A 输出至P0显示
INC R0 取下一个码
MOV A,R0 取码指针载入A
MOV DPTR,#TABLE 数据指针指到TABLE
MOVC A,@A+DPTR 到TABLE 取下半部的数据码
MOV P2,A 输出至p2显示
INC R0 取码值加1
MOV R3,#25 延时
DJNZ R3,$
MOV A,#00H 清除屏幕
MOV P0,A
MOV P2,A
RET
DELAY:
MOV R3,#200
D7: MOV R5,#248
DJNZ R5,$
DJNZ R3,D7
RET
1 "振"
TABLE:DB 08H,40H,08H,42H
DB 08H,81H,0FFH,0FEH
DB 09H,02H,0AH,0CH
DB 7FH,0F0H,49H,00H
DB 49H,0FFH,49H,02H
DB 49H,0E0H,49H,18H
DB 59H,14H,0CBH,26H
DB 41H,44H,00H,00H
2 "兴"
DB 00H,80H,00H,81H
DB 20H,82H,18H,84H
DB 0CH,88H,00H,98H
DB 0C0H,80H,3CH,80H
DB 00H,80H,01H,90H
DB 06H,88H,18H,84H
DB 60H,86H,01H,83H
DB 00H,80H,00H,00H
3 "中"
DB 00H,00H,1FH,0C0H
DB 10H,80H,10H,80H
DB 10H,80H,10H,80H
DB 10H,80H,0FFH,0FFH
DB 10H,80H,10H,80H
DB 10H,80H,10H,80H
DB 10H,80H,3FH,0C0H
DB 10H,00H,00H,00H
4 "华"
DB 00H,20H,02H,20H
DB 04H,20H,08H,20H
DB 3FH,0A0H,0C0H,20H
DB 02H,20H,04H,0FFH
DB 08H,20H,0FFH,20H
DB 10H,0A0H,20H,0A0H
DB 60H,0A0H,03H,0A0H
DB 00H,20H,00H,00H
5 "电"
DB 00H,00H,1FH,0E0H
DB 12H,40H,12H,40H
DB 12H,40H,12H,40H
DB 0FFH,0FCH,12H,42H
DB 12H,42H,12H,42H
DB 12H,42H,3FH,0E2H
DB 10H,02H,00H,0EH
DB 00H,00H,00H,00H
6 "子"
DB 01H,00H,01H,00H
DB 41H,00H,41H,00H
DB 41H,00H,41H,02H
DB 41H,01H,47H,0FEH
DB 45H,00H,49H,00H
DB 51H,00H,61H,00H
DB 01H,00H,03H,00H
DB 01H,00H,00H,00H
7 "事"
DB 20H,20H,20H,20H
DB 2EH,0A8H,2AH,0A8H
DB 2AH,0A8H,2AH,0AAH
DB 2AH,0A9H,0FFH,0FEH
DB 2AH,0A8H,2AH,0A8H
DB 2AH,0A8H,2AH,0A8H
DB 2EH,0FCH,60H,20H
DB 20H,20H,00H,00H
8 "业"
DB 00H,02H,08H,02H
DB 06H,02H,01H,0E2H
DB 00H,02H,0FFH,0FEH
DB 00H,02H,00H,02H
DB 00H,02H,0FFH,0FEH
DB 00H,22H,00H,0C2H
DB 03H,02H,0CH,06H
DB 00H,02H,00H,00H
END
利用8X8点阵显示数字0到9的数字。
2. 电路原理图
图4.25.1
3. 硬件系统连线
(1). 把“单片机系统”区域中的P3端口用8芯排芯连接到“点阵模块”区域中的“DR1-DR8”端口上;
(2). 把“单片机系统”区域中的P1端口用8芯排芯连接到“点阵模块”区域中的“DC1-DC8”端口上;
4. 程序设计内容
(1). 数字0-9点阵显示代码的形成
如下图所示,假设显示数字“0”
1 2 3 4 5 6 7 8
● ● ●
● ●
● ●
● ●
● ●
● ●
● ● ●
00 00 3E 41 41 41 3E 00
因此,形成的列代码为 00H,00H,3EH,41H,41H,3EH,00H,00H;只要把这些代码分别送到相应的列线上面,即可实现“0”的数字显示。
送显示代码过程如下所示
送第一列线代码到P3端口,同时置第一行线为“0”,其它行线为“1”,延时2ms左右,送第二列线代码到P3端口,同时置第二行线为“0”,其它行线为“1”,延时2ms左右,如此下去,直到送完最后一列代码,又从头开始送。
数字“1”代码建立如下图所示1 2 3 4 5 6 7 8
●
● ●
●
●
●
●
● ● ●
其显示代码为 00H,00H,00H,00H,21H,7FH,01H,00H 由上到下7~0 ,21H=00100001B
数字“2”代码建立如下图所示
1 2 3 4 5 6 7 8
● ● ●
● ●
●
●
● ● ● ●
●
● ● ● ● ●
00H,00H,27H,45H,45H,45H,39H,00H
数字“3”代码建立如下图所示
1 2 3 4 5 6 7 8
迹巧
● ● ●
● ●
●
● ● ●
●
● ●
● ● ●
00H,00H,22H,49H,49H,49H,36H,00H
数字“4”代码建立如下图所示
1 2 3 4 5 6 7 8
●
● ●
● ●
● ●
● ● ● ● ●
●
●
00H,00H,0CH,14H,24H,7FH,04H,00H
数字“5”代码建立如下姿租键图所示
1 2 3 4 5 6 7 8
● ● ● ● ●
●
● ● ● ●
●
●
● ●
● ● ●
00H,00H,72H,51H,51H,51H,4EH,00H
数字“6”代码建立如下图所示
1 2 3 4 5 6 7 8
● ● ●
● ●
●
● ● ● ●
● ●
● ●
● ● ●
00H,00H,3EH,49H,49H,49H,26H,00H
数字“7”代码建立如下图所示
1 2 3 4 5 6 7 8
● ● ● ● ●
●
●
●
●
●
●
00H,00H,40H,40H,40H,4FH,70H,00H
数字“8”代码建立如下图所示
1 2 3 4 5 6 7 8
● ● ●
● ●
● ●
● ● ●
● ●
● ●
● ● ●
00H,00H,36H,49H,49H,49H,36H,00H
数字“9”代码建立如下图所示
1 2 3 4 5 6 7 8
● ● ●
型掘 ● ●
● ●
● ● ● ●
●
● ●
● ● ●
00H,00H,32H,49H,49H,49H,3EH,00H
5. 汇编源程序
TIM EQU 30H
CNTA EQU 31H
CNTB EQU 32H
ORG 00H
LJMP START
ORG 0BH
LJMP T0X
ORG 30H
START: MOV TIM,#00H
MOV CNTA,#00H
MOV CNTB,#00H
MOV TMOD,#01H
MOV TH0,#(65536-1000)/256 //原文设定的3000太“闪”了
MOV TL0,#(65536-1000) MOD 256
SETB TR0
SETB ET0
SETB EA
SJMP $
T0X:
MOV TH0,#(65536-1000)/256
MOV TL0,#(65536-1000) MOD 256
MOV DPTR,#TAB
MOV A,CNTA
MOVC A,@A+DPTR
MOV P3,A
MOV DPTR,#DIGIT
MOV A,CNTB
MOV B,#8
MUL AB
ADD A,CNTA
MOVC A,@A+DPTR
MOV P1,A
INC CNTA
MOV A,CNTA
CJNE A,#8,NEXT
MOV CNTA,#00H
NEXT: INC TIM
MOV A,TIM
CJNE A,#250,NEX
MOV TIM,#00H
INC CNTB
MOV A,CNTB
CJNE A,#10,NEX
MOV CNTB,#00H
NEX: RETI
TAB: DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH
DIGIT: DB 00H,00H,3EH,41H,41H,41H,3EH,00H
DB 00H,00H,00H,00H,21H,7FH,01H,00H
DB 00H,00H,27H,45H,45H,45H,39H,00H
DB 00H,00H,22H,49H,49H,49H,36H,00H
DB 00H,00H,0CH,14H,24H,7FH,04H,00H
DB 00H,00H,72H,51H,51H,51H,4EH,00H
DB 00H,00H,3EH,49H,49H,49H,26H,00H
DB 00H,00H,40H,40H,40H,4FH,70H,00H
DB 00H,00H,36H,49H,49H,49H,36H,00H
DB 00H,00H,32H,49H,49H,49H,3EH,00H
END
6. C语言源程序
#include <AT89X52.H>
unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}
unsigned char code digittab[10][8]={ {0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0
{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8
{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00} //9
}
unsigned int timecount
unsigned char cnta
unsigned char cntb
void main(void)
{
TMOD=0x01
TH0=(65536-1000)/256
TL0=(65536-1000)%256
TR0=1
ET0=1
EA=1
while(1)
{
}
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-1000)/256
TL0=(65536-1000)%256
P3=tab[cnta]
P1=digittab[cntb][cnta]
cnta++
if(cnta==8)
{
cnta=0
}
timecount++
if(timecount==333)
{
timecount=0
cntb++
if(cntb==10)
{
cntb=0
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)