www.pudn.com > p4.rar > P4.ASM


 
	;WRITE By chenhaocheng. 
	;2006.9.18 
	    
	COUNT	EQU	20H 
	TEMP	EQU	25H 
	LED	EQU	26H 
	RL0	EQU	21H 
	RL1	EQU	22H 
	RL2	EQU	23H 
        D0 DATA 27H 
        D1 DATA 28H 
        D2 DATA 29H 
        dppl equ 30h 
        dpph equ 31h 
        RS	BIT	P3.7 
	RW	BIT	P3.6 
	EN	BIT	P3.5 
	lcd7 bit p2.7 
	lcd6 bit p2.6 
	lcd5 bit p2.5 
	lcd4 bit p2.4 
	ORG	00H 
	JMP	BEGIN 
	ORG	0BH 
	JMP	TIMER0 
        org    23h 
        jmp    rs232 
	ORG	150H 
BEGIN:	 
        MOV	SP,#50H     
	MOV     TEMP,#120 
	MOV	LED,#0feH 
	MOV	TMOD,#20h 
	mov scon,#50h 
	mov pcon,#80h 
       	MOV	TH0,#0 
	MOV	TL0,#0 
	mov th1,#0fdh 
	SETB	ET0 
	SETB	TR0 
        setb    tr1 
        setb   es 
	setb	EA 
       call inilcd 
       mov dptr,#cg1 
       call display 
        setb p3.2 
        setb p3.3 
        setb p3.4 
        setb p1.4 
LOOP:	 
        JNB	P3.2,bt1 
	JNB	P3.3,bt2 
	JNB	P3.4,bt3 
	jnb p1.4,bt4 
	JMP	LOOP 
bt1: 
    call dll 
    JNB	P3.2,bt11 
    jmp loop 
bt11: 
    JNB	P3.2,$ 
    jmp sw1 
    jmp $ 
bt2: 
    call dll 
    JNB	P3.3,bt22 
    jmp loop 
bt22: 
    JNB	P3.3,$ 
    jmp sw2 
    jmp $ 
bt3: 
    call dll 
    JNB	P3.4,bt33 
bt33: 
    JNB	P3.4,$ 
    jmp sw3 
    jmp $ 
bt4: 
    call dll 
    jnb p1.4,bt88 
bt88: 
    jnb p1.4,$ 
    jmp sw4 
    jmp $ 
 
sw1: 
     
    cpl tr0 
    mov sbuf,'1' 
    mov dptr,#cg2 
    call display 
    jmp loop 
sw2: 
    cpl tr0 
    mov sbuf,"2" 
    mov dptr,#cg3 
    call display 
    jmp loop 
sw3: 
    cpl tr0 
    mov sbuf,"3" 
    mov dptr,#cg4 
    call display 
    jmp loop 
sw4: 
    cpl tr0 
    mov sbuf,"4" 
    mov dptr,#cg5 
    call display 
    jmp loop 
 
inilcd: 
  call wait 
  mov a,#28h 
  call wc 
  mov a,#28h 
  call wc 
  mov a,#0ch 
  call wc 
  mov a,#06h 
  call wc 
  mov a,#01h 
  call wc 
  ret 
 
wc: 
  call wait 
  clr en 
  clr rs 
  clr rw 
  jmp comm 
wd: 
  call wait 
  clr en 
  setb rs 
  clr rw 
comm: 
  ;mov P2,a 
  rlc a 
  mov lcd7,c 
  rlc a 
  mov lcd6,c 
  rlc a 
  mov lcd5,c 
  rlc a 
  mov lcd4,c 
  setb en 
  clr en 
  rlc a 
  mov lcd7,c 
  rlc a 
  mov lcd6,c 
  rlc a 
  mov lcd5,c 
  rlc a 
  mov lcd4,c 
  setb en 
  clr en 
  ret 
 
wait: 
  clr en 
  clr rs 
  setb rw 
  setb lcd7 
loop1: 
  setb en 
  mov c,lcd7 
  clr en 
  setb en 
  clr en 
  jc loop1 
  ret 
 
display: 
  mov count,#16 
  mov dpph,dph 
  mov dppl,dpl 
  mov a,#01h 
  call wc 
  mov a,#80h 
  call wc 
loop2: 
  clr a 
  movc a,@a+dptr 
  inc dptr 
  call wd 
  djnz count,loop2 
  mov dpl,dppl 
  mov dph,dpph 
  mov count,#16 
  mov a,#0c0h 
  call wc 
loop3: 
  clr a 
  movc a,@a+dptr 
  call wd 
  inc dptr 
  djnz count,loop3 
  ret 
 
DELAY:	MOV	D0,#012H 
LP1:	MOV	D1,#0FFH 
LP2:	MOV	D2,#0FFH 
LP3:	DJNZ	D2,LP3 
	DJNZ	D1,LP2 
	DJNZ	D0,LP1 
	RET 
   
dll:	 
        MOV	RL0,#02 
dl1:	MOV	RL1,#50 
dl2:	MOV	RL2,#50 
dl3:	DJNZ	RL2,dl3 
	DJNZ	RL1,dl2 
	DJNZ	RL0,dl1 
	RET 
 
TIMER0:	CLR	EA 
	PUSH	A 
        PUSH    B 
	MOV	TL0,#0 
	MOV	TH0,#0 
	DJNZ	TEMP,EXIT 
	MOV	TEMP,#120 
	MOV	A,LED 
	MOV	P0,A 
	RL	A 
	MOV	LED,A 
        ;cpl P0 
        ;cpl p3.6 
EXIT:	POP	A 
        POP     B 
	SETB	EA 
	RETI 
 
rs232:  
        clr ea 
        jnb ti,rxd 
        clr ti 
rxd: 
        jnb ri,jiesu 
        mov R6,sbuf 
        clr ri 
jiesu: 
        setb ea 
        reti 
 
cg1:   DB "  Chenhaocheng  " 
cg2:   db "Wo ai ni Yatou  " 
cg3: db"TTTTTTTTTTTTTTTT" 
cg4: db"PPPPPPPPPPPPPPPP" 
cg5: db"EEEEEEEEEEEEEEEE" 
	END