Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save urmil0071/126055b232456f2b0b05605c67a3ec7b to your computer and use it in GitHub Desktop.
Save urmil0071/126055b232456f2b0b05605c67a3ec7b to your computer and use it in GitHub Desktop.
Operate CLKTC0 Counter0 to count external rising edges from T1pin(DPIN 11)
#include <Arduino.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
void setup()
{
int secPassed=0;
pinMode(11,INPUT);
TCCR0B=0x00; /// TC0 Stop
TCNT0=0x00; ///TCNT0 preset=0
TCCR0A=0x00; ///TC0 As normal counter mode
TCCR0B=0x07; /// TC0 start with rising edge from dpin 11
bitSet(TIFR1,0); /// TOV0 Clear
TCCR1A=0x00; /// TC1 as Counter mode
TCCR1B=0x00; /// TC1 Stop
TCNT1=0xC2F7; ///Timer1 Preset
bitSet(TIFR1,2); /// TOV1 CLEAR
TCCR1B=0x05; /// Timer1 Start
while(secPassed<=10)
{
if (bitRead(TIFR1,2)==1)
{
TCCR1B=0x00;
TCNT1=0xC2F7;
bitSet(TIFR1,2); ///TOV1 Clear
secPassed=secPassed+1;
TCCR1B=0x05;
}
}
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(6,0);
lcd.print(TCNT0,10); /// Show Pulse Count on LCD
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment