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

📄 main.c

📁 一个关于AVR单片机的例程
💻 C
字号:
// ICC-AVR application builder : 2007-2-14 21:34:00
// Target : M16
// Crystal: 7.3728Mhz
// 演示 at45db041 读写过程

#include "config.h"

void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0x00;
 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();
 at4541_init(); //at45db041初始化

 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

void main(void)
{
 unsigned int temp1;
 unsigned char i=0,temp2=0;
 unsigned char receive_buf[10];
 init_devices();
 at4541_commond_send(0x8200,0x00);//开始写指令,地址为0x00
 for(i=0;i<10;i++)
 {
  at4541_write(i);
 }
 at4541_stop();
 delay_ms(500);
 
 while(!at4541_check_busy())
  ;//忙等待
  
 if(at4541_check_busy())
 {
  at4541_commond_send(0xe800,0x00);
  for(i=0;i<10;i++)
  {
   receive_buf[i]=at4541_read();
  }
 }
 while(1)
 ;
}

⌨️ 快捷键说明

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