搜索
bottom↓
回复: 3

遥控控制PT225电子音量

[复制链接]

出0入0汤圆

发表于 2009-6-16 18:03:06 | 显示全部楼层 |阅读模式
大家来看看我编的用遥控器控制PT2258做的5.1功放的程序
BIG   equ  12h;10db2258调整存放
SML    equ  13h;1DB2258调整存放
INBUFF   equ  14h;2416I2C输入
OUTBUFF   equ  15h;24C02输出
PAGE_2416     equ  16h;24C02器件地址
ADDR_2416IC   equ  17h;24C02字节地址
FLAG_T0   equ  18h
FLAG5     equ  19h
AIRDATA  EQU  1AH;遥控用户码低8位
BIRDATA  EQU  1BH;遥控用户码高8位
CIRDATA  EQU  1CH;遥控键码
DIRDATA  EQU  1DH;遥控键反码
LEDT0    EQU  1EH
LEDJS    EQU  1Fh
addr2258  equ  88h;2258器件地址
tempbuff  equ  30h
flag_i2c  bit  20h.1
FLAG_IR  BIT   20H.0
         sda                bit        p3.5;PT2258SDA
         scl                bit        p3.4;PT2258SCL

        flag_mute        bit        p3.1;=0静音关,=1静音开
        flag_led        bit        p3.0;有遥控信号闪8下,没信号长亮
       


        sda1                bit        p1.1;24C02SDA
        scl1                bit        p1.0;24C02SCL
       
org  0000h
ljmp start
org  000bh
ljmp int_t0
org  0040h
start:  
       mov   sp,#60h
       mov p1,#0ffh
       mov p3,#0ffh
       setb flag_mute
       setb flag_led
       mov   tmod,#01h
       mov   th0,#00h
       mov   tl0,#00h
;       setb  tr0
;       setb  et0
;       clr   tf0
;       setb  ea
;       mov   ledt0,#00h
;       mov   ledjs,#00h
;       mov   dptr,#table
;       mov   led1,#0eh
;       mov   led2,#0eh
;       mov   led3,#5h
;       mov   led4,#1h
;       mov   led5,#10h
;       mov   led6,#08h
;       mov   led7,#08h
;       mov   led8,#08h
;       mov   led9,#08h
;       mov   led10,#11h
MAIN1:     MOV R0,#0ffH
loop1:    LCALL  DELAY2400
           lcall  delay1000
           lcall  delay882
          djnz r0,loop1
          clr flag_mute
          lcall init2416
          lcall tiao2258
main:
       jnb  p3.2,ir;为0就是有遥控信号来了
  infrared_on:
     JB FLAG_IR,COUNT_2322
        ;LCALL INIT2416
        ;mov softdog,#00h
       ljmp  main
;*********************
;遥控子程序,输出在CIRDATA为键码,DIRDATA为键码反码,
;AIRDATA为用户码低8位,BIRDATA为用户码高8位,有键按
;下置位FLAG_IR
;*******************
ir:
       mov  r6,#9
sb:
       acall  delay882;延是0.8ms
       jb  p3.2,exit;是误信号退出
       djnz  r6,sb ;延时8.82ms是误信号退出
       jnb p3.2,$;等待9ms低电平过去
       acall  delay2400;延时2.4ms
       jnb p3.2,ir_rp;为低电平则为连按
       ;acall delay2400;
       JB P3.2,$
       ;LCALL DELAY500
       mov r1,#AIRDATA
       mov r2,#4
pp:
       mov r3,#8
jjjj:
       jnb p3.2,$
       lcall  delay882
       mov c,p3.2
       jnc uuu
       lcall delay1000
uuu:
       mov a,@r1
       rrc a
       mov @r1,a
       djnz r3,jjjj
       inc r1
       djnz r2,pp
       MOV A,DIRDATA
       CPL A
       CJNE A,CIRDATA,EXIT
       SETB FLAG_IR
       JMP EXIT
