main.c

来自「ATmega128单片机开发板原理图」· C语言 代码 · 共 76 行

C
76
字号
//ICC-AVR application builder : 2008-2-22 9:34:31
// Target : M128
// Crystal: 14.7456Mhz

#include <iom128v.h>
#include <macros.h>

void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0x00;
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x00; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
 PORTE = 0x00;
 DDRE  = 0x00;
 PORTF = 0x00;
 DDRF  = 0x00;
 PORTG = 0x00;
 DDRG  = 0x00;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 XDIV  = 0x00; //xtal divider
 XMCRA = 0x00; //external memory
 port_init();

 MCUCR = 0x00;
 EICRA = 0x00; //extended ext ints
 EICRB = 0x00; //extended ext ints
 EIMSK = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 ETIMSK = 0x00; //extended timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

void delay()
{
 unsigned char x,y,z;
 for(x=0;x<127;x++)
   for(y=0;y<127;y++)
     for(z=0;z<127;z++);
}

void main(void)
{
 init_devices();
 //insert your functional code here...
 DDRA=0x0F;//设置A口低4位为输出模式
 for(;;){
  PORTA=0x00;//点亮所有LED
  delay();
  PORTA=0x0D;//点亮DS1
  delay();
  PORTA=0x0B;//点亮DS2
  delay();
  PORTA=0x07;//点亮DS3
  delay();
  PORTA=0x0B;//点亮DS2
  delay();
  PORTA=0x0D;//点亮DS1
  delay();
  PORTA=0x0E;//点亮DS0
  delay();
 }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?