1. A microcontroller system P2 port connected to a digital-analog converter DAC0832 output analog, now requires continuous triangular wave output from the DAC0832, the method is to continuously output from the P2 port in accordance with the value of the triangular wave changes, gradually increased from 0 to a After a maximum value gradually decreases until 0, and then gradually increase from 0, so that output. Try to write a function that will produce a triangular wave from the value output from port P2, and the period and maximum value of the triangle wave can be changed by the entry parameter.
#include"absacc.h"
#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<<zhou/max;j++)
Delay();
}
For(i=max-1;i"0,i--)
{
DAC0832=i;
For(j=0;j<<zhou/max;j++)
Delay();
}
}
2. In digital filtering, there is a so-called "median filtering" technique in which the collected data is sorted from large to small or from small to large, and then the number in the middle is taken as the sampled value. Write a function to sort the sampled data of 20 units from 0x50, which is stored in the on-chip data memory, by median filtering with the bubble method, and store the sampled data in the 0x4f unit.
Void midf()
{
Unsigned char data temp,i,j,*ptr,*ptr1;
Ptr=0x50;
Ptr1=0x4f;
For(j=20;j"1,j--)
{
For(i=0;i'j;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 "de-extreme average filtering", which sorts the collected data from large to small or from small to large, and then removes the same number of local maximum and minimum values. Find the arithmetic average as the sample value. Try to write a function to store 16 data samples from 0x150 in the off-chip data memory. Use the selection method to perform “de-extreme average filtering†and store the sampled 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'j;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);
}
4. Write a function using the library function _getkey, realize the C51 program that receives data from the serial port of the one-chip computer, store the received data in the area that the on-chip data memory begins from 0x40, meet carriage return CR (ASCII code is 0x0d) Finish .
Include "stdio.h"
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. Write a function using the scanf function to realize the C51 program that receives data from the serial port of the microcontroller. Store the received data in the area starting from 0x240 for the off-chip data memory and end with carriage return CR (ASCII code 0x0d).
Include "stdio.h"
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 that implements the C51 program that sends data from the serial port of the microcontroller. The transmitted data is stored in the area where the on-chip data memory starts from 0x50, and the carriage return CR (ASCII code 0x0d) is encountered.
Include "stdio.h"
Void main()
{
Unsigned char data *dpt;
Unsigned char i=0;
Dpt=0x50;
While(*(dpt+i)!=0x0d)
{
Putchar(*(dpt+i));
i++;
}
}
7. Using the library function printf to write a function, to achieve the C51 program to send data from the microcontroller serial port, the data sent is stored in the area outside the off-chip data memory starting from 0x100, and the carriage return CR (ASCII code is 0x0d) is encountered.
Include "stdio.h"
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 handling function to enable the function to implement the function of the clock, ie 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.
Let fosc=6mhz
#include reg52.h
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;
}
}
With more than 15+ yrs rich MFG experience, you can definitely trust in and cooperate with.
Provide you with the supply of personal protective equipment. to help you safely get back to your daily routine.
Our products include pulse Oximeter Finger, Forehead Thermometer, Automatic foam soap dispenser, etc.
Our strict quality control protocol thoroughly vets every aspect of production, storage, and shipments all the way way to our end customers.
protective equipment, ppe personal protective equipment, definition of personal protective equipment
TOPNOTCH INTERNATIONAL GROUP LIMITED , https://www.itopnoobluetoothes.com