Classic function signal generator

Publisher:平和宁静Latest update time:2017-12-01 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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;
}

Reference address:Classic function signal generator

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

Design of Spectral Data Acquisition System Based on AT89S52 Control
Overview In spectral measurement, photomultiplier tubes (PMT) and charge-coupled devices (CCD) are often used as photoelectric converters. PMT is used in slow-changing, high-precision spectral measurements; CCD is used for spectral signals whose intensity changes over time, such as flash, fluorescence, and phosphore
[Microcontroller]
Design of Spectral Data Acquisition System Based on AT89S52 Control
AT89S52 and DS18B20 digital temperature sensor testing completed
/***********************************************************************  * Use four-digit common cathode digital tube R42056K, P1 port connects to digital tube segment code. P0.0 connects to the first digit * P0.1 connects to the second digit, p0.2 connects to the third digit, and p0.3 connects to the fourth digit. *
[Microcontroller]
Hardware Design of LED Display Screen Based on AT89S52 and ATF1508AS
0 Introduction The LED display screen is mainly composed of three parts: current drive circuit and LED dot matrix array, control system and PC management software (Figure 1). The control system is responsible for receiving, converting and processing various external signals, and realizing scanning control, and
[Microcontroller]
Hardware Design of LED Display Screen Based on AT89S52 and ATF1508AS
Design of sound and light control switch based on AT89S52 single chip microcomputer
With the development of electronic technology, especially the development of digital technology, it is becoming more and more important to use digital circuit technology to realize the automatic lighting of lights, energy saving and power saving, and extend the life of lights, and it is close to real life. The sound a
[Power Management]
Design of sound and light control switch based on AT89S52 single chip microcomputer
Wireless remote control switch system for long-distance lighting control based on AT89S52
1 System Design With the continuous development of electronic technology, wireless technology plays an increasingly important role in intelligence. This design is a wireless remote control switch system that can realize long-distance lighting control. It consists of two parts: the transmitting system and the receivi
[Microcontroller]
Wireless remote control switch system for long-distance lighting control based on AT89S52
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号