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

📄 counter.c

📁 82C54 counter programming
💻 C
字号:
/*-----------------------------------------------------------------------------------------
COUNTER.C
Source file to Counter operation
Project: RADIATION COUNTING SYSTEM
ELECTRONICS CORPORATION OF INDIA LIMITED, HYDERABAD
Developed By VINAY                			All rights reserved.
-------------------------------------------------------------------------------------------*/
#include "counter.h"
#include "AT89x51.h"
#include "lcd.h"
#include "intrins.h"
#include "keypad.h"
unsigned char lcdcount[9]={0,0,0,0,0,0,0,0,'\0'};
extern unsigned long countervalue;

extern count1 xdata count;
extern count2 xdata count3;

unsigned char   count5[3];  

unsigned long int a=0;
int xdata m;

void Counter_Init(void)  //Counter Initialization Function
{
read =1;

A0=1;                 //COUNTER ZERO INITIALIZATION  AS RATE GENERATOR
A1=1;
Counter1_Enable=0;
P2 =0x34;
write=0;
Counter1_Enable=1;
write=1;

/*A0=1;
A1=1;
Counter1_Enable=0;
P2 =0x70;              //COUNTR ONE INITIALIZATION interrupt on terminal Mode
write=0;
Counter1_Enable=1;
write=1;         */

A0=1;
A1=1;
Counter1_Enable=0;
P2 =0x74;              //COUNTR ONE INITIALIZATION AS RATE GENERATOR
write=0;
Counter1_Enable=1;
write=1;

A0=1;
A1=1;                 //COUNTER TWO INITIALIZATION AS INTERRUPT ON TERMINAL MODE
Counter1_Enable=0;
P2=0xB0;
Counter1_Enable=0;
write=0;
Counter1_Enable=1;
write=1;

}

  void Counter1_Load(unsigned char lsb,unsigned char msb)           //for counter 1
  {

                        A0=1;
                        A1=0;
                        Counter1_Enable=0;
                        write=0;
                        P2= lsb;
                        write=1;
                        Counter1_Enable=1;

                        A0=1;
                        A1=0;
                        Counter1_Enable=0;
                        write=0;
                        P2= msb;
                        write=1;
                        Counter1_Enable=1;
   
  }


      void Counter2_Load(unsigned char lsb,unsigned char msb)          //for counter 1
  {
                  Counter1_Enable=0;
                        A0=0;
                        A1=1;
                        write=0;
                        P2= lsb;
                        write=1;
                        Counter1_Enable=1;

                   Counter1_Enable=0;
                        A0=0;
                        A1=1;
                        write=0;
                        P2= msb;
                        write=1;
                        Counter1_Enable=1;


  }

  void Counter3_Load(unsigned char lsb,unsigned char msb)           //for counter 0
  {

                        A0=0;
                        A1=0;
                     Counter1_Enable=0;
                        write=0;
                        P2= lsb;
                        write=1;
                        Counter1_Enable=1;

                        A0=0;
                        A1=0;
                     Counter1_Enable=0;
                        write=0;
                        P2= msb;
                        write=1;
                        Counter1_Enable=1;
      }



  void counter_Read(void)
  {

                count5[0]=0;
                count5[1]=0;
                count5[2]=0;
                count5[3]=0;
                Counter1_Enable=0;

                A0=1;                           //counter1 selection
                A1=0;
                read=0;
                delay(500);
                count5[0]= P2;          // Reading LSB of Counter1
                Counter1_Enable=1;
                read=1;

                Counter1_Enable=0;
                A0=1;
                A1=0;                             //Reading MSB of Counter1
                read=0;
                count5[1]= P2;
                Counter1_Enable=1;
                read=1;


  Counter1_Enable=0;
  A0=0;
  A1=1;
  read=0;
  delay(500);
  count5[2]= P2;                 // Reading LSB of Counter1
  Counter1_Enable=1;
  read=1;

Counter1_Enable=0;
  A0=0;
  A1=1;
  read=0;
  delay(500);
  count5[3]= P2;                 // Reading MSB of Counter1
  Counter1_Enable=1;
  read=1;

   }
                                                                                                   //to display the count value
  void countdisply(void)                 //To Display The counts in COUNTER Mode
  {
				
				a=((count5[1]*256)+count5[0]);
			    if(countervalue<=65536)
               
				a = (2*(count3.counts-a));
             else if(countervalue>65536)
              
				 a = (16*(count3.counts-a));

                for (m=5;m>=0;m--)
                {
                lcdcount[m] = (a%10)+0x30;
                if (lcdcount[m]<0)
                lcdcount[m]=0+30;
                a=a/10;
                  }
                if(lcdcount==countervalue)
				LcdWriteString("000000");
				else
				LcdWriteString(lcdcount);
	     }

  void countdisplyend(void)              // To display the counts in TIMER mode
  {
		     a=((count5[1]*256)+count5[0]);
               	
				a=(10*(65536-a));
                for (m=5;m>=0;m--)
                {
                lcdcount[m] = (a%10)+0x30;
                if (lcdcount[m]<0)
                lcdcount[m]=0+30;
                a=a/10;
                  }
                LcdWriteString(lcdcount);
    }



void PulseGenerator(void)
{
Counter3_Load(0x0C,0x00);
CounterStartPulse=1; //counter start
}

void Counter_ReadOnFlyCounter(void)
{
        read =1;
        count5[0]=0;
        count5[1]=0;
	
		A0=1;
        A1=1;
        Counter1_Enable=0;
        write=0;
        P2=0x80;                         // Read and Fly Command for counter2
        write=1;
		Counter1_Enable=1;

         P2=0x0FF;
         A0=0;           				  // Counter2 Selection
         A1=1;

                Counter1_Enable=0;                // Reading LSB of Counter1
                read=0;
                count5[0]= P2;
               	read=1;
				Counter1_Enable=1;

                Counter1_Enable=0;                // Reading MSB of Counter1
                read=0;
                count5[1]= P2;
                read=1;
				Counter1_Enable=1;

  }

  






⌨️ 快捷键说明

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