函数发生器程序

时间:2021-08-14 23:31:57

/*数码管按共阴的算,假设DA0832片选接在平P2.0口上*/

ORG 0000H

LJMP MAIN

ORG 0003H

LJMP L0

MAIN:MOV R2,#01H                  

      MOV R4,#01H                 

pp: SETB EA

      SETB EX0                 

      MOV A,P1

      JNB ACC.0,ZXB      

      JNB ACC.1,SJB     

      JNB ACC.2,FB       

      AJMP PP

         /*正弦波*/

ZXB:MOV R1,#00H

LOOP1:MOV A,R1

      MOV DPTR,#TABLE1            

      MOVC A,@A+DPTR               

      MOV B,R2

      MUL AB             

      INC R1

      XCH A,R1

      CLR C

      SUBB A, #0AH                   

      JNC LK1                

      ADD A,#0AH

      XCH A,R1                     

      ADD A,#80H                   

      AJMP LK0

LK1:ADD A,#0AH

      XCH A,R1

      MOV R3,A

      MOV A,#80H

      CLR C

      SUBB A,R3                     

LK0:

      CALL DELAY

      CJNE R1,#12H,LOOP1

      LJMP PP

 

/*三角波*/

SJB:MOV R1,#00H

LOOP2:MOV A,R1

      MOV DPTR,#TABLE2             

      MOVC A,@A+DPTR               

      MOV B,R2

      MUL AB             

      INC R1

      XCH A,R1

      CLR C

      SUBB A,#0DH                 

      JNC LK5                      

      ADD A,#0DH

      XCH A,R1                      

      ADD A,#80H                   

      AJMP LK4

LK5:ADD A,#0DH

      XCH A,R1

      MOV R3,A

      MOV A,#80H

      CLR C

      SUBB A,R3                    

LK4:

      CALL DELAY

      CJNE R1,#18H,LOOP2

      LJMP PP

 

/*方波*/

FB:MOV R1,#00H

LOOP3:MOV A,R1

      MOV DPTR,#TABLE3              

      MOVC A,@A+DPTR               

      MOV B,R2

      MUL AB              

      INC R1

      XCH A,R1

      CLR C

      SUBB A,#0AH                   

      JNC LK3                  

      ADD A,#0AH

      XCH A,R1                     

      ADD A,#80H                   

      AJMP LK2

LK3:ADD A,#0AH

      XCH A,R1

      MOV R3,A

      MOV A,#80H

      CLR C

      SUBB A,R3                    

LK2:

      CALL DELAY

      CJNE R1,#12H,LOOP3

      LJMP PP

DELAY:MOV DPTR,#0FEFFH

      MOVX @DPTR,A

        ; ACALL DISUP

      MOV A,R4

         MOV R5,A

KD0:  DEC R5

      CJNE R5,#00H,KD0

      MOV R5,A

      RET

 

/*外中断服务程序        */

   L0:CLR EA

      MOV B,A

      PUSH B

      PUSH PSW

/*判断幅度*/

  L1:    JB P1.3,L2                  

      JNB P1.5,KK0                              

      CJNE R2,#0AH,KK1             

      SJMP LD1

KK1:INC R2       

      SJMP LD1

KL1:CJNE R2,#00H,KK1

      SJMP LD1

KK0:DEC R2                       

LD1:JNB P1.3,LD1

      LJMP LEND

  /*判断频率的*/

   L2:JB P1.4 ,LEND

      JB P1.6,KLL                      

      CJNE R4,#0FFH,KF1

         SJMP MAX

KF1:  CLR C

      ADD A,#0FH    

      JC MAX

      MOV R4,A

      LJMP LD2

MAX:  MOV R4,#0FFH

      LJMP LD2

KLL:  MOV A,R4

      CJNE R4,#01H,KF0

         SJMP MIN

KF0:  CLR C

      SUBB A,#0FH

      JC MIN

      MOV R4,A

         LJMP LD2

MIN:  MOV R4,#01H

LD2:JNB P1.4,LD2

LEND:POP PSW

      POP B

         MOV A,B

      SETB EA

      RETI

         /*显示幅度,频率

DISUP:MOV DPTR,#TABLE4               ;读取振幅数据首地址

      MOV A,R2

         MOVC A,@A+DPTR                 ;取表格数据

                                                                                             */

 

TABLE1:DB 00H,04H,08H,0AH,0CH,0CH,0AH,08H,04H,00H,04H,08H,0AH,0CH,0CH,0AH,08H ,04H

TABLE2:DB 00H,02H,04H,06H,08H,0AH,0CH,0AH,08H,06H,04H,02H,00H,02H,04H,06H,08H,0AH,0CH,0AH,08H,06H,04H,02H

TABLE3:DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,0CH,0CH,0CH,0CH,0CH,0CH,0CH,0CH ,0CH

/*TABLE4:DB 0FDH, */

 

END

 

MOV  DPTR,#83E8H

MOV  A,80H

MOVX @DPTR,A

MOV A,R2

MOV B,0C

MUL; AB