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

📄 r_w.c

📁 这也是PHILIPS系列A/D解码芯片SAA7115的驱动程序源码
💻 C
字号:
#include<reg51.h>
#include<stdio.h>
#include "i2c.h"


#define WRITE_7115  0x42           //定义7115的芯片写地址
#define READ_7115   0x43           //定义7115的芯片读地址
#define FALSE 0
#define TRUE  1

sbit RES_7115 = 0xA2;
sbit RES_6752 = 0xA3;

sbit REDLED  = 0xA1;
sbit BLUELED = 0xA0;

//以下定义saa6752五种工作模式转换命令
#define soft_reset            0x00        
#define enable                0x01
#define start                 0x02
#define stop                  0x03
#define pause                 0x04
#define reconfigure           0x05
#define sleep                 0x06
#define forced_reconfigure    0x07


#define BYTE_SIZE 64

unsigned int   data  read_reg;               //定义变量存储读得寄存器值
unsigned int   data  option;                 //定义选择标志
unsigned int   data  reg_addr;               //定义寄存器子地址
unsigned int   data  write_reg;              //定义写入寄存器值

unsigned int  xdata reg_buffer[BYTE_SIZE]={0x00};  //定义外部数据缓冲区用于存储多字节写6752寄存器值

unsigned char  code  C2_buffer_PAT[26]={0,71,64,0,16,0,0,176,17,0,0,193,0,0,0,0,224,16,0,1,224,32,211,106,240,172};                //定义数组存储C2地址189个字节的数据
unsigned char  code  C2_buffer_PMT[44]={1,71,64,32,16,0,2,176,35,0,1,193,0,0,225,4,240,12,11,2,64,31,16,6,192,107,108,192,6,0,2,225,0,240,0,3,225,3,240,0,18,47,233,137};
unsigned char  code  C2_buffer_SIT[53]={4,71,64,31,16,0,127,240,44,255,255,193,0,0,240,10,99,8,192,146,124,255,255,255,255,255,0,1,192,19,72,17,7,7,80,104,105,108,105,112,115,7,69,77,80,82,69,83,83,83,94,18,58};





bit address_7115(unsigned int  s_address)                   //向7115写入芯片从地址和片内字节地址  
{                                                  //写入成功则返回1,否则返回0                             
  I_init();
  I_start();
  if(I_send(WRITE_7115))
     return (I_send(s_address));
  else 
     return (FALSE);
}




bit read_7115_single_byte(unsigned int subaddress)                   //对7115片内指定寄存器读取,subaddress为寄存器地址
{ 
                                                             //读得值存于read_reg中,读取成功返回1,否则返回0
  if(address_7115((unsigned char)subaddress))                            
   { 
     I_start();
	 if(I_send(READ_7115))
	   {
	      read_reg=I_receive();
	      return(TRUE);
	   }
     else
	   {
 	      I_stop();
		  return(FALSE);
	   }
   }
  else
   I_stop();
  return(FALSE);

}

bit write_7115_single_byte(unsigned int subaddress,unsigned int write_value)     //对7115片内寄存器写入值,subaddress为寄存器值
{                                                              //write_value为写入值,写入成功返回1,否则返回0
   
  if(address_7115((unsigned char)subaddress)&I_send((unsigned char)write_value))
      I_stop();
   else
      return(FALSE);
   return(TRUE);
}


