在8X8點陣式LED顯示“★”、“●”和心形圖,通過按鍵來選擇要顯示的圖形。
1. 電路原理圖
圖4.26.1
2. 硬件系統(tǒng)連線
(1). 把“單片機系統(tǒng)”區(qū)域中的P1端口用8芯排芯連接到“點陣模塊”區(qū)域中的“DR1-DR8”端口上;
(2). 把“單片機系統(tǒng)”區(qū)域中的P3端口用8芯排芯連接到“點陣模塊”區(qū)域中的“DC1-DC8”端口上;
(3). 把“單片機系統(tǒng)”區(qū)域中的P2.0/A8端子用導線連接到“獨立式鍵盤”區(qū)域中的SP1端子上;
3. 程序設(shè)計內(nèi)容
4. 匯編源程序
CNTA EQU 30H
COUNT EQU 31H
ORG 00H
LJMP START
ORG 0BH
LJMP T0X
ORG 30H
START: MOV CNTA,#00H
MOV COUNT,#00H
MOV TMOD,#01H
MOV TH0,#(65536-4000) / 256
MOV TL0,#(65536-4000) MOD 256
SETB TR0
SETB ET0
SETB EA
WT: JB P2.0,WT
MOV R6,#5
MOV R7,#248
D1: DJNZ R7,$
DJNZ R6,D1
JB P2.0,WT
INC COUNT
MOV A,COUNT
CJNE A,#03H,NEXT
MOV COUNT,#00H
NEXT: JNB P2.0,$
SJMP WT
T0X: NOP
MOV TH0,#(65536-4000) / 256
MOV TL0,#(65536-4000) MOD 256
MOV DPTR,#TAB
MOV A,CNTA
MOVC A,@A+DPTR
MOV P3,A
MOV DPTR,#GRAPH
MOV A,COUNT
MOV B,#8
MUL AB
ADD A,CNTA
MOVC A,@A+DPTR
MOV P1,A
INC CNTA
MOV A,CNTA
CJNE A,#8,NEX
MOV CNTA,#00H
NEX: RETI
TAB: DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH
GRAPH: DB 12H,14H,3CH,48H,3CH,14H,12H,00H
DB 00H,00H,38H,44H,44H,44H,38H,00H
DB 30H,48H,44H,22H,44H,48H,30H,00H
END
6. C語言源程序
#include
unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code graph[3][8]={{0x12,0x14,0x3c,0x48,0x3c,0x14,0x12,0x00},
{0x00,0x00,0x38,0x44,0x44,0x44,0x38,0x00},
{0x30,0x48,0x44,0x22,0x44,0x48,0x30,0x00}
};
unsigned char count;
unsigned char cnta;
void main(void)
{
unsigned char i,j;
TMOD=0x01;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
TR0=1;
ET0=1;
EA=1;
while(1)
{
if(P2_0==0)
{
for(i=5;i>0;i--)
for(j=248;j>0;j--);
if(P2_0==0)
{
count++;
if(count==3)
{
count=0;
}
while(P2_0==0);
}
}
}
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
P3=tab[cnta];
P1=graph[count][cnta];
cnta++;
if(cnta==8)
{
cnta=0;
}
}