[
Experimental task
]
Use two buttons to control the output of DAC0832 through the microcontroller, so that the OUT terminal can output two waveforms, sawtooth wave and triangle wave, with an amplitude of 0-5V and a frequency of 1KHZ. After the power is turned on; press INT1 to output a triangle wave, and press INT0 to output a sawtooth wave.
[
Experimental principle
]
ADC0804 is an 8-bit full MOS medium-speed D/A converter, using R-2RT resistor decoding network, the conversion result is a pair of differential current output, the conversion time is about 1us. Use a single power supply +5V-+15V. The reference voltage is -10V-+10V. Here we directly choose +5V as the reference voltage. DAC0832 has three working modes: direct mode, single buffer mode, double buffer mode; here we choose the direct mode, connect all XFER WR 1WR2 CS pins to digital ground. Pin 8 is connected to the reference voltage, and the reference voltage we connect here is +5V. Then after the first stage op amp, the output voltage will be -5V-0V, and after the second stage op amp inverts and amplifies 1 times, it can output 0V-5V. When we control the regular changes of the output data of P1 port, we can generate waveforms such as triangle wave, sawtooth wave, ladder wave, etc.
[
C language source program
]
#include
unsigned char keycnt=0;
unsigned char tcnt=0; //Key value judgment
bit sjz=0; //Flag used when generating triangle wave
void delayl() //Delay subroutine
{ unsigned char i,j;
for(i=20;i>0;i--)
for(j=248;j>0;j--); }
void KEY() //Key scanning program
{
if(P3_2==0)
{
delayl(); //Delay skips the jitter when pressing
if(P3_2==0)
{
keycnt=0; //Timer generates sawtooth wave flag
TR0=0; //Temporarily stop waveform output
TH0=0x256-40; //Assign TH0 TL0 to
TL0 TL0=0x256-40;
TR0=1; //Start timing and generate sawtooth wave
while(P3_2==0); //If the key is pressed all the time, wait for the key to be released to open
delayl(); //Delay to skip the jitter after releasing
} }
if(P3_3==0)
{
delayl(); //Delay to skip the jitter when pressing
if(P3_3==0)
{
keycnt=1; //Timer generates triangle wave flag
TR0=0; //Temporarily stop waveform output
TH0=0x256-40; //Assign TH0 TL0 value
TL0=0x256-40;
TR0=1; //Start timing to generate triangle wave
}
while(P3_2==0); //If the key is pressed all the time, wait for the key to be released to open
delayl(); //Delay to skip the jitter after releasing
}
} //Please pay attention to the format specification when writing the program, this is to save paper
void t0(void) interrupt 1 using 0 //Timer interrupt service function
{
if(keycnt==0) //Generate sawtooth wave
{
P0=tcnt;
tcnt=+0x0a; //Step 0.2V/one interruptif
(tcnt==0xfb)
{tcnt=0;}
}
if(keycnt==1) //Generate triangle wave
{ if(sjz==0)
{P0=tcnt;
tcnt=+0x0a;//Step 0.2V/one interruptif
(tcnt==0xfa)
{sjz=1;}
}
if(sjz==1)
{
P0=tcnt;
tcnt=-0x0a;
if(tcnt==0)
{sjz=0;}
}
}
}
void main(void)
{
TMOD=0x02; //Timer works in mode 2
ET0=1;
EA=1;
while(1)
{ KEY(); }
}
[Hardware Circuit Diagram]
Previous article:I2C read and write operation experiment based on single chip microcomputer
Next article:Application experiment of analog-to-digital conversion DAC0832
- Popular Resources
- Popular amplifiers
- Virtualization Technology Practice Guide - High-efficiency and low-cost solutions for small and medium-sized enterprises (Wang Chunhai)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
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
- Matlab Machine Learning (English and Chinese subtitles)
- 【NXP Rapid IoT Review】+Preparation for Data Download
- EK140P UART5 Issue
- [RT-Thread reading notes] The simplest port to STM32F103CBT6
- Evaluation of domestic single-chip networking chips
- Square wave generator for msp430 microcontroller
- The problem of too small spacing between chip leads in AD
- EEWORLD University----Azure RTOS step by step workshop
- Working principle, functional characteristics and classification of photoelectric liquid level sensors
- EEWORLD University Hall--Detailed explanation of MATLAB image functions and their applications