//The PIC16F877 microcontroller outputs a sine wave signal simulation schematic diagram as follows
//20MHz crystal oscillator, outputs 500Hz sine wave, 100 points per cycle.
//1 cycle time is 2ms, the interval between two points is 2000/100=20us
//Use TMR2 to delay, 256*Tcy*K=20, Tcy=0.2, take K=1
//PR2 calculation: (PR2+1)*Tcy*1=20, PR2=99
#include __CONFIG(0x3F3A); #define CS RB1 #define LDAC RB2 char BUF,N; #define nn 100 const unsigned int SS[100]={ 2048,2111,2173,2235,2297,2357,2416,2474,2530,2584,2636,2685,2733,2777,2819,2857, 2892,2924,2953,2978,2999,3017,3030,3040,3046,3048,3046,3040,3030,3017,2999,2978, 2953,2924,2892,2857,2819,2777,2733,2685,2636,2584,2530,2474,2416,2357,2297,2235, 2173,2111,2048,1985,1923,1861,1799,1739,1680,1622,1566,1512,1460,1411,1363,1319, 1277,1239,1204,1172,1143,1118,1097,1079,1066,1056,1050,1048,1050,1056,1066,1079, 1097,1118,1143,1172,1204,1239,1277,1319,1363,1411,1460,1512,1566,1622,1680,1739, 1799,1861,1923,1985}; //Macro definition, the final read of SSPBUF is a must! #define SPI_WRITE(A) SSPBUF=A; while(STAT_BF==0); BUF=SSPBUF void main(void) { unsigned int x; TRISB=0b11111001; CS=1;NOP(); LDAC=1; TRISC=0b00010000; //RC3 output (SCK), RC4 input (SDI), RC5 output (SDO) SSPEN=1; //SPI serial port enable CKP=1; //Idle clock is high level SSPM3=0; SSPM2=0; SSPM1=0; SSPM0=0; //SPI master mode, clock is Fosc/4 STAT_SMP = 1; // Sample input data at the end of the data output time STAT_CKE=0; //Transmit data on the rising edge of SCK PR2=99; //According to calculation, interrupt once every 20us T2CON=0b00000100; N=0; TMR2IE=1; //Enable TMR2 interrupt LIKE=1; GIE=1; while(1); } void interrupt INT_ISR(void) { unsigned int X; char i,j; if (TMR2IF==1) { TMR2IF=0; X=SS[N++]; if (N>=nn) N=0; X+=0x7000; //HSDN=1, reference voltage buffer, amplification factor GA=1 CS=0; //Chip select is valid i=X>>8; j=X; SPI_WRITE(i); //output the high 8 bits of the command SPI_WRITE(j); //output the lower 8 bits of the command LDAC=0;NOP(); //DA output is valid LDAC=1;NOP(); CS=1; } }
Previous article:PIC16F684 MCU Timer Interrupt Marquee
Next article:PIC microcontroller electronic clock program + simulation circuit
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- AD17 There is a problem with copper laying on a four-layer board
- Static Timing Analysis Basics and Applications
- How to use Segger Embedded Studio to develop the HPM6750?
- 485 Point-to-Many Communication Problem
- The program of the microcontroller is lost, what's going on?
- EEWORLD University Hall----Audio Amplifier for Smart Speaker
- Qorvo Expands 1.8 GHz DOCSIS 4.0 Portfolio
- Gain Circuit Compensation
- [Hua Diao Experience] 01 Getting Started with Xingkong Board
- Discharge needle under the common mode inductor