void main()
{
  unsigned int gl_tndb1,gl_tndb2,gl_tncb,gl_tnbb,gl_tnab;
  unsigned int gl_ifb,gl_ifc,gl_ife;
  unsigned int I;
  unsigned int byte_number;

  SCON = 0x52;
  TMOD = 0x20;
  TCON = 0x69;
  TH1 = 0xfd;
  delay_time(1000);
  I_init();
  REDLED = 1;
  BLUELED = 1;
  RES_7115=0;
  RES_6752=0;
  delay_time(1000);



  //以下为SAA7115配置
  RES_7115=1;
  delay_time(1000);
  write_7115_single_byte( 0x01, 0x08);
  write_7115_single_byte( 0x02, 0xC5);
  write_7115_single_byte( 0x03, 0x20);
  write_7115_single_byte( 0x04, 0x90);
  write_7115_single_byte( 0x05, 0x90);
  write_7115_single_byte( 0x06, 0xEB);
  write_7115_single_byte( 0x07, 0xE0);
  write_7115_single_byte( 0x08, 0xB0);
  write_7115_single_byte( 0x09, 0x40);
  write_7115_single_byte( 0x0A, 0x80);
  write_7115_single_byte( 0x0B, 0x44);
  write_7115_single_byte( 0x0C, 0x40);
  write_7115_single_byte( 0x0D, 0x00);
  write_7115_single_byte( 0x0E, 0x85);
  write_7115_single_byte( 0x0F, 0x2a);
  write_7115_single_byte( 0x10, 0x06);
  write_7115_single_byte( 0x11, 0x00);
  write_7115_single_byte( 0x12, 0x00);
  write_7115_single_byte( 0x13, 0x00);
  write_7115_single_byte( 0x14, 0x01);
  write_7115_single_byte( 0x15, 0x11);
  write_7115_single_byte( 0x16, 0xFE);
  write_7115_single_byte( 0x17, 0xd8);
  write_7115_single_byte( 0x18, 0x40);
  write_7115_single_byte( 0x19, 0x80);
  write_7115_single_byte( 0x1A, 0x77);
  write_7115_single_byte( 0x1B, 0x42);
  write_7115_single_byte( 0x1C, 0xA9);
  write_7115_single_byte( 0x1D, 0x01);

/*
  write_7115_single_byte( 0x30, 0xbc);
  write_7115_single_byte( 0x31, 0xdf);
  write_7115_single_byte( 0x32, 0x02);
  write_7115_single_byte( 0x33, 0x00);
  write_7115_single_byte( 0x34, 0xcd);
  write_7115_single_byte( 0x35, 0xcc);
  write_7115_single_byte( 0x36, 0x3a);
  write_7115_single_byte( 0x37, 0x00);
  write_7115_single_byte( 0x38, 0x03);
  write_7115_single_byte( 0x39, 0x10);
  write_7115_single_byte( 0x3a, 0x00);
*/
  write_7115_single_byte( 0x41, 0x40);
  write_7115_single_byte( 0x42, 0x00);
  write_7115_single_byte( 0x43, 0x00);
  write_7115_single_byte( 0x44, 0x00);
  write_7115_single_byte( 0x45, 0x00);
  write_7115_single_byte( 0x46, 0x00);
  write_7115_single_byte( 0x47, 0x00);
  write_7115_single_byte( 0x48, 0x00);
  write_7115_single_byte( 0x49, 0x00);
  write_7115_single_byte( 0x4a, 0x00);
  write_7115_single_byte( 0x4b, 0x00);
  write_7115_single_byte( 0x4c, 0x00);
  write_7115_single_byte( 0x4d, 0x00);
  write_7115_single_byte( 0x4e, 0x00);
  write_7115_single_byte( 0x4f, 0x00);
  write_7115_single_byte( 0x50, 0x00);
  write_7115_single_byte( 0x51, 0x00);
  write_7115_single_byte( 0x52, 0x00);
  write_7115_single_byte( 0x53, 0x00);
  write_7115_single_byte( 0x54, 0x4f);
  write_7115_single_byte( 0x55, 0x00);
  write_7115_single_byte( 0x56, 0x00);
  write_7115_single_byte( 0x57, 0x00);
  write_7115_single_byte( 0x58, 0x00);
  write_7115_single_byte( 0x59, 0x47);
  write_7115_single_byte( 0x5a, 0x03);
  write_7115_single_byte( 0x5b, 0x03);
  write_7115_single_byte( 0x5c, 0x00);
  write_7115_single_byte( 0x5d, 0x0c);
  write_7115_single_byte( 0x5e, 0x00);

//  write_7115_single_byte( 0x80, 0x90);
//  write_7115_single_byte( 0x81, 0x00);
//  write_7115_single_byte( 0x84, 0x00);
//  write_7115_single_byte( 0x85, 0x00);
//  write_7115_single_byte( 0x86, 0xc5);

  write_7115_single_byte( 0x83, 0x31);
  write_7115_single_byte( 0x87, 0x10);
  write_7115_single_byte( 0x88, 0x8a);
  

  while(1)
 {
  REDLED = ~REDLED;
  printf("\nplease select 1,2,3,4,5,6,7,8,9,10:\n");
  printf("       1:write the FQ1216 Tuner Part.\n");
  printf("       2:Read the FQ1216 Tuner Part.\n");
  printf("       3:write the FQ1216 IF Part.\n");
  printf("       4:Read the FQ1216 IF Part.\n");
  printf("       5:Read the single register in saa6752.\n");
  printf("       6:write the single register in saa6752.\n");
  printf("       7:Read the single register in saa7115.\n");
  printf("       8:write the single register in saa7115.\n");
  printf("       9:Read the multi-byte register in saa6752.\n");
  printf("      10:mode transtion to saa6752: \n");
  scanf("%u",&option);
  if(option==1)
  {
  	printf("\nplease input db1:\n");
	scanf("%x",&gl_tndb1);
	printf("\nplease input db2:\n");
	scanf("%x",&gl_tndb2);
	printf("\nplease input cb:\n");
	scanf("%x",&gl_tncb);
	printf("\nplease input bb:\n");
	scanf("%x",&gl_tnbb);
	printf("\nplease input ab:\n");
	scanf("%x",&gl_tnab);
    write_tuner(gl_tndb1,gl_tndb2,gl_tncb,gl_tnbb,gl_tnab);
  }
  else if(option==2)
  {
    read_tuner();
  }
  else if (option==3)
  {
 	printf("\nplease input b:\n");
	scanf("%x",&gl_ifb);
	printf("\nplease input c:\n");
	scanf("%x",&gl_ifc);
	printf("\nplease input e:\n");
	scanf("%x",&gl_ife);
    write_IF(gl_ifb,gl_ifc,gl_ife);
  }
  else if (option==4)
  {
    read_IF();
  }
  else if(option==5)
  {
	  printf("\nplease input the register address you wanna read:\n");
	  scanf("%x",&reg_addr);
	  if(read_6752_single_byte(reg_addr))
	     printf("\nsuccess and the register value is: %x ",read_reg);
	  else 
	     printf("\nfail to read saa6752.");
  }
  else if(option==6)
  {
	  printf("\nplease input the register address you wanna write:\n");
	  scanf("%x",&reg_addr);
	  printf("\nplease input the register value you wanna write:\n");
      scanf("%x",&write_reg);
	  if(write_6752_single_byte(reg_addr,write_reg))
	     printf("\nsuccess to write saa6752.\n");
	  else
	     printf("fail to write saa6752.\n");
  }
  else if(option==10)
  {
    printf("\nplease input the mode transition:\n");
    scanf("%x",&reg_addr);
    if(mode_transition(reg_addr))
    printf("transition success!");
    else   printf("transition error!");
  }
  else if(option==9)
  {
    printf("\nplease input the  register address you wanna read:\n");
    scanf("%x",&reg_addr);
    printf("\nplease input the register byte number:\n"); 
    scanf("%u",&byte_number);
    if(read_6752_multi_byte( reg_addr , byte_number ))
      printf("read saa6752 success and the register value is:\n");
    for(I=0;I<byte_number;I++)
      printf(" %x \n", reg_buffer[I]);
  }
  else if(option==7)
  {    
      printf("\nplease input the register address you wanna read:\n");
	  scanf("%x",&reg_addr);
	  if(read_7115_single_byte(reg_addr))
	     printf("\nsuccess and the register value is: %x ",read_reg);
	  else 
	     printf("\nfail to read saa7115.\n");
  }
  else if(option==8)
  {
	  printf("\nplease input the register address you wanna write:\n");
	  scanf("%x",&reg_addr);
	  printf("\nplease input the register value you wanna write:\n");
      scanf("%x",&write_reg);
	  if(write_7115_single_byte(reg_addr,write_reg))
	     printf("\nsuccess to write saa7115.\n");
	  else
	     printf("\nfail to write saa7115.\n");
  }
 }  
}



    
  

⌨️ 快捷键说明

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