本帖最后由 古朩寒湶 于 2012-5-18 13:38 编辑
ORG 00H
SQU_K BIT P3.4
SAW_K BIT P3.5
TRI_K BIT P3.6
SIN_K BIT P3.7
SQU_L BIT P1.0
SAW_L BIT P1.1
TRI_L BIT P1.2
SIN_L BIT P1.3
START:
MOV P1, #0FFH
MOV P2, #0FFH
MOV P3, #0FFH
MOV DPTR,#SIN_TAB
MAIN:
MOV P0, #00H
JNB SQU_K,S1
SETB SQU_L
JNB SAW_K,S2
SETB SAW_L
JNB TRI_K,S3
SETB TRI_L
JNB SIN_K,S4
SETB SIN_L
SJMP MAIN
S1: CLR SQU_L
LCALL SQUARE
SJMP MAIN
S2: CLR SAW_L
LCALL SAWTOOTH
SJMP MAIN
S3: CLR TRI_L
LCALL TRIANG
SJMP MAIN
S4: CLR SIN_L
LCALL SINWAVE
SJMP MAIN
SQUARE:
MOV R0,#00H
J11: MOV P0,#0FFH
MOV P2,#0FFH
MOV A,P2
CPL A
MOV R3,A
L11: DEC R3
CJNE R3,#255,L11
INC R0
INC R0
CJNE R0,#254,J11
MOV R0,#00H
J12: MOV P0,#00H
MOV P2,#0FFH
MOV A,P2
CPL A
MOV R3,A
L12: DEC R3
CJNE R3,#255,L12
INC R0
INC R0
CJNE R0,#254,J12
MOV R0,#00H
RET
SAWTOOTH:
; MOV DPTR,#0DFFFH
; MOVX @DPTR,A
CLR A
MOV R7,A
J21: MOV P0,R7
MOV P2,#0FFH
MOV A ,P2
CPL A
MOV R3,A
L21: DEC R3
CJNE R3,#255,L21
INC R7
INC R7
INC R7
INC R7
CJNE R7,#251,J21
RET
TRIANG:
MOV R7,#00H
J31: MOV P0,R7
MOV P2,#0FFH
MOV A,P2
CPL A
MOV R3,A
L31: DEC R3
CJNE R3,#255,L31
INC R7
INC R7
INC R7
CJNE R7,#253,J31
J32: MOV P0,R7
MOV P2,#0FFH
MOV A,P2
CPL A
MOV R3,A
L32: DEC R3
CJNE R3,#255,L32
DEC R7
DEC R7
DEC R7
CJNE R7,#00H,J32
RET
SINWAVE:
MOV R0,#00H
K41: MOV A,R0
MOVC A,@A+DPTR
MOV P0,A
INC R0
MOV P2,#0FFH
MOV A,P2
CPL A
MOV R3,A
L41: DEC R3
CJNE R3,#255,L41
CJNE R0,#92,K41
K42: DEC R0
MOV A,R0
MOVC A,@A+DPTR
MOV P0,A
MOV P2,#0FFH
MOV A,P2
CPL A
MOV R3,A
L42: DEC R3
CJNE R3,#255,L42
CJNE R0,#0,K42
RET
SIN_TAB:
DB 0,0,0,0
DB 1,1,2,3,4,5,6,8
DB 9,11,13,15,17,19,22,24
DB 27,30,33,36,39,42,46,49
DB 53,56,60,64,68,72,76,80
DB 84,88,92,97,101,105,110,114
DB 119,123,128,132,136,141,145,150
DB 154,158,163,167,171,175,179,183
DB 187,191,195,199,202,206,209,213
DB 216,219,222,225,228,231,233,236
DB 238,240,242,244,246,247,249,250
DB 251,252,253,254,254,255,255,255
END
|