⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fm_i2cdrv1.msa

📁 5807收音机模块用于炬力平台
💻 MSA
📖 第 1 页 / 共 2 页
字号:
/********************************************************************************************
philips TEA5767 FM module driver(I2C DRIVER)
writen by Xuezhi. for S1
last update 04-2-13 15:02
********************************************************************************************/
#include "actos.h"
    module    RDA5802HN_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     WSET_XTAL

//from FM_i2cdrv2
extern     I2C_init
extern     I2C_exit
extern     WRITE_ONEFRAME
extern     READ_STATUS
extern     FMwait50ms

public     SearchFreq
public     SetFreq

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

//WRITE_BUFFER        DEFB    0xC1,0xD1,0x1A,0x10,0x06,0x00,0x88,0xa8 //Write operation buffer,size 4 words:
WRITE_BUFFER
    DEFB    0xC0, 0x01 //02H:  //24M crystal : 0xC0, 0xD1, 32.768k crystal: 0xC0, 0x01;
    DEFB     0x00, 0x00        
    DEFB     0x04, 0x00        
    DEFB     0x8b, 0xAF //05H:  //灵敏度 :0x88, 0xAF
      
                                        //02h,03h,04h,05h
READ_BUFFER         DEFB    00H,00H,00H,00H       //Read operation buffer,0Ah,0Bh
// 下面的每一个变量的有效值都与其在寄存器中的位置对应,
//比如mute对应的14bit换算为8bit为Hi bit 7,因此其有效值为40H
WSET_MUTE           DEFB    0x40    //FM mute, 02h bit 14(0 = mute 1 normal)                                  
WSET_SM             DEFB    0x01    //search mode(search or not),02h bit 8                                  
WSET_MS             DEFB    0x20     //Mono or Stereo, 02h bit 13(0= stereo)
WSET_STBY           DEFB    0x01     //power disable or enable, 02h bit 0(0 disable,1 enable)
WSET_XTAL           DEFB    0x00    //clk_mode,02h bit[6:4] 0 = 32.768 0x0D0= 24M   //24M crystal :0xD0, 32.768k crystal:  0x00;
WSET_BST            DEFB    0x00    //03H[1:0] seek step such as :100K, 50K and so on
WSET_DTC            DEFB    0x00    //de-emphasis time constant,04h bit 11(0 = 75us,1 = 50us) 
WSET_BL             DEFB    0x00     //Band,03h bit[3:2](00 = US,01 = Japan)
WSET_SM2            DEFB    0x00    //whether stop seeking at the upper or lower band limit,02h bit 7(1 stop)
WSET_RST            DEFB    0x00   //soft reset   0x02 = reset ,0x00 = not reset (now not used)
SOFT_SUD            DEFB    0x00   //Seek up or down,02h bit 9(0 = down,1 = up,now no use just set to 1)
SOFT_SLEV           DEFB    0x8b   //seek level,05h bit[14:8]
FREQ_RF             DEFB    0x00,0x00    //Freq infor,3h bit[15:6],freq = FREQ_RF*channel sapcing + 87M(76M) 

RSET_RF             DEFB    0x00    //the current channel is a station,0Bh bit 8(1 = station)
RSET_STEREO         DEFB    0x00    //Stereo indication,0AH bit 10(0 = mono,1 = stereo)                                
RSET_LEV            DEFB    0x00    //current station's level,0bh bit[15:9]                                 
                                      
FM_result           DEFB    0x00     //00 mean error,1 mean true
FMadclevel0         DEFB    0x00
FMadclevel1         DEFB    0x00
FMadclevel2         DEFB    0x00
Searchtemp_IF       DEFB    0x00
Searchtemp_LEV          DEFB     0x00
Searchtemp_STEREO       DEFB     0x00
tempresult_LEV          DEFB     0x00


WSET_PLLLB          DEFB    0x00                                     
WSET_PLLHB          DEFB    0x00
WSET_HLSI           DEFB    0x00

Analogtempbuf        DEFB     0x00,0x00

SearchFreq    defb   00
SetFreq       defb   00


#define     LEVdiffrence      03h
#define     checkIFcounter
#define     IFhighlimit       3Eh
#define     IFlowlimit        31h
//#define     checkstereo
//================================================
#define     Busen_doport        0F4H
#define     Busen_doport_num    04H
#define     Busen_outport       0F3H
#define     Busen_outport_num   04H
//-------------------------------------------------------------------------------------------
        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,bit 3:2 of 03h
        CP        0x00
        JR        NZ,JPMode   
        XOR       A 
        LD      (LWRD WSET_BL),A
        JR        NEXTLABLE
