90 likes | 226 Views
LHO 20. Project. UNI_SIN.ASM. $include (c8051f020.inc) ; reg def file. EXTRN CODE (INIT, DELAY) ; IN UNI.ASM EXTRN CODE (WR_LEDS) ; IN UNI.ASM EXTRN CODE (RD_ADC0) ; IN UNI.ASM EXTRN CODE (WR_DAC0) ; IN UNI.ASM
E N D
LHO 20 Project
UNI_SIN.ASM $include (c8051f020.inc) ; reg def file. EXTRN CODE (INIT, DELAY) ; IN UNI.ASM EXTRN CODE (WR_LEDS) ; IN UNI.ASM EXTRN CODE (RD_ADC0) ; IN UNI.ASM EXTRN CODE (WR_DAC0) ; IN UNI.ASM EXTRN CODE (WR_DAC1) ; IN UNI.ASM EXTRN CODE (SIN) ; IN TRIG.ADM EXTRN CODE (COS) ; IN TRIG.ASM ET3 EQU 00000001B ; ENABLE TIMER 3 INT BIT PROG SEGMENT CODE ; SEGMENT FOR PROGRAM IN ROM BVAR SEGMENT BIT ; SEGMENT FOR BIT VARIABLES DVAR SEGMENT DATA ; SEG FOR VARIABLES IN RAM STACK SEGMENT IDATA ; SEG STACK IN INT DATA RAM
UNI_SIN.ASM - continued RSEG BVAR GO: DBIT 1 ; FLAG TO UPDATE NEXT POINT RSEG STACK DS 20H ; Reserve 32 Bytes for Stack RSEG DVAR ; SWITCH TO DATA SEGMENT T3CNT: DS 1 ; TIMER 3 COUNT ANG: DS 1 ; ANGLE FROM 0 TO 90 DEGREES QUAD: DS 1 ; QUADRANT 0, 1, 2, OR 3. ;INTERRUPT VECTOR LOCATINS CSEG AT 0 ; absolute Seg at Address 0 RESET: LJMP MAIN ; JUMP TO START OF PROGRAM ORG 73H ; TIMER 3 OVERFLOW INT LOC T3OVF: JMP ISRT3 ; JUMP TO ISR FOR TIMER 3 RSEG PROG ; SWITCH TO CODE SEGMENT
UNI_SIN.ASM - continued ;MAIN PROGRAM STARTS HERE MAIN: MOV SP,#STACK-1 ; Init stack pointer CALL INIT ; Initialize system ;ENABLE INTERRUPTS MOV ANG,#0 ;INITIALIZE ANGLE TO 0 MOV QUAD,#0 ;INITIALIZE QUADRANT TO 0 ANL A,#0FH ;CLEAR MOST SIG NIBBLE OF COUNT MOV R7,#0 ; INITIALIZE R6|R7 TO MOV R6,#0FH ; MAX OUTPUT TO DAC ORL EIE2,#ET3 ; ENABLE TIMERE 3 INTERRUPT SETB EA ; ENABLE INTERRUPTS ;DO FOREVER LOOP LOOP: CLR GO ; CLEAR GO TILL T3 INTERRUPT WAIT: JNB GO,WAIT ; WAIT FOR INTERRUPT CALL UPDATE ; UPDATE OUTPUT JMP LOOP ; LOOP FOREVER
UNI_SIN.ASM - continued ;************************************************* ; FUNCTION: ISRT3 - TIMER 3 OVERFLOW INTERRUPT ; SERVICE ROUTINE SETS GO FLAG ; INPUTS: NONE ; OUTPUTS: GO ; CALLS: NONE ; DESTROYS: GO, TMR3CN ;************************************************ ; ISRT3: PUSH PSW ;SAVE FLAGS ANL TMR3CN,#7FH ;CLEAR T3 OVERFLOW FLAG SETB GO ;SET GO SIGNAL POP PSW ;RESTORE PSW RETI
UNI_SIN.ASM - continued ;***************************************************** ; FUNCTION: UPDATE - OUTPUT POINT AND INC TO NEXT ANGLE ; INPUTS: ANG, QUAD ; OUTPUTS: ANG, QUAD ; CALLS: SIN, WR_DAC0, WR_DAC1, INC_ANG ; DESTROYS: ;****************************************************** UPDATE: MOV R7,ANG ;GET ANGLE MOV R6,QUAD ;GET QUADRANT CALL SIN ;GET SIN CALL WR_DAC0 ;OUTPUT TO DAC0 MOV R7,ANG ;GET ANGLE MOV R6,QUAD ;GET QUADRANT CALL COS ;GET COS CALL WR_DAC1 ;OUTPUT TO DAC1 CALL INC_ANG ;INCREMENT ANGLE RET
UNI_SIN.ASM - continued ;************************************************ ; FUNCTION: INC_ANG - INCREMENT ANGLE ; INPUTS: NONE ; OUTPUTS: NONE ; CALLS: WR_LEDS ; DESTROYS: R3 ;************************************************ INC_ANG: MOV A,ANG ;GET ANGLE INC A ;INCREMENT ANGLE CJNE A,#90,ANGOK ;JUMP IF ANGLE OK ELSE INC QUAD ;INCREMENT QUADRANT ANL QUAD,#11B ;USING MOD 4 CLR A ;THEN SET ANGLE TO 0 ANGOK: MOV ANG,A ;SAVE ANGLE RET ;AND RETURN
TRIG.ASM ;************************************************* ; FUNCTION: SIN - COMPUTES SIN(R6|R7) ; INPUTS: R6,R7 - AN ANGLE FROM 0 TO 360 DEGREES ; THE ANGLE IS GIVEN BY R6*90 + R7 ; OUTPUTS: R6|R7 - 2047 * SIN(R6*90+R7) ; CALLS: ... ; DESTROYS: ... ;************************************************* USING 0 SIN: ;ENTER YOUR CODE HERE RET RSEG CONST ; SWITCH TO DATA SEGMENT SINTBL: DW 0 ; 2047 * Sin(0) DW 35 ; 2047 * Sin(1) DW 71 ; 2047 * Sin(2) DW 107 ; 2047 * Sin(3)
UNI_SIN.ASM - continued ;***************************************************** ; FUNCTION: UPDATE - OUTPUT POINT AND INC TO NEXT ANGLE ; INPUTS: ANG, QUAD ; OUTPUTS: ANG, QUAD ; CALLS: SIN, WR_DAC0, WR_DAC1, INC_ANG ; DESTROYS: ;****************************************************** UPDATE: MOV R7,ANG ;GET ANGLE MOV R6,QUAD ;GET QUADRANT CALL SIN ;GET SIN CALL WR_DAC0 ;OUTPUT TO DAC0 MOV R7,ANG ;GET ANGLE MOV R6,QUAD ;GET QUADRANT CALL COS ;GET COS CALL WR_DAC1 ;OUTPUT TO DAC1 CALL INC_ANG ;INCREMENT ANGLE RET