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

📄 test_isp.c

📁 AVR单片机开发中
💻 C
字号:
//ICC-AVR application builder : 2005-3-21 10:06:01
// Target : M128
// Crystal: 16.000Mhz

#include <iom128v.h>
#include <macros.h>
#include <stdio.h>
#define CH1    1
#define CH2    2
#define CH3    4
#define  READY 0XAA
#define  STOP  0X00
#define  TEST  0x1A

extern long len;
//SPI initialize
// clock rate: 2000000hz


  
  



unsigned char spi_tranByte (unsigned char cData, int addr)
{     
      
	  unsigned char *p = (unsigned char *) addr;
 
      *p = 0x00;
      SPDR = cData;
	  while (!(SPSR&0x80));
	  return SPDR;

}

	   
	   
long spi_cnt(unsigned char cha)
{  
      long temp=0;
      unsigned char buf=0;
	  temp=0;
	  switch (cha)
	  {
	         case CH1:     do
			               {
			               buf=spi_tranByte (CH1,0X9000);
						   asm ("nop");
			               asm ("nop");  
	                       asm ("nop");
						   }
						   while(buf!=READY);
						   delay_nus(100);
						   buf=spi_tranByte (CH1,0x9000);
						   temp=buf;
						   temp=temp*256;
						  
						   buf=spi_tranByte (CH1,0x9000);
						   temp=temp+buf;
						   temp=temp*256;
						   buf=spi_tranByte (CH1,0x9000);
						   temp=temp+buf;
						   temp*256;
						   buf=spi_tranByte (CH1,0x9000);
						   temp=temp+buf;
						   break;
					  
			 case CH2: 	  do
			               {
			               buf=spi_tranByte (CH2,0X9000);
						   asm ("nop");
			               asm ("nop");  
	                       asm ("nop");
						   }
						   while(buf!=READY);
						   delay_nus(100);
			 	  		   buf=spi_tranByte (CH2,0x9000);
						   temp+=buf;
						   temp=temp*256;
						   buf=spi_tranByte (CH2,0x9000);
						   temp+=buf;
						   temp=temp*256;
						   buf=spi_tranByte (CH2,0x9000);
						   temp+=buf;
						   temp=temp*256;
						   buf=spi_tranByte (CH2,0x9000);
						   temp+=buf;
						   break;
			
			 case CH3: 	  do
			               {
			               buf=spi_tranByte (CH3,0X9000);
						   asm ("nop");
			               asm ("nop");  
	                       asm ("nop");
						   }
						   while(buf!=READY);
						   delay_nus(100);
			 	  		   buf=spi_tranByte (CH3,0x9000);
						   temp+=buf;
						   temp=temp*256;
						   buf=spi_tranByte (CH3,0x9000);
						   temp+=buf;
						   temp=temp*256;
						   buf=spi_tranByte (CH3,0x9000);
						   temp+=buf;
						   temp=temp*256;
						   buf=spi_tranByte (CH3,0x9000);
						   temp+=buf;
						   break;
						  

			
	  }
	  len=temp;
	 
	  return  temp;
}


void port_init(void)
{
 DDRB  = 0x07;
 MCUCR |= 0X80;
 XMCRA = 0X00;
 XMCRB = 0X80;
 
}
//SPI initialize
// clock rate: 4000000hz




void spi_init(void)
{
 SPCR = 0x50;    //setup SPI
 SPSR = 0x00;    //setup SPI
}


void init_isp_devices(void)
{
 
 port_init();
 spi_init();
 
}

⌨️ 快捷键说明

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