The application of the timer, query method. Let 8 LED lights, left and right each of the 4 to light back and forth
Code:
/********************** Query method is the main program continuous query is interrupted, and do not need to prepare the sub-program ***********************/#include<reg51.h>#defineLED P1#defineCOUNT 50000//50000 * 1us = 0.05s 50000 counts several times#defineTH_M1 (65536-count)%256//MODE 1 is assigned to a high of 4 bits#deefine tl_m2 (65536-count)/ the //MODE 1 quotient value to lower 4 bitsMain () {inti; Tmod=0x01;//Mode 1 start T0 interruptLed=0xf0;//1111,0000 4 Lights on the right side of the common anode while(1) { for(i=0;i<5; i++)//5 times Interrupt Timer{TH0= TH_M1;//re-assigning initial value after overflowTL0 =th_m1; TR0=1;//Start T0 while(tf0==0)//Time Flag Timing Flag tf==0 Description overflow, waiting for overflowTF0 =0;//clear TF0, close T0} LED=~led;//LED Reverse Phase }}
Timer Application---Query mode---Let 8 LED lights, left and right each of 4