ORG 0000H
LJMP INIT
ORG 0100H
INIT: MOV DPTR,#SIN // 指向正弦表
MAIN: MOV A,#00H // A清零
ORL P1,#0F0H // 指示燈復(fù)位
JNB P1.0,SQUARE // 選擇方波
JNB P1.1,SAWTOOTH // 選擇鋸齒波
JNB P1.2,TRIANG // 選擇三角波
JNB P1.3,SINE // 選擇正弦波
SJMP MAIN
SQUARE: CLR P1.4 // 方波
SQULOOP:JB P1.0,MAIN // 判斷是否返回
MOV A,#00H // 下降沿
MOV P0,A
LCALL DELAY1
MOV A,#0FFH // 上升沿
MOV P0,A
LCALL DELAY1
SJMP SQULOOP
SAWTOOTH:CLR P1.5 // 鋸齒波
SAWLOOP:JB P1.1,MAIN // 判斷是否返回
MOV P0,A
INC A // A+1
LCALL DELAY1
SJMP SAWLOOP
TRIANG: CLR P1.6 // 三角波
UPLOOP: JB P1.2,MAIN // 判斷是否返回
MOV P0,A
INC A // A+1
LCALL DELAY1
CJNE A,#0FFH,UPLOOP // 判斷是否到大值
DOWNLOOP:JB P1.2,MAIN // 判斷是否返回
MOV P0,A
DEC A // A-1
LCALL DELAY1
CJNE A,#00H,DOWNLOOP // 判斷是否到最小值
SJMP UPLOOP
SINE: CLR P1.7 // 正弦波
SINLOOP:JB P1.3,MAIN // 判斷是否返回
MOV R0,A // 保護(hù)A
MOVC A,@A+DPTR // 查表
MOV P0,A
MOV A,R0 // 恢復(fù)A
INC A // A+1
LCALL DELAY1
SJMP SINLOOP
SIN: DB 80H, 83H, 86H, 89H, 8DH, 90H, 93H, 96H // 正弦表
DB 99H, 9CH, 9FH, 0A2H,0A5H,0A8H,0ABH,0AEH
DB 0B1H,0B4H,0B7H,0BAH,0BCH,0BFH,0C2H,0C5H
DB 0C7H,0CAH,0CCH,0CFH,0D1H,0D4H,0D6H,0D8H
DB 0DAH,0DDH,0DFH,0E1H,0E3H,0E5H,0E7H,0E9H
DB 0EAH,0ECH,0EEH,0EFH,0F1H,0F2H,0F4H,0F5H
DB 0F6H,0F7H,0F8H,0F9H,0FAH,0FBH,0FCH,0FDH
DB 0FDH,0FEH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH
DB 0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FEH,0FDH
DB 0FDH,0FCH,0FBH,0FAH,0F9H,0F8H,0F7H,0F6H
DB 0F5H,0F4H,0F2H,0F1H,0EFH,0EEH,0ECH,0EAH
DB 0E9H,0E7H,0E5H,0E3H,0E1H,0DEH,0DDH,0DAH
DB 0D8H,0D6H,0D4H,0D1H,0CFH,0CCH,0CAH,0C7H
DB 0C5H,0C2H,0BFH,0BCH,0BAH,0B7H,0B4H,0B1H
DB 0AEH,0ABH,0A8H,0A5H,0A2H,9FH, 9CH, 99H
DB 96H, 93H, 90H, 8DH, 89H, 86H, 83H, 80H
DB 80H, 7CH, 79H, 78H, 72H, 6FH, 6CH, 69H
DB 66H, 63H, 60H, 5DH, 5AH, 57H, 55H, 51H
DB 4EH, 4CH, 48H, 45H, 43H, 40H, 3DH, 3AH
DB 38H, 35H, 33H, 30H, 2EH, 2BH, 29H, 27H
DB 25H, 22H, 20H, 1EH, 1CH, 1AH, 18H, 16H
DB 15H, 13H, 11H, 10H, 0EH, 0DH, 0BH, 0AH
DB 09H, 08H, 07H, 06H, 05H, 04H, 03H, 02H
DB 02H, 01H, 00H, 00H, 00H, 00H, 00H, 00H
DB 00H, 00H, 00H, 00H, 00H, 00H, 01H, 02H
DB 02H, 03H, 04H, 05H, 06H, 07H, 08H, 09H
DB 0AH, 0BH, 0DH, 0EH, 10H, 11H, 13H, 15H
DB 16H, 18H, 1AH, 1CH, 1EH, 20H, 22H, 25H
DB 27H, 29H, 2BH, 2EH, 30H, 33H, 35H, 38H
DB 3AH, 3DH, 40H, 43H, 45H, 48H, 4CH, 4EH
DB 51H, 55H, 57H, 5AH, 5DH, 60H, 63H, 66H
DB 69H, 6CH, 6FH, 72H, 75H, 78H, 7bH, 7eH
DELAY100: MOV 30H,#195 //延時(shí)100ms
MOV 31H,#133
NEXT100: DJNZ 31H,NEXT100
DJNZ 30H,NEXT100
RET
DELAY1: MOV 30H,#2 //延時(shí)1ms
MOV 31H,#234
NEXT1: DJNZ 31H,NEXT1
DJNZ 30H,NEXT1
RET
END
效果圖方波
鋸齒波
三角波
正弦波
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