AT89C2051+AD7545正弦信號發(fā)生器
;說明:
;1.本程序使用AT89C2051單片機(jī)驅(qū)動DA轉(zhuǎn)換器AD7545輸出單相50Hz正弦波信號 ;
;2.在P3.5口輸出與正弦波同相同步的方波信號,該方波信號可用于在正弦信號 ;
;的過零處將正弦信號切斷. ;
;作者:Free Zheng ;
;********************************************************************;
DACL EQU P1 ;定義低8位數(shù)據(jù)輸出口
DACH EQU P3 ;定義高8位數(shù)據(jù)輸出口
DASHUT EQU 00H ;數(shù)據(jù)
LED EQU P3.7 ;定義指示燈輸出口
ORG 00H ;起始地址
AJMP MAIN ;跳轉(zhuǎn)至主程序
ORG 03H ;外部中斷0入口
RETI ;中斷返回
ORG 0BH ;定時器0中斷入口
RETI ;直接返回
ORG 13H ;外部中斷1入口
RETI ;直接返回
ORG 1BH ;定時器1中斷入口
RETI ;直接返回
ORG 23H ;串口中斷入口
RETI ;直接返回
ORG 30H ;主程序入口
MAIN: MOV DACL,#DASHUT ;數(shù)據(jù)輸出口輸出0
MOV DACH,#DASHUT ;數(shù)據(jù)輸出口輸出0
MOV R0,#0 ;R0=0
MOV R1,#0 ;R1=0
MOV R2,#40H ;R2=40H
START:
NOP ;空操作,用于延時
NOP
NOP
NOP
NOP
NOP
LABEL3:
MOV DPTR,#SIN1 ;正弦函數(shù)表格地址
MOV A,R0 ;把R0里面的數(shù)據(jù)送累加器
MOV DPL,R0 ;數(shù)據(jù)指針寄存器低8位
MOVC A,@A+DPTR ;查表
MOV R7,A ;所得值送入R7
INC R0 ;寄存器加1
MOV A,R0 ;把R0里面的數(shù)據(jù)送累加器
MOVC A,@A+DPTR ;查表
MOV DACL,A ;所得值輸出至低8位數(shù)據(jù)輸出口
MOV A,R7 ;把第一次查得值送入累加器
CJNE R0,#100,SQUAREL ;如果R0的值不等于100則跳轉(zhuǎn)至SQUAREL標(biāo)號處執(zhí)行
MOV R2,#0F0H ;否則送把0FH送入R2
JMP SQ1 ;跳轉(zhuǎn)至SQ1標(biāo)號處執(zhí)行
SQUAREL:
NOP ;空操作,用于延時
NOP
NOP
SQ1:
ORL A,R2 ;把R2中的內(nèi)容疊加至累加器
MOV DACH,A ;把累加器內(nèi)容送至高8位數(shù)據(jù)輸出口
ACALL DELAY ;調(diào)用延時程序
CJNE R0,#200,START ;如果R0的值不等于200則跳轉(zhuǎn)至START標(biāo)號處執(zhí)行
NOP ;空操作
JMP LABLE1 ;跳至LABLE1標(biāo)號處執(zhí)行
NEXT:
NOP ;空操作,用于延時
NOP
NOP
NOP
NOP
NOP
LABEL4:
MOV DPTR,#SIN2 ;
MOV A,R1
MOV DPL,R1
MOVC A,@A+DPTR
MOV R6,A
INC R1
MOV A,R1
MOVC A,@A+DPTR
MOV DACL,A
MOV A,R6
CJNE R1,#100,SQUAREH
MOV R2,#00H
JMP SQ2
SQUAREH:
NOP
NOP
NOP
SQ2:
ORL A,R2
MOV DACH,A
ACALL DELAY
CJNE R1,#200,NEXT
NOP
JMP LABLE2
NOP
NOP
LJMP MAIN
LABLE1:
MOV R0,#0
JMP LABEL4
NOP
NOP
LJMP MAIN
LABLE2:
MOV R1,#0
JMP LABEL3
NOP
NOP
LJMP MAIN
DELAY:
MOV R3,#8
DEL1:
DJNZ R3,DEL1
RET
NOP
NOP
LJMP MAIN
ORG 100H
SIN1:
DW 2048, 2080, 2112, 2144, 2177, 2209, 2241, 2273, 2305, 2337, 2368, 2400, 2432, 2463, 2495, 2526, 2557, 2588, 2619, 2650
DW 2681, 2711, 2742, 2772, 2802, 2832, 2861, 2891, 2920, 2949, 2978, 3006, 3035, 3063, 3091, 3118, 3145, 3172, 3199, 3226
DW 3252, 3278, 3303, 3328, 3353, 3378, 3402, 3426, 3450, 3473, 3496, 3519, 3541, 3563, 3584, 3605, 3626, 3646, 3666, 3686
DW 3705, 3724, 3742, 3760, 3777, 3794, 3811, 3827, 3843, 3858, 3873, 3887, 3901, 3915, 3928, 3940, 3952, 3964, 3975, 3986
DW 3996, 4005, 4015, 4023, 4032, 4039, 4047, 4053, 4060, 4066, 4071, 4076, 4080, 4084, 4087, 4090, 4092, 4094, 4095, 4095
DW 4095, 4095, 4095, 4094, 4092, 4090, 4087, 4084, 4080, 4076, 4071, 4066, 4060, 4053, 4047, 4039, 4032, 4023, 4015, 4005
DW 3996, 3986, 3975, 3964, 3952, 3940, 3928, 3915, 3901, 3887, 3873, 3858, 3843, 3827, 3811, 3794, 3777, 3760, 3742, 3724
DW 3705, 3686, 3666, 3646, 3626, 3605, 3584, 3563, 3541, 3519, 3496, 3473, 3450, 3426, 3402, 3378, 3353, 3328, 3303, 3278
DW 3252, 3226, 3199, 3172, 3145, 3118, 3091, 3063, 3035, 3006, 2978, 2949, 2920, 2891, 2861, 2832, 2802, 2772, 2742, 2711
DW 2681, 2650, 2619, 2588, 2557, 2526, 2495, 2463, 2432, 2400, 2368, 2337, 2305, 2273, 2241, 2209, 2177, 2144, 2112, 2080
ORG 300H
SIN2:
DW 2048, 2016, 1984, 1952, 1919, 1887, 1855, 1823, 1791, 1759, 1728, 1696, 1664, 1633, 1601, 1570, 1539, 1508, 1477, 1446
DW 1415, 1385, 1354, 1324, 1294, 1264, 1235, 1205, 1176, 1147, 1118, 1090, 1061, 1033, 1005, 978 , 951 , 924 , 897 , 870
DW 844 , 818 , 793 , 768 , 743 , 718 , 694 , 670 , 646 , 623 , 600 , 577 , 555 , 533 , 512 , 491 , 470 , 450 , 430 , 410
DW 391 , 372 , 354 , 336 , 319 , 302 , 285 , 269 , 253 , 238 , 223 , 209 , 195 , 181 , 168 , 156 , 144 , 132 , 121 , 110
DW 100 , 91 , 81 , 73 , 64 , 57 , 49 , 43 , 36 , 30 , 25 , 20 , 16 , 12 , 9 , 6 , 4 , 2 , 1 , 0
DW 0 , 0 , 1 , 2 , 4 , 6 , 9 , 12 , 16 , 20 , 25 , 30 , 36 , 43 , 49 , 57 , 64 , 73 , 81 , 91
DW 100 , 110 , 121 , 132 , 144 , 156 , 168 , 181 , 195 , 209 , 223 , 238 , 253 , 269 , 285 , 302 , 319 , 336 , 354 , 372
DW 391 , 410 , 430 , 450 , 470 , 491 , 512 , 533 , 555 , 577 , 600 , 623 , 646 , 670 , 694 , 718 , 743 , 768 , 793 , 818
DW 844 , 870 , 897 , 924 , 951 , 978 , 1005, 1033, 1061, 1090, 1118, 1147, 1176, 1205, 1235, 1264, 1294, 1324, 1354, 1385
DW 1415, 1446, 1477, 1508, 1539, 1570, 1601, 1633, 1664, 1696, 1728, 1759, 1791, 1823, 1855, 1887, 1919, 1952, 1984, 2016
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
NOP
NOP
LJMP MAIN
END
評論