Dac0832, led, Buzzer

Source: Internet
Author: User

52 control the output current of the dac0832 chip, so that the light-emitting diode D12 is reduced evenly from the off to the brightest, and then from the brightest to the brightest, the buzzer generates an alarm, the time for completing the entire cycle is controlled at around 5s.



# Include <reg52.h>
# Define uchar unsigned char
# Define uint unsigned int
Sbit Dula = P2 ^ 6;
Sbit wela = P2 ^ 7;
Sbit dawr = P3 ^ 6;
Sbit DACS = P3 ^ 2;
Sbit beep = P2 ^ 3;


Void delayms (uint XMS)
{
Uint I, J;
For (I = XMS; I> 0; I --)
For (j = 110; j> 0; j --);
}


Void main ()
{
Uchar Val, flag;
Dula = 0;
Wela = 0;
DACS = 0;
Dawr = 0;
P0 = 0;
While (1)
{
If (flag = 0)
{
Val + = 5;
P0 = val;
If (val = 255)
{
Flag = 1;
Beep = 0;
Delayms (100 );
Beep = 1;
}
Delayms (50 );
}
Else
{
Val-= 5;
P0 = val;
If (val = 0)
{
Flag = 0;
Beep = 0;
Delayms (100 );
Beep = 1;
}
Delayms (50 );
}
}

}


Enable the selection of D/A slices and then enable the write end. The latency is 50 ms, 50*51 = 2551 ms, ignoring the 100 ms occupied by the buzzer, which is about 2.5 s. The other half cycle is also 2.5 s, totaling 5 s.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.