IR_RP: mov r6,#28h;延时96ms到下一个108毫秒来
delay96:
       lcall delay2400
       djnz r6,delay96
       SETB FLAG_IR
EXIT:jmp infrared_on
;******************
;遥控按键处理
;************************
COUNT_2322:
        CLR FLAG_IR
;********************
        setb ea
        setb et0 ;开T0定时中断,遥控时灯闪8下间隔500ms
        setb tr0
        MOV FLAG_T0,#0A0H
        MOV FLAG5,#08H
;************************
        MOV A,CIRDATA
        CJNE A,#00H,VOLDEC
  cendec:
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0b5h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#09h,cen_smlinc
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0b6h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#07h,cen_biginc
         ljmp count_2322_end
     cen_biginc:        
         inc big
         mov sml,#00h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0b6h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#0b5h
         mov inbuff,sml
         lcall write_2416
         jmp cendec_end
     cen_smlinc:
          inc sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#0b5h
          mov inbuff,sml
          lcall write_2416
          jmp cendec_end
     cendec_end:
          lcall cen2258
count_2322_end:
         ljmp main
        
         
         
         
         
  ;****************
  voldec:cjne a,#01h,voladd
  
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#15h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#09h,vol_smlinc
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#16h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#07h,vol_biginc
         ljmp count_2322_end
     vol_biginc:        
         inc big
         mov sml,#00h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#16h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#15h
         mov inbuff,sml
         lcall write_2416
         jmp vol_dec_end
     vol_smlinc:
          inc sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#015h
          mov inbuff,sml
          lcall write_2416
          jmp vol_dec_end
     vol_dec_end:
          lcall vol2258
          ljmp main
         
         
  ;************
  voladd:cjne a,#02h,frdec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#15h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#00h,vol_smldec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#16h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#00h,vol_bigdec
         ljmp count_2322_end
     vol_bigdec:        
         dec big
         mov sml,#09h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#16h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#15h
         mov inbuff,sml
         lcall write_2416
         jmp vol_add_end
     vol_smldec:
          dec sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#15h
          mov inbuff,sml
          lcall write_2416
          jmp fr_add_end
     VOL_add_end:
          lcall vol2258
          ljmp main
  
  ;***************
  frdec:cjne a,#04h,fradd
        
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#35h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#09h,fr_smlinc
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#36h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#07h,fr_biginc
         ljmp count_2322_end
     fr_biginc:        
         inc big
         mov sml,#00h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#36h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#35h
         mov inbuff,sml
         lcall write_2416
         jmp fr_dec_end
     fr_smlinc:
          inc sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#35h
          mov inbuff,sml
          lcall write_2416
          jmp fr_dec_end
     fr_dec_end:
          lcall fr2258
          ljmp main
  ;
  fradd:cjne a,#05h,fldec
  
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#35h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#00h,fr_smldec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#36h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#00h,fr_bigdec
         ljmp count_2322_end
     fr_bigdec:        
         dec big
         mov sml,#09h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#36h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#35h
         mov inbuff,sml
         lcall write_2416
         jmp fr_add_end
     fr_smldec:
          dec sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#35h
          mov inbuff,sml
          lcall write_2416
          jmp fr_add_end
     fr_add_end:
          lcall fr2258
          ljmp main
  
  fldec:cjne a,#07h,fladd
  
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#55h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#09h,fl_smlinc
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#56h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#07h,fL_biginc
         ljmp count_2322_end
     fl_biginc:        
         inc big
         mov sml,#00h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#56h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#55h
         mov inbuff,sml
         lcall write_2416
         jmp fl_dec_end
     fl_smlinc:
          inc sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#55h
          mov inbuff,sml
          lcall write_2416
          jmp fl_dec_end
     fl_dec_end:
          lcall fl2258
          ljmp main
  fladd:cjne a,#08h,srdec
        
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#55h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#00h,fl_smldec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#56h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#00h,fl_bigdec
         ljmp count_2322_end
     fl_bigdec:        
         dec big
         mov sml,#09h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#56h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#55h
         mov inbuff,sml
         lcall write_2416
         jmp fl_add_end
     fl_smldec:
          dec sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#55h
          mov inbuff,sml
          lcall write_2416
          jmp fl_add_end
     fl_add_end:
          lcall fl2258
          ljmp main
  srdec:cjne a,#0ah,sradd
        
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#75h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#09h,sr_smlinc
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#76h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#07h,sr_biginc
         ljmp count_2322_end
     sr_biginc:        
         inc big
         mov sml,#00h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#76h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#75h
         mov inbuff,sml
         lcall write_2416
         jmp srdec_end
     sr_smlinc:
          inc sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#75h
          mov inbuff,sml
          lcall write_2416
          jmp srdec_end
     srdec_end:
          lcall sr2258
          ljmp main
  sradd:cjne a,#1bh,sldec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#75h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#00h,sr_smldec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#76h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#00h,sr_bigdec
         ljmp count_2322_end
     sr_bigdec:        
         dec big
         mov sml,#09h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#76h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#75h
         mov inbuff,sml
         lcall write_2416
         jmp sr_add_end
     sr_smldec:
          dec sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#75h
          mov inbuff,sml
          lcall write_2416
          jmp sr_add_end
     sr_add_end:
          lcall sr2258
          ljmp main
  sldec:cjne a,#0ch,sladd
        
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#95h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#09h,sl_smlinc
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#96h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#07h,sl_biginc
         ljmp count_2322_end
     sl_biginc:        
         inc big
         mov sml,#00h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#96h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#95h
         mov inbuff,sml
         lcall write_2416
         jmp sldec_end
     sl_smlinc:
          inc sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#95h
          mov inbuff,sml
          lcall write_2416
          jmp sldec_end
     sldec_end:
          lcall sl2258
          ljmp main
  sladd:cjne a,#0dh,cenadd
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#95h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#00h,sl_smldec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#96h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#00h,sl_bigdec
         ljmp count_2322_end
     sl_bigdec:        
         dec big
         mov sml,#09h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#96h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#95h
         mov inbuff,sml
         lcall write_2416
         jmp sl_add_end
     sl_smldec:
          dec sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#95h
          mov inbuff,sml
          lcall write_2416
          jmp sl_add_end
     sl_add_end:
          lcall sl2258
          ljmp main
  
  cenadd:cjne a,#0fh,subdec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0b5h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#00h,cen_smldec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0b6h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#00h,cen_bigdec
         ljmp count_2322_end
     cen_bigdec:        
         dec big
         mov sml,#09h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0b6h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#0b5h
         mov inbuff,sml
         lcall write_2416
         jmp cen_add_end
     cen_smldec:
          dec sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#0b5h
          mov inbuff,sml
          lcall write_2416
          jmp cen_add_end
     cen_add_end:
          lcall cen2258
          ljmp main
  
  subdec:cjne a,#19h,subadd
         
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0d5h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#09h,sub_smlinc
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0d6h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#07h,sub_biginc
         ljmp count_2322_end
     sub_biginc:        
         inc big
         mov sml,#00h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0d6h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#0d5h
         mov inbuff,sml
         lcall write_2416
         jmp subdec_end
     sub_smlinc:
          inc sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#0d5h
          mov inbuff,sml
          lcall write_2416
          jmp subdec_end
     subdec_end:
          lcall sub2258
          ljmp main
  subadd:cjne a,#0eh,mute
         
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0d5h
         lcall READ_2416
         mov a,outbuff
         mov sml,a
         cjne a,#00h,sub_smldec
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0d6h
         lcall READ_2416
         mov a,outbuff
         mov big,a
         cjne a,#00h,sub_bigdec
         ljmp count_2322_end
     sub_bigdec:        
         dec big
         mov sml,#09h
         mov PAGE_2416,#0a0h
         mov ADDR_2416IC,#0d6h
         mov inbuff,big
         lcall write_2416
         mov ADDR_2416IC,#0d5h
         mov inbuff,sml
         lcall write_2416
         jmp sub_add_end
     sub_smldec:
          dec sml
          mov PAGE_2416,#0a0h
          mov ADDR_2416IC,#0d5h
          mov inbuff,sml
          lcall write_2416
          jmp sub_add_end
     sub_add_end:
          lcall sub2258
          ljmp main
  mute:cjne a,#1fh,count_2322_out
        cpl flag_mute
  
