Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<reg51.h>
- #include<stdio.h>
- sfr DPTR = 0x82;
- long int time_total, freq;
- unsigned char flag=0;
- intr() interrupt 0{
- if(TR0){
- TR0 = 0;
- flag = 1;
- }
- else{
- TR0 = 1;
- }
- }
- init_timer(){
- TMOD |= 0x01;
- TCON |= 0x01;
- }
- void prnt(char ch){
- TI = 0;
- SBUF = ch;
- while(!TI);
- }
- main(){
- unsigned int divisor=10000, temp;
- IE |= 0x81;
- SCON |= 0x50;
- TMOD |= 0x20;
- TH1 = 0xfd;
- TL1 = 0xfd;
- TR1 = 1;
- while(1){
- init_timer();
- if(flag){
- DPH = TH0;
- DPL = TL0;
- time_total = DPTR;
- freq = 1000000/time_total;
- while(freq){
- temp = freq/divisor;
- temp += 0x30;
- freq%=divisor;
- divisor/=10;
- prnt(temp);
- }
- TH0 = 0x00;
- TL0 = 0x00;
- flag = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement