TA的每日心情 | 郁闷 2013-9-12 12:12 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]初来乍到
|
- 实验9-2:正弦信号发生器
- 该程序利用DAC0产生正弦波信号。
- $MOD841
- SP0 EQU 50H
- CLK81 EQU P3.5
- DAT81 EQU P3.3
- KEYVAL EQU 31H
- ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- ORG 0000H
- LJMP MAIN
- ORG 0003H
- LJMP SERVE1
- ORG 002BH
- LJMP SERVE2
- ORG 0060H
- MAIN: MOV R0,#0FH
- CLR A
- QING: MOV @R0,A
- DJNZ R0,QING
- MOV SP,#SP0
- MOV R3,#0FFH
- LCALL YS
- ;---------------------------------------
- LCALL INI8281
- LCALL INI841
- HERE: LJMP HERE
- ;-------------------------------------
- INI841: SETB EA
- SETB ET2
- SETB EX0
- MOV T2CON,#00H
- MOV ADCCON1,#80H ; 给内部参考电源上电
- MOV DACCON,#0DH ; DAC1清0,DAC0正常输出,设置同步更新输出,上电DAC0
- RET
- ;----------------------------------
- INI8281: SETB CLK81
- SETB DAT81
- MOV A,#12H
- LCALL WTO81
- MOV A,#80H
- LCALL WTO81
- RET
- ;---------------------------------
- SERVE1: CLR TR2
- MOV A,#93H
- LCALL WTO81
- LCALL RDKVAL
- MOV A,KEYVAL
- CJNE A,#01H,S1
- LCALL FUNCTION1
- LJMP S2
- S1: CJNE A,#02H,S2
- LCALL FUNCTION2
- S2: RETI
- ;----------------------------------
- SERVE2: CLR TF2
- KAISHI: INC R3
- CJNE R3,#200,DADISP
- MOV R3,#0FFH
- LJMP KAISHI
- DADISP: MOV DPTR,#TAB1
- MOV A,R3
- MOVC A,@A+DPTR
- MOV DAC0H,A
- MOV DPTR,#TAB2
- MOV A,R3
- MOVC A,@A+DPTR
- MOV DAC0L,A
- RETI
- ;---------------------------------
- FUNCTION1:MOV RCAP2H,#0EAH
- MOV RCAP2L,#65H
- MOV TH2,#0EAH
- MOV TL2,#65H
- SETB TR2
- RET
- ;-----------------------------------
- FUNCTION2:MOV RCAP2H,#0FDH
- MOV RCAP2L,#0D7H
- MOV TH2,#0FDH
- MOV TL2,#0D7H
- SETB TR2
- RET
- ;-----------------------------
- WTO81: MOV R6,#08H
- WAT: CLR CLK81
- LCALL DELAY
- SETB CLK81
- JB DAT81,WAT
- CLR CLK81
- LCALL DELAY
- SETB CLK81
- JNB DAT81,$
- WTB81: RLC A
- MOV DAT81,C
- CLR CLK81
- LCALL DELAY
- SETB CLK81
- LCALL DELAY
- LCALL DELAY
- DJNZ R6,WTB81
- SETB DAT81
- RET
- ;-----------------------------------
- RDKVAL: CLR CLK81
- LCALL DELAY
- SETB CLK81
- JB DAT81,$
- CLR CLK81
- LCALL DELAY
- SETB CLK81
- MOV R6,#08H
- RD1: LCALL DELAY
- LCALL DELAY
- LCALL DELAY
- MOV C,DAT81
- LCALL DELAY
- RLC A
- CLR CLK81
- LCALL DELAY
- SETB CLK81
- DJNZ R6,RD1
- MOV KEYVAL,A
- RET
- ;---------------------------------
- DELAY: NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- RET
- ;----------------------------------------
- YS: MOV R5,#00H
- MOV R4,#50H
- YS1: DJNZ R5,$
- DJNZ R4,YS1
- RET
- ;----------------------------------------
- TAB1: DB 08H,08H,08H,08H,09H,09H,09H,09H,09H,0AH,0AH,0AH,0AH,0BH,0BH,0BH,0BH,0CH,0CH
- DB 0CH,0CH,0CH,0DH,0DH,0DH,0DH,0DH,0EH,0EH,0EH,0EH,0EH,0EH,0EH,0FH,0FH,0FH,0FH
- DB 0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH
- DB 0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0FH,0EH,0EH,0EH,0EH,0EH,0EH,0EH,0DH,0DH
- DB 0DH,0DH,0DH,0CH,0CH,0CH,0CH,0CH,0BH,0BH,0BH,0BH,0AH,0AH,0AH,0AH,09H,09H,09H
- DB 09H,09H,08H,08H,08H,08H,07H,07H,07H,06H,06H,06H,06H,06H,05H,05H,05H,05H,04H
- DB 04H,04H,04H,03H,03H,03H,03H,03H,02H,02H,02H,02H,02H,02H,01H,01H,01H,01H,01H
- DB 01H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H
- DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,01H,01H,01H,01H
- DB 01H,01H,02H,02H,02H,02H,02H,02H,03H,03H,03H,03H,03H,04H,04H,04H,04H,05H,05H
- DB 05H,05H,06H,06H,06H,06H,06H,07H,07H,07H
- TAB2:DB 00H,40H,81H,0C1H,01H,40H,80H,0BFH,0FDH,3BH,79H,0B6H,0F2H,2DH,68H,0A2H,0DBH,13H
- DB 49H,7FH,0B4H,0E7H,19H,4AH,7AH,0A8H,0D5H,00H,2AH,52H,79H,9EH,0C1H,0E3H,03H,21H
- DB 3DH,58H,70H,87H,9CH,0AFH,0C0H,0CFH,0DCH,0E7H,0F0H,0F7H,0FCH,0FDH,0FEH,0FFH,0FCH
- DB 0F7H,0F0H,0E7H,0DCH,0CFH,0C0H,0AFH,9CH,87H,70H,58H,3DH,21H,03H,0E3H,0C1H,9EH,79H
- DB 52H,2AH,00H,0D5H,0A8H,7AH,4AH,19H,0E7H,0B4H,7FH,49H,13H,0DBH,0A2H,68H,2DH,0F2H
- DB 0B6H,79H,3BH,0FDH,0BFH,80H,40H,01H,0C1H,81H,40H,00H,0C0H,7FH,3FH,0FFH,0C0H,80H
- DB 41H,03H,0C5H,87H,4AH,0EH,0D3H,98H,5EH,25H,0EDH,0B7H,81H,4CH,19H,0E7H,0B6H,86H
- DB 58H,2BH,00H,0D6H,0AEH,87H,62H,3FH,1DH,0FDH,0DFH,0C3H,0A8H,90H,79H,64H,51H,40H,31H
- DB 24H,19H,10H,09H,04H,02H,01H,02H,04H,09H,10H,19H,24H,31H,40H,51H,64H,79H,90H,0A8H
- DB 0C3H,0DFH,0FDH,1DH,3FH,62H,87H,0AEH,0D6H,00H,2BH,58H,86H,0B6H,0E7H,19H,4CH,81H
- DB 0B7H,0EDH,25H,5EH,98H,0D3H,0EH,4AH,87H,0C5H,03H,41H,80H,0C0H,0FFH,3FH,7FH,0C0H
- ;===============================================
- END
-
- 实验9-3:PWM信号输出
- 下面的程序产生固定的PWM脉宽输出,按00h键开始,按其他键结束。
- $MOD841
- CLK81 EQU P3.5
- DAT81 EQU P3.3
- KEY EQU P3.2
- KEYVAL EQU 30H
- ;***********************
- ORG 0000H
- LJMP MAIN
- ORG 0003H
- LJMP SERVE
- ORG 0060H
- MAIN: MOV R0, #0FFH;
- CLR_IN_RAM: MOV @R0, #00H
- DJNZ R0, CLR_IN_RAM
- MOV SP, #50H
- LCALL YS
- ;***********************初始化
- LCALL INI841
- LCALL INIWH8281
- ;***********************欢迎菜单
- LCALL WELCOME
- MOV 40H, #0FFH
- ZYS: LCALL YS
- DJNZ 40H, ZYS
- ;***********************清屏
- MOV A, #16H
- LCALL WTO81
- MOV A, #00H
- LCALL WTO81
- ;***********************
- START: LJMP $
- ;***********************
- SERVE: MOV A, #93H
- LCALL WTO81
- LCALL RDKVAL
- MOV A, 30H
- CJNE A, #00H, J1
- MOV CFG841, #40H ; 选择PWM输出引脚为P3.4和P3.3,分频数为32
- MOV PWMCON, #13H ; 允许PWM输出,两通道16位归零PWM选择模式
- MOV PWM0L, #55H ; 写入初值
- MOV PWM1L, #00H ; 写入初值
- MOV PWM0H, #05H ; 写入初值
- MOV PWM1H, #10H ; 写入初值
- LJMP HUIQU
- J1: MOV PWMCON, #80H
- HUIQU: RETI
-
- ;********************初始化841
- INI841: SETB EA
- SETB EX0
- RET
- ;***********************初始化WH8281
- INIWH8281: SETB CLK81
- SETB DAT81
- MOV A, #12H
- LCALL WTO81
- MOV A, #84H;
- LCALL WTO81
- RET
- ;***********************欢迎界面子程
- WELCOME: MOV A, #14H;
- LCALL WTO81
- MOV A, #0CH
- LCALL WTO81
- MOV A, #14H
- LCALL WTO81
- MOV A, #1BH
- LCALL WTO81
- MOV A, #14H
- LCALL WTO81
- MOV A, #2DH
- LCALL WTO81
- MOV A, #14H
- LCALL WTO81
- MOV A, #3DH
- LCALL WTO81
- MOV A, #14H
- LCALL WTO81
- MOV A, #40H
- LCALL WTO81
- RET
- ;***********************写入WH8281子程序
- WTO81: MOV R6, #08H
- WAT: CLR CLK81
- NOP
- NOP
- SETB CLK81
- JB DAT81, WAT
- CLR CLK81
- LCALL DELAY
- SETB CLK81
- JNB DAT81, $
- WTB81: RLC A
- MOV DAT81,C
- CLR CLK81
- LCALL DELAY
- SETB CLK81
- LCALL DELAY
- LCALL DELAY
- DJNZ R6, WTB81
- SETB DAT81
- RET
- DELAY: NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- RET
- ;***********************读取键值子程序
- RDKVAL: CLR CLK81
- NOP
- NOP
- SETB CLK81
- JB DAT81, $
- CLR CLK81
- LCALL DELAY
- SETB CLK81
- MOV R6, #08H
- RD1: LCALL DELAY
- LCALL DELAY
- MOV C, DAT81
- RLC A
- CLR CLK81
- LCALL DELAY
- SETB CLK81
- DJNZ R6, RD1
- MOV KEYVAL, A
- RET
- ;***********************延时程序
- YS: MOV R5, #00H
- MOV R4, #50H
- YS1: DJNZ R5, $
- DJNZ R4, YS1
- RET
- ;***********************
- END
复制代码
|
|