It can generate triangle wave, square wave and sine wave. It can also adjust the frequency and amplitude.
It is a classic circuit that must be used when learning electronic technology.
/************************************************************************************
* Frequency meter program
* The single chip microcomputer uses AT89S52, and the crystal frequency is: 12.00MHz.
/******************************************************************************/
#include
unsigned char code SEG_Tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};//digital code segment
unsigned char code DS_Tab[]={0x01,0x02,0x04,0x08};//bit selection code
unsigned char display_buf[]={0,0,0,0};//value to be displayed
unsigned char digit;
sfr SEG_OUT = 0x80;
sfr DS_OUT = 0xa0;
unsigned char temp[4];
unsigned char T0count;
unsigned char timecount;
unsigned long x;
bit flag; //define
void variables main(void)
{
unsigned char i;
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;//open interrupt
while(1)
{
if(flag==1)
{
flag=0;
x=T0count*65536+TH0*256+TL0;//convert frequency to numerical value
for(i=0;i<4;i++)
{
temp=0;
}
i=0;
while(x/10)//assign the value to that bit
{
temp=x%10;
x=x/10;
i++;
}
temp=x;
for(i=0;i<4;i++)
{
display_buf=temp;
}
timecount=0;
T0count=0;
TH0=0;
TL0=0;
TR0=1;//clear T0 counter
}
}
}
void time0(void) interrupt 1 using 1
{
T0count++;
}
void t1(void) interrupt 3 using 0
{
TH1=(65536-4000)/256;//generate one second timing
TL1=(65536-4000)%256;
timecount++;
if(timecount==250)
{
TR0=0;
timecount=0;
flag=1;
}
SEG_OUT = SEG_Tab[display_buf[digit]];//data display of P0 port
DS_OUT = DS_Tab[digit];//bit selection of P2 portif
(++digit > 3)
digit = 0;
}
Previous article:Weighing system based on pressure sensor
Next article:Infrared remote control digital clock with temperature measurement LCD display
Recommended ReadingLatest update time:2024-11-16 13:32
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
- Share a PD fast charging power deception chip CH224 is very practical
- Alloy sampling resistor series
- TI's Class AB car amplifier chip recommendations
- I am majoring in measurement and control, and am planning to work in the embedded system industry. Could you please tell me if this is the right major for me?
- MSP432E401Y MCU intelligent car speed measurement function
- Motor drive video
- Complementary PWM generation and dead zone control module of c2000
- About nRF52xx ADC stability issues
- Guys, please help me, I've been stuck for 3 days and can't figure it out
- Zero Knowledge Open Source Sharing-Zero Knowledge ESP8266 Development Board Released