JPMode:   
        LD        A,0x04
        LD        (LWRD WSET_BL),A 
NEXTLABLE:    
    LD    B,A
        PUsh    DE
        LD    DE,LWRD WRITE_BUFFER+3
        LD     A,(DE)
        AND    0xF0
        OR    B
        LD    (DE),A
        POP    DE
        INC     DE
        LD      A,(DE)              //search level
        LD      (LWRD SOFT_SLEV),A
        INC     DE
        LD      A,(DE)              //crystal info,bit 6:4 of 02h
        LD      (LWRD WSET_XTAL),A
        LD      A,01H
        LD         (LWRD WSET_STBY),A   //Standby ,bit 0 of 02h
        LD      A,01H
        LD         (LWRD WSET_SM),A     //Search  mode ,bit8 of 02h
        
        
      
         
        CALL    LWRD I2C_init

        POP     DE               //buffer address
        PUSH    DE
        LD      A,01h
        LD    (DE),A
        CALL    LWRD FM_STANDBY_Drv

  
       
      
        CALL    LWRD FMwait50ms 
        LD      E,02H
        LD      C,05H
        //CALL    LWRD SetAGain
        mSetAGain
             
              
        LD      DE,LWRD Analogtempbuf
        LD      A,08H
        LD      (DE),A
        //CALL    LWRD EnableAIn
        mEnableAIn  
        
#if 0       
          CALL    LWRD FMwait50ms 
        LD      DE,LWRD Analogtempbuf
        LD      A,00H
        LD      (DE),A
        INC     DE
//volume set!!   
        LD      A,00H
        LD      (DE),A
        DEC    DE

        mPA_Enable
        
        CALL    LWRD FMwait50ms 
#endif         
        
        LD      DE,LWRD Analogtempbuf
        LD      A,02H
        LD      (DE),A
        INC     DE
//volume set!!   
        LD      A,00H
        LD      (DE),A
        DEC    DE

        mPA_Enable  
        
        



        POP    DE
        POP    BC  
        POP    AF
        RET
//============================================================
/*************************************************************
Function is FM exit and release bus.
入口:  no
**************************************************************/
FM_EXIT_Drv:
        PUSH    AF 
        PUSH    BC
        
        LD    A,0
        LD    E,A
        mPA_SetVolume
        
        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 High 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             //DE is the address of FMStatus_Tab_t which contained 3 bytes:stereo,Freq

         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)
         CP     0x01
         JR      NZ,StorageMono
         LD      A,01H           //stereo mode
         JR     StoragetoBuffer
StorageMono:
     LD     A,0x00          //MOno mode
StoragetoBuffer:
         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
//A传入参数,如果传递的参数是0,则mute,否则释放mute
      LD    C,3
      CP    00H
      JR    Z,MuteSeted
      LD    A,(HL)
      RES    6,A
      LD    (HL),A
      JR    WriteBuffer
MuteSeted:
      LD    A,(HL)
      SET    6,A
      LD    (HL),A
WriteBuffer:
      DEC    C
      JR    Z,MuteExit
      push    BC
      ld    A,2
      ld    C,A
      CALL    LWRD WRITE_ONEFRAME 
      POP    BC
      CP    0x00
      JR    Z,WriteBuffer
      LD    A,01H
MuteExit:        
      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+1
      RES     0,(HL)                 //power disable
      RES     1,(HL)                 //RST disable

      LD      A,(DE)
      LD      (LWRD WSET_STBY),A       //Standby
      CP      00H
      JR      Z,FM_STANDBY_start
      SET     0,(HL)
      
      LD      C,3
FM_STANDBY_start:     
      DEC     C
      JR      Z,FM_STANDBY_exit

    push    BC
    ld    A,8
    ld    C,A
    CALL    LWRD WRITE_ONEFRAME
    pop    BC
         
      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
      RES     5,(HL)
      LD      A,(DE)
      LD      (LWRD WSET_MS),A        //Mono or stereo
      CP      00H
      JR      Z,FM_STEREO_start
      SET     5,(HL)
      
      LD      C,3
FM_STEREO_start:     
      DEC     C
      JR      Z,FM_STEREO_exit
    push    BC
    ld    A,8
    ld    C,A
      CALL    LWRD WRITE_ONEFRAME
      pop    BC
      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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -