⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 一个关于AVR单片机的例程
💻 C
字号:
//ICC-AVR application builder : 2007-1-29 10:04:38
// Target : M16
// Crystal: 7.3728Mhz
// 功能:霓虹灯程序
// 作者:古欣
// AVR与虚拟仪器 http://www.avrvi.com

#include <iom16v.h>
#include <macros.h>

#define led_port PORTA
//定义输出端口
#define led_ddr DDRA
//定义输出控制寄存器
//可以自行修改,必须保持 led_port和led_ddr一致,PORTA对应DDRA

const led_table[20]={   //定义要输出的值
0xff,0x00,0x88,0x44,0x22,
0x11,0x33,0x77,0xff,0x66,
0x18,0x24,0x42,0x81,0xa5,
0xe7,0xff,0x7e,0x3c,0x18};


void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0x00;
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x00; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
 led_ddr=0xff; //设置LED的端口为输出
}

//call this routine to initialize all peripherals
//此处为ICC系统生成,未做更改
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
}

void Delay(void)  //延时,没有详细计算
{
unsigned char i,j;
for(i=150;i>0;i--)
{
  for(j=200;j>0;j--)
;
}
}

void main(void)
{
 unsigned int i;
 init_devices();
 while(1)
 {
 for(i=0;i<20;i++)
   {
    led_port=led_table[i]; //顺序显示表中的内容
	Delay();               //延时
	Delay();               //延时
	Delay();               //延时
   }
 }
}

⌨️ 快捷键说明

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