count_2322_out:
           ljmp main
  
;******************************

;**************************
DELAY882:
         MOV R7,#220
    DELAY882LOOP:
         NOP
         NOP
         DJNZ R7,DELAY882LOOP
         RET
DELAY1000:
          MOV R7,#249
    DELAY1000LOOP:
         NOP
         NOP
         DJNZ R7,DELAY1000LOOP
         RET
        
DELAY2400:
         MOV R7,#239
    DELAY2400LOOP:
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         DJNZ R7,DELAY2400LOOP
         RET
;************************

;****************************
vol2258:
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#15h
        lcall READ_2416
        mov a,outbuff
        mov sml,a
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#16h
        lcall READ_2416
        mov a,outbuff
        mov big,a        
        lcall i2c_bigen
        mov tempbuff,#addr2258
        lcall bitout_2416
        mov a,big
        anl a,#0fh
        orl a,#11010000b
        mov tempbuff,a
        lcall bitout_2416
        mov a,sml
        anl a,0fh
        orl a,#11100000b
        mov tempbuff,a
        lcall bitout_2416
        lcall i2c_end
        ret
fr2258:
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#35h
        lcall READ_2416
        mov a,outbuff
        mov sml,a
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#36h
        lcall READ_2416
        mov a,outbuff
        mov big,a        
        lcall i2c_bigen
        mov tempbuff,#addr2258
        lcall bitout_2416
        mov a,big
        anl a,#0fh
        orl a,#01000000b
        mov tempbuff,a
        lcall bitout_2416
        mov a,sml
        anl a,0fh
        orl a,#01010000b
        mov tempbuff,a
        lcall bitout_2416
        lcall i2c_end
        ret
