speedtest4.c

来自「直流电机调速 利用c语言进行调pwm」· C语言 代码 · 共 92 行

C
92
字号
#include<reg51.h>
#include<absacc.h>
#include <intrins.h>

#define uchar unsigned char
#define uint  unsigned int

sbit P2_0=P2^0;
sbit P2_1=P2^1;

uchar flag;
//uint store;
uchar n;
uchar time_sgn;
uchar timer0_high,timer0_low;
uchar frag=0;
uchar freq1;
//uchar tempa,tempb;

///
void delay(uint j) /* 简易延时函数 */ 
{ 
  for(j;j>0;j--); 
} 

///
main()
{
   //uint t_a,t_b;
   P2_0=0;
   P2_1=1;
   //tempa=-10000/256;
   //tempb=-10000%256;
   //t_a=-1000/256;
   //t_b=-1000%256;
   
   EA=1;
   IT0=1;
   EX0=1;
   ET0=1;
   //ET1=1;
   //PT1=1;
   //TH1=-1000/256;
   //TL1=-1000%256;
   TMOD=0x09;
   TR0=1;

   while(1)
   {
    if(n==4)   
     {    
          TR0=0;
          P2_0=1;
          delay(1000);
          time_sgn=0;
          TR0=1;
    }
   }      
}
//
void int0(void) interrupt 0 using 1
{
  uint temp,i;
  if(flag==1)
   { 
	  flag=0;
      timer0_high=TH0;
      timer0_low=TL0;
      temp=256*timer0_high+timer0_low;
      for(i=0;i<4;i++)
      { time_sgn=time_sgn+temp;}
 
      TH0=0;
      TL0=0;
   }
  if(flag==0)
   {
      flag=1;
      TH0=0;
      TL0=0;
      TR0=1;
    }
}
//
void timer0(void) interrupt 1 using 1
{
   TH0=0;
   TL0=0;
   n=n+1;
} 
//

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?