AVR MCU timer count

Publisher:cloudsousou6Latest update time:2015-07-20 Source: 51heiKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar num1;
#pragma interrupt_handler miao:9//Its corresponding position
#pragma data:code//Define the program to be stored in ROM
const uchar table[]={
0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,
0x8e
};
/***************************************************/
/*******************Delay subroutine******************/
/***************************************************/
void delay(uchar z)
{
   uchar x,y;
  for(x=0;x<255;x++)
  for(y=0;y }
/***************************************************/
/***********************Display subroutine******************/
/***************************************************/
void xian(uchar num)
{
  PORTA=table[num/10];//Tens digit
  PORTC&=~BIT(1);
  delay(2);
  PORTC|=BIT(1);
  PORTA=table[num%10];//Ones digit
  PORTC&=~BIT(0);
  delay(2);
  PORTC|=BIT(0);
}
/***************************************************/
/*********************Interrupt service subroutine***************/
/***************************************************/
void miao()
{
    if(num1==60)
 num1=0;
 num1++;//Increase the variable by 1
 TCNT1H=0XA4;//Assign high bit
 TCNT1L=0X71;//Assign low bit
}
/***************************************************/
/***********************Main program************************/
/***********************************************/
void main()
{
    DDRA=0XFF;//Set PA port as output mode
 DDRC|=BIT(0)|BIT(1);//Set two bits as output mode
 TCCR1B=0XA4;//Set 256-division 6M crystal=6000000/256-division-65535 into hexadecimal
 TCNT1H=0X71;//Assign high bit
 TCNT1L=0XED;//Assign low bit
 TIMSK|=BIT(2);//Turn on timer interrupt
 SREG|=BIT(7);//Turn on total interrupt
 while(1)
 {
   xian(num1); 
 }
}
Keywords:AVR Reference address:AVR MCU timer count

Previous article:AVR independent button C program
Next article:AVR microcontroller matrix keyboard program (2 methods)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号