fl2258:
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#55h
        lcall READ_2416
        mov a,outbuff
        mov sml,a
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#56h
        lcall READ_2416
        mov a,outbuff
        mov big,a
        
        lcall i2c_bigen
        mov tempbuff,#addr2258
        lcall bitout_2416
        mov a,big
        anl a,#0fh
        orl a,#10000000b
        mov tempbuff,a
        lcall bitout_2416
        mov a,sml
        anl a,0fh
        orl a,#10010000b
        mov tempbuff,a
        lcall bitout_2416
        lcall i2c_end
        ret
      
sr2258:
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#75h
        lcall READ_2416
        mov a,outbuff
        mov sml,a
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#76h
        lcall READ_2416
        mov a,outbuff
        mov big,a
        
        lcall i2c_bigen
        mov tempbuff,#addr2258
        lcall bitout_2416
        mov a,big
        anl a,#0fh
        orl a,#10100000b
        mov tempbuff,a
        lcall bitout_2416
        mov a,sml
        anl a,0fh
        orl a,#10110000b
        mov tempbuff,a
        lcall bitout_2416
        lcall i2c_end
        ret
sl2258:
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#95h
        lcall READ_2416
        mov a,outbuff
        mov sml,a
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#96h
        lcall READ_2416
        mov a,outbuff
        mov big,a
        
        lcall i2c_bigen
        mov tempbuff,#addr2258
        lcall bitout_2416
        mov a,big
        anl a,#0fh
        orl a,#01100000b
        mov tempbuff,a
        lcall bitout_2416
        mov a,sml
        anl a,0fh
        orl a,#01110000b
        mov tempbuff,a
        lcall bitout_2416
        lcall i2c_end
        ret
