1. The P2 port of a certain single-chip computer system is connected to a digital-to-analog converter DAC0832 to output analog quantity. Now it is required to output a continuous triangular wave from the DAC0832. The implementation method is to continuously output the value that changes according to the triangular wave from the P2 port, starting from 0 and gradually increasing, and then gradually decreasing after reaching a certain maximum value until 0, and then gradually increasing from 0, and continue to output in this way. Try to write a function to make the value output from the P2 port generate a triangular wave, and make the period and maximum value of the triangular wave changeable through the input parameters.
#include
#define DAC0832 XBYTE[0x7FFF]
void san(unsigned char max1,unsigned char zhou1)
{
unsigned char i,j,max,zhou;
max=max1;
zhou=zhou1;
while(1)
{
for(i=0;i<=max,i++)
{
DAC0832=i;
for(j=0;j
}
for(i=max-1;i>0,i--)
{
DAC0832=i;
for(j=0;j
}
}
2. In digital filtering, there is a technology called "median filtering", which is to sort the collected data from large to small or from small to large, and then take the number in the middle as the sampling value. Try to write a function to sort the sampled data of 20 cells starting from 0x50 in the on-chip data memory using the bubble method and perform median filtering, and store the obtained sampled data in cell 0x4f.
void midf()
{
unsigned char data temp,i,j,*ptr,*ptr1;
ptr=0x50;
ptr1=0x4f;
for(j=20;j>1,j--)
{
for(i=0;i
if(*(ptr+i)>*(ptr+i+1))
{
temp=*(ptr+i+1);
*(ptr+i+1)=*(ptr+i);
*(ptr+i)=temp;
}
}
}
*ptr1=*(ptr+20/2);
}
3. In digital filtering, there is a technique called "extreme value average filtering", which is to sort the collected data from large to small or from small to large, then remove the same number of maximum and minimum values, and calculate the arithmetic mean of the middle part of the data as the sampling value. Try to write a function to perform "extreme value average filtering" on the sampling data of 16 units starting from 0x150 stored in the off-chip data memory using the selection method, and store the obtained sampling data in the 0x14f unit.
void teaf()
{
unsigned char xdata *ptr;
unsigned char data temp,i,j,*ptr1;
ptr=0x150;
ptr1=0x4f;
for(j=16;j>1,j--)
{
for(i=0;i
if(*(ptr+i)>*(ptr+i+1))
{
temp=*(ptr+i+1);
*(ptr+i +1)=*(ptr+i);
*(ptr+i)=temp;
}
}
}
temp=0;
for(i=0;i<16-2;i++)
temp=temp+*(ptr+i+1);
*ptr1=temp/(16-2);
}[page]
4. Use the library function _getkey to write a function to implement a C51 program that receives data from the serial port of the microcontroller. The received data is stored in the area starting from 0x40 in the on-chip data memory and ends when a carriage return character CR (ASCII code is 0x0d) is encountered.
include
void main()
{
unsigned char data *dpt;
unsigned char i=0,temp;
dpt=0x40;
while(1)
{
temp=_getchar();
if(temp==0x0d)
break;
*(dpt+i)=temp;
i++;
}
}
5. Use the library function scanf to write a function to implement a C51 program that receives data from the serial port of the microcontroller. The received data is stored in the area starting from 0x240 in the off-chip data memory and ends when a carriage return character CR (ASCII code is 0x0d) is encountered.
include
void main()
{
unsigned char xdata *xdpt;
unsigned char i=0,temp;
xdpt=0x240;
while(1)
{
scanf(“%c”,&temp);
if(temp==0x0d)
break;
*(xdpt+i)=temp;
i++;
}
}
6. Use the library function putchar to write a function to implement a C51 program that sends data from the serial port of the single-chip microcomputer. The data to be sent is stored in the area starting from 0x50 in the on-chip data memory and ends when a carriage return character CR (ASCII code is 0x0d) is encountered.
include
void main()
{
unsigned char data *dpt;
unsigned char i=0;
dpt=0x50;
while(*(dpt+i)!=0x0d)
{
putchar(*(dpt+i));
i++;
}
}
7. Use the library function printf to write a function to implement a C51 program that sends data from the serial port of the single-chip microcomputer. The data to be sent is stored in the area starting from 0x100 in the off-chip data memory and ends when a carriage return character CR (ASCII code is 0x0d) is encountered.
include
void main()
{
unsigned char xdata *xdpt;
unsigned char i=0;
xdpt=0x100;
while(*(xdpt+i)!=0x0d)
{
printf(“%c”,*(xdpt+i));
i++;
}
}
8. Write a timer/counter 0 timing 100ms interrupt processing function to make the function realize the clock function, that is, generate the seconds, minutes and hours of the clock. The high and low bytes of the initial value are set to TIMER_H and TIMER_L respectively.
Assume fosc=6mhz
#include
sfr TIMER_H=0x8b;
sfr TIMER_L=0x8a;
unsigned char data shi,fen,miao,bfm;
void main()
{
TMOD=0x01;
TIMER_H=15536/16;
TIMER_L=15536%16;
ET0=1;
EA=1;
TR0=1;
while( 1);
}
void time0_int() interrupt 1
{
TIMER_H=15536/16;
TIMER_L=15536%16;
bfm++;
if(bfm==10)
{
bfm=0;
miao++;
}
if(miao==60)
{
miao=0;
fen++;
}
if(fen==60)
{
fen=0;
shi++;
}
if(shi==24)
{
shi=0;
}
}
Previous article:Microcontroller delay program experience
Next article:The structure and working principle of single chip microcomputer timer/counter
Recommended ReadingLatest update time:2024-11-16 16:53
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- Share an example of MSP430G2 series driving DS18B20
-
[NXP Rapid IoT Review] +
NXP Rapid IoT Unboxing Surprises - Chint ZTW0111A Digital Multimeter Disassembly and Evaluation
- 【TouchGFX Design】First experience based on F746DISCOVRY
- CircuitPython 4.0.0 is now available
- Embedded Software Engineer
- Win Jingdong Cards to fight against indoor air hazards - Infineon XENSIV PAS CO2 sensor
- MicroPython adds UF2 firmware format for esp32-S2/S3 chips
- Verilog data splicing and splitting.zip
- EEWORLD University ---- Data Structure and Algorithm