📄 r_w.c.bak
字号:
#include<reg51.h>
#include<stdio.h>
#include "i2c.h"
#define WRITE_6752 0x40 //定义6752的芯片写地址
#define READ_6752 0x41 //定义6752的芯片读地址
#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};
//定义6752模式转换命令函数,command_name为上面定义的八个命令之一
bit mode_transition(unsigned int command_name)
{
I_init();
I_start();
if(command_name<=0x07&&command_name>=0x00)
{
if(I_send(WRITE_6752))
return (I_send((unsigned char)command_name));
else
return ( FALSE );
}
else
{
printf("\ncommmand name error!\n");
return ( FALSE );
}
}
bit address_6752(unsigned int s_address) //向6752写入芯片从地址和片内字节地址
{ //写入成功则返回1,否则返回0
I_init();
I_start();
if(I_send(WRITE_6752))
return (I_send(s_address));
else
return (FALSE);
}
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);
}
bit read_6752_single_byte(unsigned int subaddress) //对6752片内指定寄存器读取,subaddress为寄存器地址
{ //读得值存于read_reg中,读取成功返回1,否则返回0
if(address_6752((unsigned char)subaddress))
{
I_start();
if(I_send(READ_6752))
{
read_reg=I_receive();
return(TRUE);
}
else
{
I_stop();
return(FALSE);
}
}
else
I_stop();
return(FALSE);
}
bit read_6752_multi_byte(unsigned int subaddress, unsigned int byte_num )
{
int i;
if(address_6752((unsigned char)subaddress))
{
I_start();
if(I_send(READ_6752))
{
for( i=0; i<byte_num; i++)
{
reg_buffer[i]=( I_receive() );
if(i!=byte_num)
I_Ack();
else
{
I_clock();
I_stop();
}
}
return ( TRUE );
}
else
{
I_stop();
return ( FALSE );
}
}
else
I_stop();
return ( FALSE );
}
bit write_6752_single_byte(unsigned int subaddress, unsigned int write_value) //对6752片内寄存器写入值,subaddress为寄存器值
{ //write_value为写入值,写入成功返回1,否则返回0
if(address_6752((unsigned char)subaddress)&I_send((unsigned char)write_value))
I_stop();
else
return(FALSE);
return(TRUE);
}
bit write_6752_multi_byte( unsigned int subaddress, unsigned int byte_num)
{
int i;
if(address_6752((unsigned char)subaddress))
{
for( i=0; i<byte_num; i++)
{
if(I_send((unsigned char)reg_buffer[i]))
continue;
else
{
printf("write 6752 multi error! ");
return( FALSE );
}
}
I_stop();
}
return(TRUE);
}
bit write_6752_PAT(void)
{
int i;
if(address_6752(0xC2))
{
for( i=0; i<26; i++)
{
if(I_send(C2_buffer_PAT[i]))
continue;
else
{
printf("\nwrite 6752 PAT ERROR!\n");
return( FALSE );
}
}
I_stop();
}
else
return (FALSE);
return(TRUE);
}
bit write_6752_PMT(void)
{
int i;
if(address_6752(0xC2))
{
for( i=0; i<44; i++)
{
if(I_send(C2_buffer_PMT[i]))
continue;
else
{
printf("\nwrite 6752 PMT ERROR!\n");
return( FALSE );
}
}
I_stop();
}
else
return (FALSE);
return(TRUE);
}
bit write_6752_SIT(void)
{
int i;
if(address_6752(0xC2))
{
for( i=0; i<53; i++)
{
if(I_send(C2_buffer_SIT[i]))
continue;
else
{
printf("\nwrite 6752 SIT ERROR!\n");
return( FALSE );
}
}
I_stop();
}
else
return (FALSE);
return(TRUE);
}
void write_tuner(unsigned int tndb1,unsigned int tndb2,unsigned int tncb,unsigned int tnbb,unsigned int tnab)
{
I_init();
I_start();
if(!I_send(0xC2))
printf("\n write 1216 error!1 \n");
if(!I_send((unsigned char)tndb1))
printf("\n write 1216 error!2 \n");
if(!I_send((unsigned char)tndb2))
printf("\n write 1216 error!3 \n");
if(!I_send((unsigned char)tncb))
printf("\n write 1216 error!4 \n");
if(!I_send((unsigned char)tnbb))
printf("\n write 1216 error!5 \n");
if(I_send((unsigned char)tnab))
{
I_stop();
printf("\n write 1216 ok1 \n");
}else printf("\n write 1216 error!6 \n");
}
void read_tuner (void)
{
I_init();
I_start();
if(I_send(0xC3))
{
read_reg=I_receive();
I_stop();
printf("\nthe Tuner Part Status Byte is %x", read_reg);
}
}
void write_IF (unsigned int ifb,unsigned int ifc,unsigned int ife)
{
I_init();
I_start();
if(I_send(0x86))
{
if(I_send(0x00))
{
if(I_send((unsigned char)ifb))
{
I_stop();
printf("\n write 1216 ok16 \n");
}
else
{
I_stop();
printf(" write IF error!");
}
}
else
{
I_stop();
printf(" write IF error!");
}
}
else
{
I_stop();
printf(" write IF error!");
}
I_start();
if(I_send(0x86))
{
if(I_send(0x01))
{
if(I_send((unsigned char)ifc))
{
I_stop();
printf("\n write 1216 ok70 \n");
}
else
{
I_stop();
printf(" write IF error!");
}
}
else
{
I_stop();
printf(" write IF error!");
}
}
else
{
printf(" write IF error!");
I_stop();
}
I_start();
if(I_send(0x86))
{
if(I_send(0x02))
{
if(I_send((unsigned char)ife))
{
I_stop();
printf("\n write 1216 ok4b \n");
}
else
{
I_stop();
printf(" write IF error!");
}
}
else
{
I_stop();
printf(" write IF error!");
}
}
else
{
I_stop();
printf(" write IF error!");
}
}
void read_IF (void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -