函数发生器程序

/*数码管按共阴的算,假设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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值