#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
#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);
}
}
Previous article:AVR independent button C program
Next article:AVR microcontroller matrix keyboard program (2 methods)
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
Guess you like
- [NXP Rapid IoT Review] + Rapid IoT Studio WEB/GUI programming tool learning and use
- Today at 10:30 AM Live: Start your journey from embedded to cloud with dedicated IoT hardware and software solutions
- I saved 4,000 yuan in one day off!
- RL78 RAM question
- [NXP Rapid IoT Review] + Unable to add devices again (Summary of the third week review)
- About atmel studio 7 to generate .lib library files
- Basic knowledge of power supply that you must know
- AD PCB cannot be saved, showing file save failed
- In the EMC-related experiments of circuits, there are some voltage pulse experiments. How should the withstand voltage value of the capacitor be considered?
- Start with LoRa and learn more about the Internet of Things