51proteus simulation: generating sine waves

Publisher:RoboPilotLatest update time:2017-01-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The simulation circuit diagram is the same as the circuit diagram for generating sawtooth wave .

The program is timed using interrupts.

The C program is as follows:

 

#include
sbit CS0=P3^0;
sbit WR0=P3^1; 
bit flag=0; 
unsigned char i=0;   
unsigned char code sin_num[]={     
      0,0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2,
   2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
      10, 10, 11, 12, 12, 13, 14, 15, 15, 16, 17, 18, 18, 19, 20, 21,
   22, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37,
      38, 39, 40, 41, 42, 44, 45, 46, 47, 49, 50, 51, 52, 54, 55, 56,
      57, 59, 60, 61, 63, 64, 66, 67, 68, 70, 71, 73, 74, 75, 77, 78,
    80, 81, 83, 84, 86, 87, 89, 90, 92, 93, 95, 96, 98, 99, 101,102,
   104, 106, 107, 109, 110, 112,    113, 115, 116, 118, 120, 121, 123, 124, 126, 128,
   129, 131,    132, 134, 135,    137,    139, 140, 142, 143, 145, 146, 148,    149, 151, 153,
   154, 156, 157, 159, 160, 162, 163, 165,    166, 168, 169, 171, 172, 174, 175, 177,
   178, 180, 181,    182, 184, 185, 187, 188, 189, 191, 192, 194, 195, 196, 198, 199,
   200, 201, 203, 204, 205, 206, 208, 209, 210, 211, 213, 214, 215, 216, 217, 218, 
   219, 220, 221, 223, 224, 225, 226, 227, 228, 229, 230, 230, 231, 232, 233, 234, 
   235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 245, 246, 
   246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 251,    251, 252, 252, 253, 253, 
   253, 253, 254, 254, 254, 254, 254, 255, 255, 255, 255,    255, 255, 255, 255, 255


      }; //This is the sampling of the rising half cycle of the sine wave


 void sinn() interrupt 1
 {
   if(flag==0)
   {   
     P2=sin_num[i++];
     if(i==0){flag=1;i=255;}
   }
   else
   {
   P2=sin_num[i--];
   if(i==255){flag=0;i=0;}
   }

 }

main()
{

   TMOD=0X01; //Counter T0, self-start, timing, mode 1
   TH0=0xff; //Select counter T0
   TL0=0x00;
   IT0=1; //Set interrupt trigger mode, falling edge
   EA=1; //Open interrupt
   EX0=1; //External interrupt INT0, to expand the waveform, you can press the key to adjust the waveform
   ET0=1; //External interrupt INT0, to expand the waveform, you can press the key to adjust the waveform
   IP=0X01; //Keyboard interrupt level high
   TR0=1;
   CS0=0;//dac0832 is in direct mode
   WR0=0;
   while(1)
    {
   
 }


}


Reference address:51proteus simulation: generating sine waves

Previous article:51proteus simulation: generate square wave, sine wave, sawtooth wave and triangle wave
Next article:51proteus simulation: generating sawtooth waves

Recommended ReadingLatest update time:2024-11-17 03:03

Industrial control system based on 51 single chip
0 Introduction In recent years, the field of automation control has been changing with each passing day, and control systems such as PLC, DCS, PAC, etc. have emerged in an endless stream. However, the application of such control systems requires relatively expensive costs. On the one hand, in order to facilitate
[Microcontroller]
Industrial control system based on 51 single chip
51 single chip microcomputer program - button control LED light
#include void Delay(unsigned int t);  sbit key=P3^2;           //Corresponding to the s19 button on the MCU development board   void main (void) { while (1)   //After the function starts, it keeps checking whether the button is pressed {     if(key==0)               { unsigned char i;   //define an
[Microcontroller]
Addressing mode of MCS-51 single-chip microcomputer instruction system
1. Register addressing  Register addressing mode can be used to access the 8 working registers R0~R7 in the selected register area. The register used is indicated by the lower 3 bits of the instruction opcode. Registers A, B, DPTR and C (accumulator of the bit processor) can also be used as addressing objects. 2. Dir
[Microcontroller]
51 MCU [IV] Buzzer crystal oscillator MCU frequency
I suddenly remembered the sound of the computer self-test when I was a child. Of course, we also have washing machines, air conditioners, etc. The principle of the buzzer is that two iron plates are used to make the positive and negative poles of one end of the plate change continuously, so that the other end can
[Microcontroller]
51 MCU [IV] Buzzer crystal oscillator MCU frequency
Design of ultrasonic distance measurement system based on AT89C2051 single chip microcomputer and temperature compensation
0 Introduction Ultrasonic waves are mechanical vibrations in elastic media. They are caused by a vibration source in contact with the medium, and their frequency is above 20kHz. Since the speed of ultrasonic waves is much smaller than the speed of light, their propagation time is easier to detect, and they are easy to
[Microcontroller]
Design of ultrasonic distance measurement system based on AT89C2051 single chip microcomputer and temperature compensation
[C51 code] LCD12864 header file [upper and lower screen]
Model: LCD12864a3 Driver: ST7920A Chinese character display coordinate diagram: Graphical display coordinate graph: /*==================== lcd12864.h =====================*/ #ifndef _LCD12864_h_ #define _LCD12864_h_ #include Atmel/AT89X51.h #include "delay.h" #include "link.h" /*==================
[Microcontroller]
[C51 code] LCD12864 header file [upper and lower screen]
Static digital tube of 51 single chip microcomputer
1.138 decoder 1.74HC138 is a high-speed CMOS device. The 74HC138 pin is compatible with the low-power Schottky TTL (LSTTL) series. The 74HC138 decoder accepts 3-bit binary weighted address inputs (A0, A1, and A2) and provides 8 mutually exclusive low-valid outputs (Y0 to Y7) when enabled. 2. Using 138 decoder, thr
[Microcontroller]
Static digital tube of 51 single chip microcomputer
What are the differences in internal structure between RUPI-44 series MCU and 051 MCU?
The CPU in the RUPI-44 series of microcontrollers is basically the same as the 8051. Its instruction system, port operations, on-chip EPROM programming, and operation are all the same as the 8051. The main differences between them are: 1. The RUPI-44 series microcontrollers use SIU to replace the serial port of 80
[Microcontroller]
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号