cen2258:
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#0b5h
        lcall READ_2416
        mov a,outbuff
        mov sml,a
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#0b6h
        lcall READ_2416
        mov a,outbuff
        mov big,a
        
        lcall i2c_bigen
        mov tempbuff,#addr2258
        lcall bitout_2416
        mov a,big
        anl a,#0fh
        orl a,#00000000b
        mov tempbuff,a
        lcall bitout_2416
        mov a,sml
        anl a,0fh
        orl a,#00010000b
        mov tempbuff,a
        lcall bitout_2416
        lcall i2c_end
        ret
sub2258:
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#0d5h
        lcall READ_2416
        mov a,outbuff
        mov sml,a
        mov PAGE_2416,#0a0h
        mov ADDR_2416IC,#0d6h
        lcall READ_2416
        mov a,outbuff
        mov big,a
        
        lcall i2c_bigen
        mov tempbuff,#addr2258
        lcall bitout_2416
        mov a,big
        anl a,#0fh
        orl a,#00100000b
        mov tempbuff,a
        lcall bitout_2416
        mov a,sml
        anl a,0fh
        orl a,#00110000b
        mov tempbuff,a
        lcall bitout_2416
        lcall i2c_end
        ret
tiao2258:lcall vol2258
         lcall fr2258
         lcall fl2258
         lcall sr2258
         lcall sl2258
         lcall cen2258
         lcall sub2258
         ret
;******************************
;初始化2416,13H=12H,33H=30H,53H=30H,73H=30H,
;93H=30,0B3H=30H,0D3H=30H,不是就到重新初始化
;到INIT2416GOOD
;*******************
init2416:
         MOV ADDR_2416IC,#13h
         mov PAGE_2416,#0a0h
         lcall read_2416
         mov a,outbuff
         cjne a,#12h,init2416_good
         MOV ADDR_2416IC,#33h
         mov PAGE_2416,#0a0h
         lcall read_2416
         mov a,outbuff
         cjne a,#30h,init2416_good
         MOV ADDR_2416IC,#53h
         mov PAGE_2416,#0a0h
         lcall read_2416
         mov a,outbuff
         cjne a,#30h,init2416_good
         MOV ADDR_2416IC,#73h
         mov PAGE_2416,#0a0h
         lcall read_2416
         mov a,outbuff
         cjne a,#30h,init2416_good
         MOV ADDR_2416IC,#93h
         mov PAGE_2416,#0a0h
         lcall read_2416
         mov a,outbuff
         cjne a,#30h,init2416_good
         MOV ADDR_2416IC,#0b3h
         mov PAGE_2416,#0a0h
         lcall read_2416
         mov a,outbuff
         cjne a,#30h,init2416_good
         MOV ADDR_2416IC,#0d3h
         mov PAGE_2416,#0a0h
         lcall read_2416
         mov a,outbuff
         cjne a,#30h,init2416_good
         jmp init2416_end
  init2416_good:
         
          mov r4,#00h
          mov r5,#00h
  init2416vol:
          mov dptr,#vol_tab
          mov ADDR_2416IC,#17h
   init2416loop:
          mov inbuff,#00h
          lcall write_2416
          dec ADDR_2416IC
          mov a,r4
          rl a
          movc a,@a+dptr
          mov inbuff,a
          lcall write_2416
          dec ADDR_2416IC
          mov a,r4
          rl a
          inc a
          movc a,@a+dptr
          mov inbuff,a
          lcall write_2416
          dec ADDR_2416IC
          mov a,r4
          rl a
          inc a
          inc a
          movc a,@a+dptr
          mov inbuff,a
          lcall write_2416
          dec ADDR_2416IC
          mov a,r4
          rl a
          inc a
          inc a
          inc a
          movc a,@a+dptr
          mov inbuff,a
          lcall write_2416
          inc r5
init2416fr:
          cjne r5,#01h,init2416fl
          mov ADDR_2416IC,#37h
          mov dptr,#fr_tab
          jmp init2416loop
init2416fl:         
          cjne r5,#02h,init2416sr
          mov ADDR_2416IC,#57h
          mov dptr,#fl_tab
          jmp init2416loop
init2416sr:         
          cjne r5,#03h,init2416sl
          mov ADDR_2416IC,#77h
          mov dptr,#sr_tab
          jmp init2416loop
init2416sl:         
          cjne r5,#04h,init2416cen
          mov ADDR_2416IC,#97h
          mov dptr,#sl_tab
          jmp init2416loop
init2416cen:
          cjne r5,#05h,init2416sub
          mov ADDR_2416IC,#0b7h
          mov dptr,#cen_tab
          jmp init2416loop
init2416sub:
          cjne r5,#06h,init2416_end
          mov ADDR_2416IC,#0d7h
          mov dptr,#sub_tab
          jmp init2416loop
         
         
               
init2416_end:ret

;***************
vol_tab:
        db        03h,09h,00h,12h;06h,  3123h,1003H, 0000h, 0000h,11e0h,3123h  ;0707h
;                16h,15h,14h,13h,                                  0
fr_tab:       
        dw        0fh,0fh,00h,30h;c2h, 31d2h, 0000h, 0000h, 0000h,0000h, 3123h
;                36h,35h,34h,33h,数字        F        L                                          0
fl_tab:       
        dw        0fh,0fh,00h,30h;c2h, 1003H, 0000h, 0000h, 0000h,0000h, 3123h
;                56h,55h,54h,53h,数字        S        R                                          0
sr_tab:
        dw        0fh,0fh,00h,30h;e1h, 31d2h, 0000h, 0000h, 0000h,0000h, 3123h
;                76h,75h,74h,73h,数字        S        L                                          0
sl_tab:
        dw        0fh,0fh,00h,30h;e1h, 1003H, 0000h, 0000h, 0000h,0000h, 3123h
;                96h,95h,94h,93h;数字        C        E        N                        0
cen_tab:
        dw        0fh,0fh,00h,30h;03h,30c3h,1932h, 0000h, 0000h,0000h, 3123h
        ;        b6h,b5h,b4h,b3h;数字        S        U        B                           0
sub_tab:
        dw        0fh,0fh,00h,30h;e1h, 1123h,  31e3h, 0000h, 0000h,0000h,3123h
;                d6h,d5h,d4h,d3h;数字        T        R        E                            0      

;--------------------------------------------------
;Serial I2C Sub Program
;---------------------------------------------------
I2C_Bigen:
        setb                sda
        nop
        nop
        nop
        nop
        nop
        nop
        setb                scl
        nop
        nop
        nop
        nop
        nop
        jnb                scl,$
        clr                sda
        nop
        nop
        nop
        nop
        nop
        clr                scl
        nop
        nop
        nop
        nop
        nop
        ret
;------------------------------------------------
I2C_End:
        clr        scl
        nop
        nop
        nop
        nop
        nop
        nop
        clr        sda
        nop
        nop
        nop
        nop
        nop
        nop
        ;jb        scl,$
        setb        scl
        nop
        nop
        nop
        nop
        nop
        nop
        setb        sda
        nop
        nop
        nop
        nop

        ret
;-------------------------------------------
;主应答
;-------------------------------------------
i2c_sendack:
        clr        sda
        nop
        setb        scl

        nop
        clr        scl
        nop
        setb        sda

        ret
;-------------------------------
;无应答
;-----------------------------
I2C_noack:
        setb        sda
        nop
        setb        scl
        nop
        clr        scl
        ret

