====================================
At the beginning, the program was successfully received by referring to the examples of ouravr netizens. Because the Hex file generated by the program is too large to be 2051 loaded, it was just published on the blog and there was no time to sort it out. Later, Jiang of Shenzhen guangshimei Electronics Co., Ltd. sent me a reference code for sp3767. By studying sp3767 code, he found many good ideas and methods, combined with the programs I wrote, modify to the current program.
====================================
We would like to thank ouravr and Shenzhen guangshi Meimei Electronics Co., Ltd. for providing the program.
Ouravr user original post address: http://www.ouravr.com/bbs/bbs_content.jsp? Bbs_sn = 1117837 & bbs_page_no = 1 & search_mode = 1 & search_text = 5767 & bbs_id = 9999
====================================
# Include <reg51.h> <br/> # include <math. h> <br/> # include <I2C. c> <br/> sbit key_0 = p1 ^ 2; // S3 key, automatically rounded up <br/> sbit key_1 = p1 ^ 3; // S2 key, automatic downloading <br/> sbit key_2 = p1 ^ 4; // S1 key, manual reception <br/> sbit have = P3 ^ 7; // collection flag, <br/> sbit band = P3 ^ 5; // boundary flag, indicates that the frequency reaches the minimum or maximum value <br/> # define max_freq 1080 <br/> # define min_freq 875 <br/> # define point 0xfe // decimal point <br/> unsigned char code led_7 [10] = {0x03, 0x9f, 0x25, 0x0d, 0x99,0x49,0X41, 0x1f, 0x01,0x09}; // 0 .. 9. digital tube segment code table <br/> unsigned char dis_buff [4] = {3, 5, 9, 0}; // display the buffer zone, low front <br/> unsigned char radio_write_data [5] = {0x2d, 0x56, 0x20, 0x11, 0x00 }; // data to be written into TEA5767 <br/> unsigned char radio_read_data [5]; // status read from TEA5767 <br/> unsigned int default_pll = 0x2d56; // 0x2d56; // The PLL of the default storage unit, 95.3 MHz <br/> unsigned int PLL; <br/> unsigned long frequency = 935; <br/> unsigned int max_pll = 0x339b; // PLL at 108mhz, <br/> unsigned int min_pll = 0x9000; // PLL at 70 MHz '<br/> void uart_send_byte (unsigned char dat) <br/> {<br/> sbuf = dat; <br/> while (Ti = 0); // wait cyclically <br/> Ti = 0; <br/>}< br/> // calculate the PLL by frequency <br/> void get_pll (void) <br/>{< br/> unsigned char hlsi; <br/> unsigned int twpll = "0"; <br/> hlsi = "radio" _ write_data [2] & 0x10; <br/> If (hlsi) <br/> PLL = (frequency * 100000) + 225000)> 13; // Frequency Unit: K; <br/> else <br/> PLL = (frequency * 100000)-225000)> 13; // Frequency Unit: k <br/>}< br/> // frequency calculated by the PLL <br/> void get_frequency (void) <br/>{< br/> unsigned char hlsi; <br/> unsigned int npll = "0"; <br/> npll = "PLL "; <br/> hlsi = "radio" _ write_data [2] & 0x10; <br/> If (hlsi) <br/> frequency = (unsigned long) npll <13)-225000)/100000) + 1; // Frequency Unit: kHz <br/> else <br/> frequency = (unsigned long) npll <13) + 225000)/100000) + 1; // Frequency Unit: kHz <br/>}< br/> // The frequency value is sent to the display buffer, low front <br/> // high 108.0 low MHz <br/> // ------------------ <br/> // number of digits: <br/> void frequency_to_disbuff (void) <br/>{< br/> // unsigned long fre; <br/> // fre = f/100; <br/> dis_buff [3] = Frequency/1000; // 1st bits, 1080/1000 = 1 <br/> dis_buff [2] = Frequency/100% 10; // 2nd bits, 1080/100 = 100/10 = 0 <br/> dis_buff [1] = frequency % 3rd; // bits, 1080% 100 = 80, 80/10 = 8 <br/> dis_buff [0] = frequency % 10; // 4th bits, 1080% 10 = 0 <br/>}< br/> void fm_dis (void) <br/>{< br/> frequency_to_disbuff (); <br/> uart_send_byte (led_7 [dis_buff [0]); <br/> uart_send_byte (led_7 [dis_buff [1] & Point ); <br/> uart_send_byte (led_7 [dis_buff [2]); <br/> If (dis_buff [3] = 0) <br/> uart_send_byte (0xff ); <br/> else <br/> uart_send_byte (led_7 [dis_buff [3]); <br/>}< br/> // write 5767 <br/> void radio_write (void) <br/>{< br/> unsigned char I; <br/> iic_start (); <br/> iic_write8bit (0xc0); // TEA5767 write address <br/> waitack (); <br/> for (I = 0; I <5; I ++) <br/>{< br/> iic_write8bit (radio_write_data [I]); <br/> waitack (); <br/>}< br/> iic_stop (); <br/>}< br/> // read the TEA5767 status, convert it to frequency <br/> void radio_read (void) <br/>{< br/> unsigned char I; <br/> unsigned char temp_l, temp_h; <br/> PLL = "0"; <br/> iic_start (); <br/> iic_write8bit (0xc1); // TEA5767 read address <br/> waitack (); <br/> for (I = 0; I <5; I ++) <br/> {<br/> radio_read_data [I] = iic_read8bit (); <br/> iic_ack (); <br/>}< br/> iic_stop (); <br/> temp_l = radio_read_data [1]; <br/> temp_h = radio_read_data [0]; <br/> temp_h & = 0x3f; <br/> PLL = "Temp" _ H * 256 + temp_l; <br/> get_frequency (); <br/>}< br/> // set the frequency manually, mode = 1, + 0.1 MHz; mode = "0:-0 ". 1 MHz. You do not need to consider the related slots used by TEA5767 for the Search: Sm, Sud <br/> void search () <br/>{< br/> radio_read (); <br/> Frequency ++; <br/> If (frequency> max_freq) <br/>{< br/> frequency = min_freq; <br/> band = 0; <br/>}< br/> else <br/> band = 1; <br/> get_pll (); <br/> radio_write_data [0] = PLL/256; <br/> radio_write_data [1] = PLL % 256; <br/> radio_write_data [2] = 0x20; <br/> radio_write_data [3] = 0x11; <br/> radio_write_data [4] = 0x00; <br/> radio_write (); <br/>}< br/> // automatically searches for servers, increase the frequency of searching <br/> void auto_searchup () <br/> {<br/> radio_read (); <br/> If (frequency> max_freq) <br/>{< br/> frequency = min_freq; <br/> band = 0; <br/>}< br/> else <br/> band = 1; <br/> get_pll (); <br/> radio_write_data [2] = 0xa0; <br/> radio_write_data [0] = PLL/256 + 0x40; <br/> radio_write_data [1] = PLL % 256; <br/> radio_write_data [3] = 0x11; <br/> radio_write_data [4] = 0x00; <br/> radio_write (); <br/> radio_read (); <br/>}< br/> // automatically searches for servers, reduced frequency search <br/> void auto_searchdown () <br/> {<br/> radio_read (); <br/> If (frequency <min_freq) <br/>{< br/> frequency = max_freq; <br/> band = 0; <br/>}< br/> else <br/> band = 1; <br/> get_pll (); <br/> radio_write_data [2] = 0x20; <br/> radio_write_data [0] = PLL/256 + 0x40; <br/> radio_write_data [1] = PLL % 256; <br/> radio_write_data [3] = 0x11; <br/> radio_write_data [4] = 0x00; <br/> radio_write (); <br/> radio_read (); <br/>}</P> <p> // Ms latency <br/> void delay (unsigned int I) <br/>{< br/> unsigned char J; <br/> do {<br/> J = 163; <br/> DO <br/>{< br/>}< br/> while (j --); <br/>}< br/> while (I --); <br/>}< br/> void main () <br/> {<br/> scon = 0x00; // serial port initialization, working mode 0, synchronous shift register output mode <br/> fm_dis (); <br/> delay (10); <br/> radio_write (); <br/> while (1) <br/>{< br/> radio_read (); <br/> P1 = 0xff; <br/> If (radio_read_data [0] & 0x80) // indicates that the server is successfully searched. <br/> have = 0; <br/> else <br/> have = 1; </P> <p> // search for servers up <br/> If (key_0 = 0) <br/>{< br/> delay (10); <br/> If (key_0 = 0) <br/>{< br/> auto_searchup (); <br/> while (key_0 = 0) <br/>{< br/> fm_dis (); <br/> delay (5 ); <br/>}< br/> // search for servers <br/> If (key_1 = 0) <br/>{< br/> If (key_1 = 0) <br/>{< br/> auto_searchdown (); <br/> while (key_1 = 0) <br/>{< br/> fm_dis (); <br/> delay (5 ); <br/>}< br/> // manually search for servers, increase the frequency of each press + 0.1 MHz <br/> If (key_2 = 0) <br/>{< br/> If (key_2 = 0) <br/>{< br/> Search (); <br/> while (key_2 = 0) <br/>{< br/> fm_dis (); <br/> delay (5); <br/>}< br/>}