用一个按键接到INT0,按一下记一个数,并且显示。按另一个清零。
仿真截图:
ATMEL Studio6.2编译通过截图:
程序:
/*
* GccApplication19.c
*
* Created: 2014-10-15 20:16:25
* Author: Administrator
*/
#define F_CPU 0x8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#define KEY_CLEAR_ON() ((PIND & _BV(PD6))==0x00)
const uint8_t DSY_CODE[] = {0x3f,0x06,0x58,0x4f,0x66,0x60,0x70,0x07,0x7F,0x6F,0x00};
uint8_t Count = 0;
uint8_t Display_Buffer[3] = {0,0,0};
void Show_Count_ON_DSY()
{
Display_Buffer[2] = Count/100;
Display_Buffer[1] = Count % 100 / 10;
Display_Buffer[0] = Count % 10;
if(Display_Buffer[2] == 0)
{
Display_Buffer[2] = 10;
if(Display_Buffer[1] == 0) Display_Buffer[1] = 10;
}
PORTA = DSY_CODE[Display_Buffer[2]];
PORTB = DSY_CODE[Display_Buffer[1]];
PORTC = DSY_CODE[Display_Buffer[0]];
}
int main(void)
{
DDRA = 0xFF;PORTA = 0xFF;
DDRB = 0xFF;PORTB = 0xFF;
DDRC = 0xFF;PORTC = 0xFF;
DDRD = 0x00;PORTD = 0xFF;
MCUCR = 0x02;GICR = 0x40;
SREG = 0x80;
while(1)
{
if (KEY_CLEAR_ON())Count = 0;
Show_Count_ON_DSY();
}
}
ISR(INT0_vect)
{
Count++;
}
|