我也买了马老师的书,第一眼,就觉得A口输出的数据根据行列来变换不怎么好弄,先用二维数组来实现。
*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
?Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version : 1.0
Date : 2013-7-15
Author : JianZhou
Company : LieMing
Comments:
Chip type : ATmega16
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
flash unsigned char led_7[28][8]={{0x80,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x40,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x20,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x10,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x08,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x04,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x02,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x01,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x00,0x01,0x00,0x18,0x18,0x00,0x00,0x00},
{0x00,0x00,0x01,0x18,0x18,0x00,0x00,0x00},
{0x00,0x00,0x00,0x19,0x18,0x00,0x00,0x00},
{0x00,0x00,0x00,0x18,0x19,0x00,0x00,0x00},
{0x00,0x00,0x00,0x18,0x18,0x01,0x00,0x00},
{0x00,0x00,0x00,0x18,0x18,0x00,0x01,0x00},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x01},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x02},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x04},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x08},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x10},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x20},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x40},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x80},
{0x00,0x00,0x00,0x18,0x18,0x00,0x80,0x00},
{0x00,0x00,0x00,0x18,0x18,0x80,0x00,0x00},
{0x00,0x00,0x00,0x18,0x98,0x00,0x00,0x00},
{0x00,0x00,0x00,0x98,0x18,0x00,0x00,0x00},
{0x00,0x00,0x80,0x18,0x18,0x00,0x00,0x00},
{0x00,0x80,0x00,0x18,0x18,0x00,0x00,0x00}};
flash unsigned char position[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char col=0;
unsigned char row=0;
unsigned char time_counter=0;
bit time_200ms_ok=0;
void display(void)
{
PORTC=0xff;
PORTA=led_7[col][row];
PORTC=position[row];
if (++row>=8) row=0;
};
// Timer 0 output compare interrupt service routine
interrupt [TIM0_COMP] void timer0_comp_isr(void)
{
display();
if (++time_counter>=100)
{
time_counter=0;
time_200ms_ok=1;
}
}
void main(void)
{
// Input/Output Ports initialization
// Port A initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTA=0x00;
DDRA=0xFF;
// Port C initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=1 State6=1 State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
PORTC=0xFF;
DDRC=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 62.500 kHz
// Mode: CTC top=OCR0
// OC0 output: Disconnected
TCCR0=0x0B;
TCNT0=0x00;
OCR0=0x7c; //OCR0=0x7C (124+1)/62.5k=2ms
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x02;
// Global enable interrupts
#asm("sei")
while (1)
{
if (time_200ms_ok)
{
if (++col>=28) col=0;
time_200ms_ok=0;
}
};
}
|