ICCAVR_mega8_Proteus 跑马灯
[复制链接]
//ICC-AVR application builder : 2009-3-10 13:53:36
// Http://www.oa-only.com
// Target : M8
// Crystal: 8.0000Mhz
#include
#include
void port_init(void)
{
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
/************************************
Name :小延时程序
Target :atmega8
Crystal(晶振):8M
************************************/
void delay()
{
unsigned int i;//最大值65536
for (i=0;i<40000;i++)
{;}
}
/************************************
Name :跑马灯
Target :atmega8
Crystal(晶振):8M
**************************************/
void show_LED()
{
unsigned char i;
DDRB=0xff;//设为输出
for (i=0;i<8;i++)
{
PORTB=(1<
delay();
}
}
void main()
{
port_init();
init_devices();
while(1)
{
show_LED();
}
}
http://www.oa-only.com/upload/20100127142953236.rar