Use the timer T0 to interrupt the control of 8-bit LED flashing

Source: Internet
Author: User

# Include <reg52.h> # define uchar unsigned char # define uint unsigned int uint I; void main () {I = 0; EA = 1; // enable the total interrupt TMOD = 0x01; // use the timer T0's working method 1 ET0 = 1; // The timer T0 interrupt allows TH0 = (65536-50000)/256; // assign TL0 = (65536-50000) % 256 to the high 8-bit timer T0; // assign TR0 = 1 to the low 8-bit timer T0; // start the timer T0 P0 = 0xff; while (1); // infinite loop wait interrupt} void Time0 (void) interrupt 1 // "interrupt" declares that the function is an interrupt service function, 1 indicates the interrupt Number of the timer T0 {I ++; if (I = 40) {P0 = ~ P0; I = 0;} TH0 = (65536-50000)/256; TL0 = (65536-50000) % 256 ;} # include <reg52.h> # define uchar unsigned char # define uint unsigned intuint I; void main () {I = 0; EA = 1; // enable the total interrupt TMOD = 0x01; // use the timer T0's working method 1ET0 = 1; // The timer T0 interrupt allows TH0 = (65536-50000)/256; // assign TL0 = (65536-50000) % 256 to the high 8-bit timer T0; // assign TR0 = 1 to the low 8-bit timer T0; // start the timer T0P0 = 0xff; while (1); // infinite loop wait interrupt} void Time0 (void) interrupt 1 // "interrupt" declares the function as an interrupt service function, 1 indicates the interrupt Number of the timer T0 {I ++; I F (I = 40) {P0 = ~ P0; I = 0;} TH0 = (65536-50000)/256; TL0 = (65536-50000) % 256 ;}

 


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.