1.匯編源程序
ORG 0000H
AJMP MAIN
MAIN: MOVR0,#32 ;循環次數32次
MOV R1,#40H ;首址
MOV A,#0H ;要存入地址的值
SJMP LOOP
LOOP: MOV@R1,A ;A->(40H)
MOV P1,@R1 ;P1輸出(40H)值
DELAY: MOVR3,#10 ;延時1秒
D1: MOVR4,#200
D2: MOVR5,#250
D3: DJNZR5,D3
DJNZ R4,D2
DJNZ R3,D1
INC R1 ;R1指向下一地址
ADD A,#05H ;A+5->A
DJNZ R0,LOOP ;是否達到循環次數,沒有則繼續循環
END
2.C51源程序
#include<REG51.h>
/*延時程序*/
void delay(int n)
{
inti,j;
for(;n>0;n--)
{
for(i=0;i<500;i--)
for(j=0;j<250;j--);
}
}
void main(){
int len;
unsigned char data *ptr;
unsigned int n;
n=0x00;
ptr=0x40;
for(len=0;len<32;len++)//將0,5,15……155依次填入以40H為首地址的32個單元格里。
{
*ptr=5*n;
n++;
ptr++;
}
ptr=0x40;
for(len=0;len<32;len++)//將以40H為首地址的32個單元格里的數據依次輸出。
{
P1=*ptr;
ptr++;
delay(1);
}
}
|