//This program uses digital tube to display frequency, crystal oscillator is 12M, has passed the test, has been made into finished product with universal board,
//There are photos made with universal board in my QQ space, high-definition photos can be viewed in QQ album, my space is not encrypted.
//In order to facilitate electronic enthusiasts to make their own, this program has macro definitions for all ports, which is convenient for beginners to modify by themselves, and adds a lot of comments
//Written by Mr. Chen Yongfei on February 19, 2011, QQ: 49204743, email: baiyni888@163.com .
//Address: Caochangmen Branch of Suning Appliance After-sales Service Center, No. 180 Huju Road, Gulou District, Nanjing City, Jiangsu Province
//The frequency adjustment of this radio is calculated by calculation. The displayed frequency is calculated and written into the TEA5767 chip to realize the adjustment
//Use MCS-51 single-chip microcomputer for control, two buttons to realize self-increase or self-decrease frequency, and add continuous addition and subtraction function!
//I used a simplified version of the TEA5767 module bought on Taobao for 4.5 yuan per piece. I received ten radio stations in Nanjing.
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
///
...
led3=P2^6; //Frequency display digital tube bit selection port 1M, P2.6 port /////port
sbit led4=P2^7; //Frequency display digital tube bit selection port 0.1M, P2.7 port /////,
sbit SDA=P3^0; //Connected to the data port of TEA5767 /////can
sbit SCL=P3^1; //Connected to the clock port of TEA5767 /////with
sbit KEY1=P1^0; //Frequency increase button port /////self
sbit KEY2=P1^1; //Frequency decrease button port /////line
#define duan P0 //Frequency display digital tube segment selection P0 port /////
Revise
//unsigned char radio_write_data[5]={0x33,0x8e,0x70,0x16,0x80}; //Data to be written into TEA5767, 107.9M Jiangsu Tourism Station
//unsigned char radio_write_data[5]={0x32,0x8e,0x70,0x16,0x80}; //Data to be written into TEA5767, 105.8M Nanjing Music Station
//unsigned char radio_write_data[5]={0x31,0xd7,0x70,0x16,0x80}; //Data to be written into TEA5767, 104.3M Nanjing Sports Station
//unsigned char radio_write_data[5]={0x30,0x9a,0x70,0x16,0x80}; //Data to be written into TEA5767, 101.7M Nanjing Economic Station City FM
unsigned char radio_write_data[5]={0x30,0x50,0x70,0x16,0x80}; //Data to be written into TEA5767, 101.1M Jiangsu Traffic Radio Network
//unsigned char radio_write_data[5]={0x2f,0xa5,0x70,0x16,0x80}; //Data to be written into TEA5767, 99.7M Jiangsu Golden Color FM
//unsigned char radio_write_data[5]={0x2c,0xc9,0x70,0x16,0x80}; //Data to be written into TEA5767, 97.5M Jiangsu Literature and Art Station
//unsigned char radio_write_data[5]={0x2c,0xc9,0x70,0x16,0x80}; //Data to be written into TEA5767, 93.7M Jiangsu Economic Station Home Broadcast
//unsigned char radio_write_data[5]={0x2b,0xb0,0x70,0x16,0x80}; //Data to be written into TEA5767, 91.4M Jiangsu Broadcast
//unsigned char radio_write_data[5]={0x2a,0xe1,0x70,0x16,0x80}; //Data to be written into TEA5767, 89.7M Jiangsu Music Station
unsigned long frequency=101100; //The radio frequency initialized at power on is 101.1MHz
unsigned int pll; //Variable used to calculate frequency synthesis
void Delayus(unsigned char x)
{
for(;x>0;x--);
}
void iic_start()
{
SDA=1;
Delayus(4);
SCL=1;
Delayus(4);
SDA=0;
Delayus(4);
SCL=0;
Delayus(4);
}
void iic_stop()
{
SCL=0;
Delayus(4);
SDA=0;
Delayus(4);
SCL=1;
Delayus(4);
SDA=1;
Delayus(4);
}
void iic_ack()
{
SDA=0;
Delayus(4);
SCL=1;
Delayus(4);
SCL=0;
Delayus(4);
SDA=1;
Delayus(4);
}
bit iic_testack()
{
bit ErrorBit;
SDA=1;
Delayus(4);
SCL=1;
Delayus(4);
ErrorBit=SDA;
Delayus(4);
SCL=0;
return ErrorBit;
}
void iic_write8bit(unsigned char input)
{
unsigned char temp;
for(temp=8;temp>0;temp--)
{
SDA=(bit)(input&0x80);
Delayus(4);
SCL=1;
Delayus(4);
SCL=0;
Delayus(4);
input=input<<1;
}
}
[page]
void delays (unsigned char b) //Delay program for key debounce
{
unsigned char i;
for(b;b>0;b--)
for(i=0;i<250;i++);
}
void radio_write(void)
{
unsigned char i;
iic_start();
iic_write8bit(0xc0); //TEA5767 write address
if(!iic_testack())
{
for(i=0;i<5;i++)
{
iic_write8bit(radio_write_data[i ]);
iic_ack();
}
}
iic_stop();
}
//Calculate the displayed frequency and write it to the TEA5767 chip for adjustment. Don't consider the related bits used by TEA5767 for searching channels: SM, SUD
void search()
{
pll=(unsigned int)((float)((frequency+225))/(float)8.192); //Calculate the synthesized frequency data, frequency unit: k
radio_write_data[0]=pll/256; //Write the calculated high-order frequency data into TEA5767
radio_write_data[1]=pll%256; //Write the calculated low-order frequency data into TEA5767
radio_write_data[2]=0x70; //This is TEA5767 stereo on, mute off
radio_write_data[3]=0x16; //Chinese standard, using 32768 crystal oscillator, soft mute off, stereo noise cancellation on
radio_write_data[4]=0x80; //6.5M phase-locked loop on, de-emphasis time 75US
radio_write();
}
void delay()
{
uchar k;
for(k=0;k<100;k++);
}
void desplay(uint aa)
{
duan=tab[aa/1000]|0x80; //Turn off the decimal point of this digital tube
led1=0;
delay();
led1=1;
duan=tab[aa%1000/100]|0x80; //Turn off the decimal point of this digital tube
led2=0;
delay();
led2=1;
duan=tab[aa%100/10]&0x7f; //light up the decimal point of this digital tube
led3=0;
delay();
led3=1;
duan=tab[aa%10]|0x80; //Turn off the decimal point of this digital tube
led4=0;
delay();
led4=1;
}
void main()
{
radio_write(); //Write to initialize the radio frequency
while(1)
{
if(!KEY1) //Manually set the frequency, +0.1MHz;
{
delays(250); //Delay debounce
frequency+=100;
if(frequency>108500) //If the frequency is greater than 108.5MHz
frequency=87500; //Set the frequency to 87.5MHz
search();
desplay(frequency/100); //Call display
}
if(!KEY2) //manually set frequency, -0.1MHz;
{
delays(250); //delay debounce
frequency-=100;
if(frequency<87500) //if the frequency is less than 87.5MHz
frequency=108500; //set the frequency to 108.5MHz
search();
desplay(frequency/100); //call display
}
desplay(frequency/100); //call display
}
}
Previous article:General EEPROM test program for STC12C2052 and 11/10xx series MCU
Next article:Atmega8 model segmentation difference
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- RSL10 rich board set!
- What challenges do you face in powering handling and harvesting robots? Let’s talk with Vicor engineers!
- What is the continuity threshold used for? Analysis of the wiring harness tester function
- Does DDR design require back drilling?
- [Integrated subway security control system based on Raspberry Pi 400] Material unboxing - Raspberry Pi 400
- SinA332.0 development board Linux & Qt adjust VGA resolution to 1280x720
- Single chip microcomputer CPU card programming system main frequency setting
- Award-winning live broadcast: Microchip's trusted platform for the CryptoAuthentication family
- What is the Internet of Things? What is the concept of the Internet of Things?
- DSP 2407 Book Request