fm_i2cdrv1.msa

来自「炬力方案176*132软件源码,适用于AK1025」· MSA 代码 · 共 797 行 · 第 1/2 页

MSA
797
字号
/********************************************************************************************
                philips TEA5767 FM module driver(I2C DRIVER)
                writen by GONGJIAN. for 3961
                last update 05-3-30 14:57
********************************************************************************************/
#include "actos.h"
    module    TEA5767HN_DIVER
   
//----------------------------------------------------------
//for FM_drv
public     FM_INIT_Drv                    //FM initialization
public     FM_EXIT_Drv                    //release bus
public     FM_SETFREQ_Drv                 //FM set frequency
public     FM_SEARCH_Drv                  //Search operation upwards or downwards
public     FM_SETMUTE_Drv                 //Set L and R audio muted or no muted
public     FM_STANDBY_Drv                 //Set standby status
public     FM_STEREO_Drv                  //Set stereo or mono
public     FM_GETSTATUS_Drv               //Judge preset operation complete
public     FM_VolumeSet_Drv
public     FM_result
//for FM_i2cdrv2
public     FREQ_RF
public     WSET_PLLLB
public     WSET_PLLHB
public     WRITE_BUFFER
public     READ_BUFFER
public     WSET_HLSI

public     buffer

//from FM_i2cdrv2
extern     WRITE_ONEFRAME
extern     READ_STATUS
extern     CALCULATE_PLL

//from I2C_Driver
extern     I2C_Init
extern     I2C_Exit

//--------------------------------------------------------------------------------------------
        RSEG    RCODE   //口 , 位 ,输入,输出,输入数据,输出数据  

WRITE_BUFFER        DEFB    80H,00H,00H,00H,00H        //Write operation buffer,size 5 bytes
READ_BUFFER         DEFB    00H,00H,00H,00H,00H        //Read operation buffer,size 5 bytes
WSET_MUTE           DEFB    00H    //Bit 7 of first byte of write buffer                                  
WSET_SM             DEFB    00H    //Bit 6 of first byte of write buffer(Search Mode)                                  
WSET_PLLLB          DEFB    00H    //Bit 5 to 0 of first byte of write buffer                                 
WSET_PLLHB          DEFB    00H    //Bit 7 to 0 of second byte of write buffer
WSET_SSL            DEFB    00H    //Bit 6 to 5 of third byte of write buffer(Search Stop Level)                                  //Setting of synthesizer programmable counter for search or preset
WSET_SUD            DEFB    00H    //Bit 7 of third byte of write buffer(Search up/down)
WSET_SSL1           DEFB    00H
WSET_SSL0           DEFB    00H
WSET_HLSI           DEFB    00H     //Bit 4 of the third byte of write buffer(HIGH/LOW Side Injection)
WSET_MS             DEFB    00H     //Bit 3 of the third byte of write buffer(Mono/Stereo)
WSET_MR             DEFB    00H     //Bit 1 of the third byte of write buffer(Mute Right)
WSET_ML             DEFB    00H     //Bit 2 of the third byte of write buffer(Mute Left)
WSET_SWP1           DEFB    00H     //Bit 0 of the third byte of write buffer(Software programmable port1)
WSET_SWP2           DEFB    00H     //Bit 7 of the fourth byte of write buffer(Software programmable port2)
WSET_STBY           DEFB    00H     //Bit 6 of the fourth byte of write buffer(Standby)
WSET_BL             DEFB    00H     //Bit 5 of the fourth byte of write buffer(Band Limits)
WSET_XTAL           DEFB    01H    //Bit 4 of the fourth byte of write buffer
WSET_SMUTE          DEFB    00H    //Bit 3 of the fourth byte of write buffer(Soft Mute)
WSET_HCC            DEFB    01H    //Bit 2 of the fourth byte of write buffer(High Cut Control)
WSET_SNC            DEFB    01H    //Bit 1 of the fourth byte of write buffer(Stereo noise cancelling)
WSET_SI             DEFB    00H    //Bit 0 of the fourth byte of write buffer(Search indicator)
WSET_PLLREF         DEFB    00H    //Bit 7 of the fifth byte of write buffer
WSET_DTC            DEFB    00H    //Bit 6 of the fifth byte of write buffer.Bit 5 to 0 is not used,position don't care
RSET_RF             DEFB    00H    //Bit 7 of the first byte of read buffer(Ready Flag)
RSET_BLF            DEFB    00H    //Bit 6 of the first byte of read buffer(Band Limit Flag)                            
RSET_STEREO         DEFB    00H    //Bit 7 of the third byte of read buffer(Stereo indication)                                 
RSET_IFCOUNTER      DEFB    00H    //Bit 6 to 0 of the third byte of read buffer ,IF Counter result                                  
RSET_LEV            DEFB    00H    //Bit 7 to 4 of the fourth byte of read buffer,Level ADC output                                  


