Timer 0 Mode 1 timer 1 Mode 1 digital tube and LED

Source: Internet
Author: User
Tags xms
# Include <reg52.h>
# Define uchar unsigned char
# Define uint unsigned int
Sbit Dula = P2 ^ 6;
Sbit wela = P2 ^ 7;
Sbit led1 = p1 ^ 0;
Uchar code table [] =
{
0x3f, 0x06, 0x5b, 0x4f, 0x66,
0x6d, 0x7d, 0x07, 0x7f, 0x6f,
0x77, 0x7c, 0x39, 0x5e, 0x79,0x71
};
Void delayms (uint );
Void display (uchar, uchar );
Uchar num, num1, num2, Shi, GE;
Void main ()
{
Tmod = 0x01; // set the timer 0 and 1 as the working mode 1 (00010001)
Th0 = (65536-45872)/256; // Initial Value
Tl0 = (65536-45872) % 256;
Th1 = (65536-45872)/256; // Initial Value
TL1 = (65536-45872) % 256;
Ea = 1;
Et0 = 1;
ET1 = 1;
Tr0 = 1;
Tr1 = 1;
While (1)
{
Display (Shi, Ge );
}
}


Void display (uchar Shi, uchar Ge)
{
Dula = 1;
P0 = table [Shi];
Dula = 0;
Wela = 1;
P0 = 0xfe;
Wela = 0;
Delayms (5 );

Dula = 1;
P0 = table [Ge];
Dula = 0;
Wela = 1;
P0 = 0xfd;
Wela = 0;
Delayms (5 );

}


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


Void t0_time () interrupt 1
{
Th0 = (65536-45872)/256; // reinstall the Initial Value
Tl0 = (65536-45872) % 256;
Num1 ++;
If (num1 = 4) // if it reaches 4 times, the time of MS is reached.
{
Num1 = 0; // then, num1 clears 0 and counts four times again.
Led1 = ~ Led1; // reverse the led state
}
}


Void t1_time () interrupt 3
{
Th1 = (65536-45872)/256; // reinstall the Initial Value
TL1 = (65536-45872) % 256;
Num2 ++;
If (num2 = 200) // if it reaches 20 times, the time from 1 second
{
Num2 = 0; // clear 0, then time
Num ++;
If (num = 60) // 0 to 60
Num = 0;
Shi = num/10;
GE = num % 10;
}
}

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.