本程序是利用T0来控制显示。效果不错的。
Proteus仿真截图:
Atmel Studio6.2编译通过截图:
程序:/*
* GccApplication23.c
*
* Created: 2014-10-21 21:47:38
* Author: Administrator
*/
#define F_CPU 4000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
const uint8_t SEG_CODE[] = { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
const uint8_t Table_OF_Digits[][8] = {
{0,9,10,1,2,10,2,5},{ 2,1,10,5,7,10,3,9 }
};
uint8_t i= 0,j=0;
uint16_t keep_Time = 0;
int main(void)
{
DDRC = 0xFF;PORTC = 0x00;
DDRD = 0xFF;PORTD = 0x00;
TCCR0 = 0x03;
TCNT0 = 0x03;
TCNT0 = 256-F_CPU/64.0 * 0.004;
TIMSK = 0x01;
sei();
while(1);
}
ISR(TIMER0_OVF_vect)
{
TCNT0 = 256 - F_CPU/64.0 * 0.004;
PORTC = 0xFF;
PORTC = SEG_CODE[Table_OF_Digits[i][j]];
PORTD = _BV(j);
j = (j+1) % 8;
if(++keep_Time != 350)return;
keep_Time = 0;
i= (i+ 1) % 2;
}
|