#include"reg51.h"
#define uchar unsigned char
sbit ksaw=P2^0; //Sawtooth wave button.
sbit ktran=P2^1; //Triangle wave button.
sbit ksquare=P2^2; //Square wave button.
sbit ksin=P2^3; //Sine wave button.
uchar key1;
uchar keya;
uchar keyb;
uchar keyc;
uchar keyd;void delay( );
uchar code tab[128]={
64,67,70,73,76,79,82,85,88,91,94, 96,99,102,104,106,
109,111,113,115,117,118,120,121,123,124,125,126,126,
127,127,127,127,127,127,127,126,126,125,124,123,12 1,
120,118,117,115,113,111,109,106,104,102,99,96,94,91,
88,85,82,79,76,73,70,67,64,60,57,54,51,48,45,42,39,
36,33,31, 28,25,23,21,18,16,14,12,10,9,7,6,4,3,2,1,
1,0,0,0,0,0,0,0,1, 1,2,3,4,6,7,9,10,12,14,16,18,21,23,
25,28,31,33,36,39,42,45,48,51,54,57,60};
void delay( )
{
uchar i;
for(i=0;i<255;i++);
}
void saw(void) //sawtooth wave.
{
uchar i;
while(1)
{
if(keya==1)
{
for (i=0;i<255;i++)
P0=i;
}
else break;
}
}
void tran(void) //Triangular wave
{
uchar i;
while(1)
{
if(keyb==1)
{
for(i= 0;i<255;i++)
P0=i;
for(i=255;i>0;i--)
P0=i;
}
else break;
}
}
void square(void) //square wave
{
while(1)
{
if(keyc==1)
{
P0=0x00;
delay();
P0=0xff;
delay();
}
else break;
}
}
void sin( ) //sine wave
{
unsigned int i=0;
while(1)
{
if(keyd==1)
{
if(++i==128)i=0;
{P0=tab[i];}
}
else break;
}
}
void main(void) //main function
{
EA=1;
EX0=1;
while(1)
{
if(key1)
{
switch(key1)
{
case 0x01:
//P0=0XC0;//
saw();
break;
case 0x02:
//P0=0XC0;//
tran();
break;
case 0x03:
//P0=0XBE;//
square();
break;
case 0x04:
//P0=0XB6;/ /
sin();
break;
}
}
}
}
void int0(void)interrupt 0 using 1
{
if(ksaw==0)
{key1=0x01;keya=1;keyb=0;keyc=0;keyd=0;}
if(ktran==0)
{key1=0x02 ;keya=0;keyb=1;keyc=0;keyd=0;}
if(ksquare==0)
{ key1=0x03;keya=0;keyb=0;keyc=1;keyd=0;}
if(ksin ==0)
{key1=0x04;keya=0;keyb=0;keyc=0;keyd=1;}
}
The pictures are as follows:
Previous article:Design of car anti-theft alarm system based on GSM network
Next article:GPRS module sends information code
Recommended ReadingLatest update time:2024-11-16 12:44
- Popular Resources
- Popular amplifiers
- 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)
- ATmega16 MCU C language programming classic example (Chen Zhongping)
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
- BSL source code for DM642EVM
- Teachers, what kind of amplifier should be used to amplify the mv level of this sensor?
- if(Data==1)start=1; Why is there no space after if and before start in this sentence? This will not cause errors during compilation.
- Xiaomi Robot Vacuum Cleaner Features and Chip Parameters
- [Raspberry Pi 4B Review] Raspberry Pi 4 pin functions and operation methods
- Live: Embedded to Cloud Journey with PIC and AVR MCUs from the Microchip Ecosystem Part 2
- Purgatory Legend-RAM War
- [CY8CKIT-149 PSoC 4100S Review] + Familiar with the development environment
- How to write program control for AT28C64
- Motor control design, accuracy? resolution? arc minutes?