⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 puls_counter.c

📁 该程序是基于c8051f020的平台
💻 C
字号:
#include <c8051f020.h>
#define uchar unsigned char
#define uint unsigned int

#include <Lcd1602.h>
#include <DS18B20_Driver.h>

void Timer1_Init(void);
void Timer3_Init (int counts);
uchar Puls_Counter(void);
void Display_Pusle(uchar times);

extern void Temperature_Display(uint Temp);


sfr16 TMR3RL   = 0x92;                 // Timer3 reload value
sfr16 TMR3     = 0x94;                 // Timer3 counter

bit Time_f;
uint Sec;

uchar Puls_Counter(void)
{
   Lcd1602_Clear_Line(2);Lcd1602_Clear_Line(1);
   Lcd1602_Write_String(1,1,"Wait!");
   Time_f = 0 ; TL1 = 0x00; TH1 = 0x00;     // Initilize
   
   TMR3CN |= 0x04;  TR1 =1;  //  Open the timer3 and the counter1
   while(!Time_f)
     {  if(Sec%50==0){ 
          Lcd1602_Write_String(1,7,"Time:");
          Lcd1602_Write_char(Sec/500+'0');
          Lcd1602_Write_char((Sec/50)%10+'0');
          Temperature_Display(Get_Temp()); 
            }
        
        }    //  Wait for 1 sec
   TMR3CN &=~0x04;  TR1 =0;  //  Close the timer3 and the counter1

   return(TL1);
}



void Display_Pusle(uchar times)
{
   uchar a[3]; uchar i;

   a[0] = times/100;
   a[1] = (times-a[0]*100)/10;
   a[2] = (times-a[0]*100-a[1]*10);

  // Lcd1602_Clear_Line(1);
   Lcd1602_Write_String(2,1,"P:");
   for(i=0;i<3;i++){  Lcd1602_Write_char(a[i]+'0');   }
}


void Timer1_Init(void)
{
  TMOD |= 0x40;   //  13-bit  ,counter1 Mode
}

void Timer3_Init (int counts)   // counts = 36864  T = 0.02s
{
   //CKCON = 0x00;
   TMR3CN = 0x00;                      // Stop Timer3; Clear TF3;
                                       // use SYSCLK/12 as timebase
   TMR3RL  = -counts;                  // Init reload values
   TMR3    = 0xffff;                   // set to reload immediately
   EIE2   |= 0x01;                    // enable Timer3 interrupts

  // TMR3CN |= 0x04;                     // start Timer3

}


void  Timer3_ISR(void) interrupt 14   // counts = 36864  T = 0.02s
{
     static uint i = 0;
     TMR3CN &= ~0x80;      //TF3 = 0;
     if (i==3000){   i=0; Sec = 0;  Time_f = 1 ;   }
     i++;    Sec++; 
}

⌨️ 快捷键说明

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