C'è ancora molto da lavorare e non so nemmeno se le sostituzioni che ho fatto possano funzionare.
#include "Wire.h"
void setup()
{
Wire.begin(66);
}
void loop()
{
}
/* I2C bus the LNB control procedures (PLL chip TSA5522 series) */
// ------------------------------------------------ -------------------------- / /
// Source public / /
// (C) Copyright 2001 - 2003 xuwenjun /
// All Rights Reserved / /
// V1.00 / /
// ------------------------------------------------ -------------------------- / /
// Title: I2C Bus tuner control program (PLL chip TSA5522 series) / /
// File name: xwj_fi1256.c / /
// Version: V1.00 / /
// Modified by: Xu Wenjun E - mail at: xuwenjun@21cn.com / /
// Date: 06 - 02 - 26 Initial Public / /
// Description: I2C Bus tuner control program (PLL chip TSA5522 series) / /
// Declare:
//
// The following code is only provided free of charge to learning purposes, but must be declared in the file referenced or modified Source / /
// For commercial use please contact the author. E - mail: xuwenjun@21cn.com / /
// Please the mailto xuwenjun@21cn.com I welcome the exchange! / /
// ------------------------------------------------ -------------------------- / /
// The old version: no old version of the file name:
//
// Create: Xu Wenjun E - mail: xuwenjun@21cn.com / /
// Date: 06 - 02 - 26 / /
// Description:
//
// ------------------------------------------------ -------------------------- //
/* Frequency for KHz */
/* image of the TV-IF signal of the IF frequency is 38MHz. Audio intermediate frequency signal is 6.5MHz. */
#define FUENCY 38900UL
/* high frequency data bytes */
#define PLLdataH(f) ((f + FUENCY) * 16 / 1000 / 256)
/* low frequency data 2 bytes */
#define PLLdataL(f) ((f + FUENCY) * 16 / 1000 % 256)
/* control word 1 byte */
#define PLLCON1 0x8e
/* Control word 4 bytes */
#define PLLcon2(f) (((f)<(168000UL))?(0xA0):(((f)>(450000UL))?(0x90):(0x30)))
#define PLLdata3(fchan) PLLdataH(fchan), PLLdataL(fchan), PLLcon2(fchan)
unsigned char ucdataTab [] [3] =
{
PLLdata3(49750), /* channel DS1 (VL) */
PLLdata3(57750), /* Channel DS2 */
PLLdata3(65750), /* Channel DS3 */
PLLdata3(77250), /* Channel DS4 */
PLLdata3(85250), /* Channel DS5 */
PLLdata3(112250), /* Channel Z1 */
PLLdata3(120250), /* Channel Z2 */
PLLdata3(128250), /* Channel Z3 */
PLLdata3(136250), /* Channel Z4 */
PLLdata3(144250), /* Channel Z5 */
PLLdata3(152250), /* Channel Z6 */
PLLdata3(160250), /* Channel Z7 */
PLLdata3 (168250), /* Channel DS6 (VH) */
PLLdata3 (176250), /* Channel DS7 */
PLLdata3 (184250), /* Channel DS8 */
PLLdata3 (192250), /* Channel DS9 */
PLLdata3 (200250), /* Channel DS10 */
PLLdata3 (208250), /* Channel DS11 */
PLLdata3 (216250), /* Channel DS12 */
PLLdata3 (224250), /* Channel Z8 */
PLLdata3 (232250), /* Channel Z9 */
PLLdata3 (240250), /* Channel Z10 */
PLLdata3 (248250), /* Channel Z11 */
PLLdata3 (256250), /* Channel Z12 */
PLLdata3 (264250), /* Channel Z13 */
PLLdata3 (272250), /* Channel Z14 */
PLLdata3 (280250), /* Channel Z15 */
PLLdata3 (288250), /* Channel Z16 */
PLLdata3 (296250), /* Channel Z17 paragraphs */
PLLdata3 (304250), /* Channel Z18 */
PLLdata3 (312250), /* Channel Z19 */
PLLdata3 (320250), /* Channel Z20 */
PLLdata3 (328250), /* Channel Z21 */
PLLdata3 (336250), /* Channel Z22 */
PLLdata3 (344250), /* Channel Z23 */
PLLdata3 (352250), /* Channel Z24 */
PLLdata3 (360250), /* Channel Z25 */
PLLdata3 (368250), /* Channel Z26 */
PLLdata3 (376250), /* Channel Z27 */
PLLdata3 (384250), /* Channel Z28 */
PLLdata3 (392250), /* Channel Z29 */
PLLdata3 (400250), /* Channel Z30 */
PLLdata3 (408250), /* Channel Z31 */
PLLdata3 (416250), /* Channel Z32 */
PLLdata3 (424250), /* Channel Z33 */
PLLdata3 (432250), /* Channel Z34 */
PLLdata3 (440250), /* Channel Z35 */
PLLdata3 (448250), /* Channel Z36 */
PLLdata3 (456250), /* Channel Z37 (UHF) */
PLLdata3 (464250), /* Channel Z38 */
PLLdata3 (471250), /* Channel DS13 */
PLLdata3 (479250), /* Channel DS14 */
PLLdata3 (487250), /* Channel DS15 */
PLLdata3 (495250), /* Channel DS16 */
PLLdata3 (503250), /* Channel DS17 */
PLLdata3 (511250), /* Channel DS18 */
PLLdata3 (519250), /* Channel DS19 */
PLLdata3 (527250), /* Channel DS20 */
PLLdata3 (535250), /* Channel DS21 */
PLLdata3 (543250), /* Channel DS22 */
PLLdata3 (551250), /* Channel DS23 */
PLLdata3 (559250), /* Channel DS24 */
PLLdata3 (607250), /* Channel DS25 */
PLLdata3 (615250), /* Channel DS26 */
PLLdata3 (623250), /* Channel DS27 */
PLLdata3 (631250), /* Channel DS28 */
PLLdata3 (639250), /* Channel DS29 */
PLLdata3 (647250), /* Channel DS30 */
PLLdata3 (655250), /* Channel DS31 */
PLLdata3 (663250), /* Channel DS32 */
PLLdata3 (671250), /* Channel DS33 */
PLLdata3 (679250), /* Channel DS34 */
PLLdata3 (687250), /* Channel DS35 */
PLLdata3 (695250), /* Channel DS36 */
PLLdata3 (703250), /* Channel DS37 */
PLLdata3 (711250), /* Channel DS38 */
PLLdata3 (719250), /* Channel DS39 */
PLLdata3 (727250), /* Channel DS40 */
PLLdata3 (735250), /* Channel DS41 */
PLLdata3 (743250), /* Channel DS42 */
PLLdata3 (751250), /* Channel DS43 */
PLLdata3 (759250), /* Channel Measures affecting consumer photographic */
PLLdata3 (767250), /* Channel DS45 */
PLLdata3 (775250), /* Channel DS46 */
PLLdata3 (783250), /* Channel DS47 */
PLLdata3 (791250), /* Channel DS48 */
PLLdata3 (799250), /* Channel DS49 */
PLLdata3 (807250), /* Channel DS50 */
PLLdata3 (815250), /* Channel DS51 */
PLLdata3 (823250), /* Channel DS52 */
PLLdata3 (831250), /* Channel DS53 */
PLLdata3 (839250), /* Channel DS54 */
PLLdata3 (847250), /* Channel DS55 */
PLLdata3 (855250), /* Channel DS56 */
PLLdata3 (863250), /* Channel DS57 */
PLLdata3 (90100 - 6500), /* economic units (FM radio) */
PLLdata3 (91000 - 6500), /* economy */
PLLdata3 (91800 - 6500), /* traffic */
PLLdata3 (97500 - 6500), /* and Taiwan */
PLLdata3 (100300 - 6500), /* traffic */
PLLdata3 (103200 - 6500), /* News Channel */
PLLdata3 (105000 - 6500), /* the Xingsha of sound */
PLLdata3 (106500 - 6500), /* Music */
};
/* I2C variable */
#define AddPllWr 0xc2 /*TSA5522 write address */
#define AddPllRd 0xc3 /*TSA5522 read address */
// sbit SDA = P0 ^ 4; /* Serial Data ---------- - P0 .4 */
// sbit SCL = P0 ^ 5; /* Serial Clock ---------- - P0 .5 */
/* I2C function */
void Start (void);
void Stop (void);
void SendACK (void);
void SendNoACK (void);
unsigned char sendByte (unsigned char d);
unsigned char readByte (void);
void SetChan (unsigned char chan);
unsigned char ReadChan (void);
/* -------- Select the channel -------------------------------------- ------ */
void SetChan (unsigned char chan)
{
Start (); /* Send the I2C bus START condition */
SendByte (AddPllWr); /* Send the controller bus write address */
SendByte (ucdataTab [chan] [0]); /* send high frequency data bytes */
SendByte (ucdataTab [chan] [1]); /* send low frequency data bytes */
SendByte (PLLCON1); /* send control word 1 byte */
SendByte (ucdataTab [chan] [2]); /* send control word 1 byte */
Stop (); /* Send the I2C bus stop condition */
}
/* ---------- - Read Status ---------------------------------- - ---------- - */
unsigned char ReadChan (void)
{
unsigned char i;
Start (); /* Send the I2C bus START condition */
SendByte (AddPllRd); /* Send the controller bus read address */
i = readByte ();
SendNoACK (); /* last byte, send non - response signal */
Stop (); /* Send the I2C bus stop condition */
return (i);
}
/* ------------ Byte data transfer subroutine to send a byte of data or address to the controller -------------- - */
unsigned char SendByte (unsigned char a)
{
Wire.write(byte(a));
return 0;
}
/* ------------------------------------------------ -------------------------- - */
unsigned char ReadByte (void) /* data reception subroutine receives a byte of data from the controller */
{
unsigned char Sin;
Sin = Wire.read();
return Sin;
}
/* ---------- - Send an Acknowledge bit ---------------------------------- ---------------- */
void SendACK ()
{
Wire.write(byte(0x01));
}
/* ------------ Send non - acknowledge bit -------------------------------- -------------- - */
void SendNoACK ()
{
Wire.write(byte(0x00));
}
/* ------------------------------------------------ -------------------------- - */
void Start (void) /* START start the I2C bus subroutine send I2C start condition */
{
Wire.beginTransmission(66);
}
/* ---------- - STOP Stop the I2C bus subroutine to send I2C bus stop condition ------------------ - */
void Stop (void)
{
Wire.endTransmission(66);
}