;------------------------------------------------
;I2C输出一个字节
;输入的参数在 tempbuff
;------------------------------------------------
BitOut_2416:
        mov                r0,#08h
        mov                a,TempBuff
  BitOut_2416_8bit:
          jnb                acc.7,BitOut_2416_low
        setb                sda
        sjmp                  BitOut_2416_again
  BitOut_2416_low:
        clr                sda
  BitOut_2416_again:
        nop
        nop
        nop
        nop
        nop
        nop
        setb                scl
        nop
        nop
        nop
        nop
        jnb                scl,$
        ;nop
        nop
        clr                scl
        nop
        nop
        nop
        nop
        nop
        rl                a
        djnz                r0,BitOut_2416_8bit
        nop
        setb                sda       ;这里要等待回答信号?
        mov                r6,#00h
        nop
        setb                scl
        jnb                scl,$
        nop
  BitOut_2416_loop:
        jnb                sda,BitOut_2416_good
        inc                r6
        cjne                r6,#08h,BitOut_2416_loop
        nop   ;这里是出错的地方
        setb                flag_i2c
BitOut_2416_good:
            clr                scl
        ret

;------------------------------------------------
;输出的参数在A中
;------------------------------------------------
BitIn_2416:
        mov        a,#00h
        mov        r0,#08h
        setb        sda
        ;clr        scl
        ;nop
BitIn_2416_8bit:
        setb        scl
        rl        a
        nop
        jnb        sda,BitIn_8bit_2416_low
        setb        acc.0
        sjmp        BitIn_8bit__2416again
BitIn_8bit_2416_low:
        clr        acc.0
BitIn_8bit__2416again:
          clr        scl
        nop
        nop
        nop
        djnz        r0,BitIn_2416_8bit
        ;clr        sda
        ;nop
        ;setb        scl
        ;nop
        ;clr        scl
        ;nop
        ret
   
   





        ;--------------------------------------------------
;Serial I2C Sub Program
;---------------------------------------------------
I2C_Bigen1:
        setb                sda1
        nop
        nop
        nop
        nop
        nop
        nop
        setb                scl1
        nop
        nop
        nop
        nop
        nop
        jnb                scl1,$
        clr                sda1
        nop
        nop
        nop
        nop
        nop
        clr                scl1
        nop
        nop
        nop
        nop
        nop
        ret
;------------------------------------------------
I2C_End1:
        clr        scl1
        nop
        nop
        nop
        nop
        nop
        nop
        clr        sda1
        nop
        nop
        nop
        nop
        nop
        nop
        jb        scl1,$
        setb        scl1
        nop
        nop
        nop
        nop
        nop
        nop
        setb        sda1
        nop
        nop
        nop
        nop

        ret
;-------------------------------------------
;主应答
;-------------------------------------------
i2c_sendack1:
        clr        sda1
        nop
        setb        scl1

        nop
        clr        scl1
        nop
        setb        sda1

        ret
;-------------------------------
;无应答
;-----------------------------
I2C_noack1:
        setb        sda1
        nop
        setb        scl1
        nop
        clr        scl1
        ret

;------------------------------------------------
;I2C输出一个字节
;输入的参数在 tempbuff
;------------------------------------------------
BitOut_24161:
        mov                r0,#08h
        mov                a,TempBuff
  BitOut_2416_8bit1:
          jnb                acc.7,BitOut_2416_low1
        setb                sda1
        sjmp                  BitOut_2416_again1
  BitOut_2416_low1:
        clr                sda1
  BitOut_2416_again1:
        nop
        nop
        nop
        nop
        nop
        nop
        setb                scl1
        nop
        nop
        nop
        nop
        jnb                scl1,$
        ;nop
        nop
        clr                scl1
        nop
        nop
        nop
        nop
        nop
        rl                a
        djnz                r0,BitOut_2416_8bit1
        nop
        setb                sda1       ;这里要等待回答信号?
        mov                r6,#00h
        nop
        setb                scl1
        jnb                scl1,$
        nop
  BitOut_2416_loop1:
        jnb                sda1,BitOut_2416_good1
        inc                r6
        cjne                r6,#08h,BitOut_2416_loop1
        nop   ;这里是出错的地方
        setb                flag_i2c