FREQ_RF             DEFB    00H,00H    //省去最高位1                                       
FM_result           DEFB    00H     //00 mean error,1 mean true
FMadclevel0         DEFB     00H
FMadclevel1         DEFB     00H
FMadclevel2         DEFB     00H
Searchtemp_IF       DEFB     00H
Searchtemp_LEV          DEFB     00H
Searchtemp_STEREO       DEFB     00H
tempresult_LEV          DEFB     00H

SOFT_SUD             DEFB     00H
SOFT_SLEV            DEFB     00H
VolumeLEV            DEFB     00H

Analogtempbuf        DEFB     00H,00H

buffer      defs    5

#define     I2Cmode           00H           //I2C SPEED:00H:100K;40H:400K

#define     LEVdiffrence      03h
#define     checkIFcounter
#define     IFhighlimit       3Eh
#define     IFlowlimit        31h
#define     checkstereo

//-------------------------------------------------------------------------------------------
        RSEG    FM_CTRL_D
/********************************************************************************************
Function is FM initialization and enable bus.
Input parameter:DE(DE is first address of input structurn).        
        1.japanese FM,UE fm band info.
        2.Xtal flag
********************************************************************************************/
FM_INIT_Drv:
        PUSH    AF
        PUSH    BC
        PUSH    DE
        
        LD      A,(DE)              //band info.
        LD      (LWRD WSET_BL),A
        INC     DE
        LD      A,(DE)              //crystal info.
        LD      (LWRD SOFT_SLEV),A
        INC     DE
        LD      A,(DE)              //crystal info.
        LD      (LWRD WSET_XTAL),A
        LD      A,00H
        LD     (LWRD WSET_STBY),A
        LD      A,00H
        LD     (LWRD WSET_SM),A
/*
        LD    B,04H
        IN    A,(0D5H)
        OR    B
        OUT   (0D5H),A
        LD    B,54H
        IN    A,(0DDH)
        OR    B
        OUT   (0DDH),A
        LD    B,95H
        IN    A,(0D4H)
        OR    B
        OUT   (0D4H),A
*/
        LD      DE,LWRD Analogtempbuf
        LD      A,08H
        LD      (DE),A
        //CALL    LWRD EnableAIn
        mEnableAIn
        
        LD      E,02H
        LD      C,05H
        //CALL    LWRD SetAGain
        mSetAGain
        
        
                            //change by  ybfu
        LD      DE,LWRD Analogtempbuf
        LD      A,02H
        LD      (DE),A
        INC     DE
//volume set!!   
        LD      A,0fH
        LD      (DE),A
        DEC    DE
        //CALL    LWRD EnablePA
        mPA_Enable
        
        LD      E,I2Cmode              
        CALL    LWRD I2C_Init  

//release standby
        POP      DE
        PUSH     DE
        LD       A,00H
        LD       (DE),A
        CALL     LWRD FM_STANDBY_Drv
                        
        //CALL    LWRD testFMi2c

        POP    DE
        POP    BC  
        POP    AF
        RET
//============================================================
/*************************************************************
Function is FM exit and release bus.
入口:  no
**************************************************************/
FM_EXIT_Drv:
        PUSH    AF 
        PUSH    BC
        
        CALL    LWRD I2C_Exit       
/*        
        LD    A,40H
        OUT   (09EH),A
        LD    A,00H
        OUT   (0D5H),A
        LD    A,14H
        OUT   (0DDH),A
        LD    A,05H
        OUT   (0D4H),A
*/        
        //CALL   LWRD DisableAIn
        //CALL   LWRD DisablePA
        mDisableAIn
        mPA_Disable

        POP    BC
        POP    AF
        RET
//==============================================================

/***************************************************************
Function is preset FM to the current frequency.
Input parameter:DE(DE is first address of input structurn).
        1.Initialization preset frequency(2 bytes).
****************************************************************/
FM_SETFREQ_Drv:
        PUSH    AF
        PUSH    DE
        LD      A,(DE)                  //FREQ_RF LOW byte
        LD      (LWRD FREQ_RF),A
        INC     DE
        LD      A,(DE)                  //FREQ_RF middle byte
        LD      (LWRD FREQ_RF+1),A
        CALL    LWRD FM_setfrequency         
        POP     DE
        POP     AF
        RET
//==============================================================
/***************************************************************
Function is read back stereo info. and current frequency
Input parameter:DE(DE is first address of input structurn).
        1.Output address.
Output parameter:DE(DE is first address of Output structurn).
           1.Stereo Indication(1 byte).
           5.Current frequency(2 bytes,low byte is frong).
*****************************************************************/
FM_GETSTATUS_Drv:
         PUSH    AF
         PUSH    HL
         PUSH    DE

         LD      D,3
FM_GETSTATUS_loop1:     
         DEC     D
         JR      Z,FM_GETSTATUS_err_exit
         CALL    LWRD READ_STATUS
         CP      0
         JR      Z,FM_GETSTATUS_loop1     
         CALL    LWRD DISASSEMBLE_RB                 
         JR      FM_GETSTATUS_exit
FM_GETSTATUS_err_exit:
         LD      A,01H
         LD      (LWRD FM_result),A
         LD      (LWRD RSET_STEREO),A
FM_GETSTATUS_exit:
         POP     DE           
         PUSH    DE
         LD      A,(LWRD RSET_STEREO)                       //0-sterreo;1-mono;                  
         BIT     0,A
         JR      NZ,FM_GETSTATUS_loop2
         LD      A,02H
FM_GETSTATUS_loop2:
         DEC     A
         LD     (DE),A
         INC    DE
         LD     HL,LWRD FREQ_RF
         LD     A,(HL)
         LD     (DE),A
         INC    DE
         INC    HL
         LD     A,(HL)
         LD     (DE),A
         POP    DE
         POP    HL
         POP    AF
         RET
//==========================================================         
 
/*********************************************************
Function is set mute.
Input parameter:DE(DE is first address of input structure)
    1.Mute flag(1 byte).
    Output parameter:no
    Operation condition:
***********************************************************/
FM_SETMUTE_Drv:
      PUSH    AF
      PUSH    BC
      PUSH    HL
    
      LD      HL,LWRD WRITE_BUFFER
      RES     7,(HL)
      LD      A,(DE)
      LD      (LWRD WSET_MUTE),A        //The L and R audio muted
      CP      00H
      JR      Z,FM_SETMUTE_start
      SET     7,(HL)
      
      LD      C,3
FM_SETMUTE_start:    
      DEC     C
      JR      Z,FM_SETMUTE_exit
      CALL    LWRD WRITE_ONEFRAME
      CP      00H
      JR      Z,FM_SETMUTE_start 
FM_SETMUTE_exit:   
      LD      A,(DE)
      AND     A
      JR      NZ,FM_SETMUTE_exit1
      IN      A,(0D5H)
      SET     2,A
      OUT     (0D5H),A
      JR      FM_SETMUTE_exit2
FM_SETMUTE_exit1: 
      IN      A,(0D5H)
      RES     2,A
      OUT     (0D5H),A
FM_SETMUTE_exit2:            
      POP     HL
      POP     BC
      POP     AF
      RET
//======================================================      
/*******************************************************
Function is set standby.
Input parameter:DE(DE is first address of input structure).
    1.Standby flag(1 byte).
    Output parameter:no.
    Operation condition:
********************************************************/
FM_STANDBY_Drv:
      PUSH    AF
      PUSH    BC
      PUSH    HL
      
      LD      HL,LWRD WRITE_BUFFER+3
      RES     6,(HL)
      LD      A,(DE)
      LD      (LWRD WSET_STBY),A       //Standby
      CP      00H
      JR      Z,FM_STANDBY_start
      SET     6,(HL)
      
      LD      C,3
FM_STANDBY_start:     
      DEC     C
      JR      Z,FM_STANDBY_exit
      CALL    LWRD WRITE_ONEFRAME
      CP      00H
      JR      Z,FM_STANDBY_start 
FM_STANDBY_exit:         
      POP    HL
      POP    BC
      POP    AF
      RET
//=============================================================
/**************************************************************
Function is set mono or stereo.
Input parameter:DE(DE is first address of input structure).
    1.Stereo flag(1 byte).
    Output parameter:no.
    Operation condition:
*************************************************************/
FM_STEREO_Drv:
      PUSH    AF
      PUSH    BC
      PUSH    HL
      LD      HL,LWRD WRITE_BUFFER+2
      RES     3,(HL)
      LD      A,(DE)
      LD      (LWRD WSET_MS),A        //Mono or stereo
      CP      00H
      JR      Z,FM_STEREO_start
      SET     3,(HL)
      
      LD      C,3
FM_STEREO_start:     
      DEC     C
      JR      Z,FM_STEREO_exit
      CALL    LWRD WRITE_ONEFRAME
      CP      00H
      JR      Z,FM_STEREO_start
FM_STEREO_exit:         
      POP     HL
      POP     BC
      POP     AF
      RET
//=============================================================
/**************************************************************
Function is set volume
Input parameter:DE(DE is first address of input structure).
    1.volume level.
*************************************************************/
FM_VolumeSet_Drv:
        PUSH   AF
        PUSH   BC 
        PUSH   DE
        
        LD     A,(DE)
        LD     (LWRD VolumeLEV),A

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?