BitOut_2416_good1:
            clr                scl1
        ret

;------------------------------------------------
;输出的参数在A中
;------------------------------------------------
BitIn_24161:
        mov        a,#00h
        mov        r0,#08h
        setb        sda
        ;clr        scl
        ;nop
BitIn_2416_8bit1:
        setb        scl1
        rl        a
        nop
        jnb        sda1,BitIn_8bit_2416_low1
        setb        acc.0
        sjmp        BitIn_8bit__2416again1
BitIn_8bit_2416_low1:
        clr        acc.0
BitIn_8bit__2416again1:
          clr        scl1
        nop
        nop
        nop
        djnz        r0,BitIn_2416_8bit1
        ;clr        sda
        ;nop
        ;setb        scl
        ;nop
        ;clr        scl
        ;nop
        ret
;------------------------------------------------
;从2416中读出一个字节的子程序
;输入的参数:2416ic_addr,page_2416
;输出的参数:outbuff
;------------------------------------------------
Read_2416:
        lcall        I2C_Bigen1
        mov        tempbuff,page_2416;#address_2416
            lcall        BitOut_24161
            mov        tempbuff,addr_2416ic
            lcall        BitOut_24161
            nop
            nop
            lcall        I2C_Bigen1
            ;mov        tempbuff,#address_2416
            mov        tempbuff,page_2416
            orl        tempbuff,#01h
            ;mov        tempbuff,#0a1h
            lcall        BitOut_24161
        nop
        nop
        lcall        BitIn_24161
        lcall        I2C_noack1
        mov        outbuff,a

        lcall        I2C_End1
       
        ret

;------------------------------------------------
;在2416中写入一个字节的子程序
;输入的参数:addr_2416ic,page_2416,inbuff''''
;注意写完结束必须要延时一段时间
;------------------------------------------------
write_2416:
        lcall        I2C_Bigen1
        mov        tempbuff,page_2416;#address_2416
        lcall        BitOut_24161
        mov        tempbuff,addr_2416ic
        lcall        BitOut_24161
        mov        tempbuff,inbuff
        lcall        BitOut_24161
       
        lcall        I2C_End1
        lcall        delay1000
        lcall        delay1000

        ret
       
;*********************

INT_T0:
        PUSH ACC
        PUSH PSw
        MOV TH0,#00H
        MOV TL0,#00H
        DEC FLAG_T0
        MOV a,FLAG_T0
        cjne a,#00h,INT_T0_EXIT
        CPL FLAG_LED
        DEC FLAG5
        MOV a,FLAG5
        cjne a,#00h,INT_T0_EXIT
        CLR EA
        CLR TR0
INT_T0_EXIT:
        POP PSW
        POP ACC
        RETi
        
        end

阿莫论坛20周年了!感谢大家的支持与爱护!!

阿莫论坛才是最爱国的,关心国家的经济、社会的发展、担心国家被别国牵连卷入战争、知道珍惜来之不易的和平发展,知道师夷之长,关注世界的先进文化与技术,也探讨中国文化的博大精深,也懂得警惕民粹主义的祸国殃民等等等等,无不是爱国忧民的表现。(坛友:tianxian)

出0入0汤圆

发表于 2009-6-16 21:15:30 | 显示全部楼层
晕,头看大了

出0入0汤圆

发表于 2009-6-16 21:48:08 | 显示全部楼层
真厉害

出0入0汤圆

发表于 2017-8-12 15:08:09 | 显示全部楼层
真的厉害,完全没看懂啊
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-16 12:08

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表