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

📄 motor_slave.c

📁 用ICC编写的程序包括SPI
💻 C
字号:
#include <iom16v.h>
#include <macros.h>

#include "time.h"
#include "ad.h"
#include "qep.h"
#include "isr.h"
#include "SPI_slave.h"


extern unsigned char SPI_rx_buff[SPI_size];  
extern unsigned char SPI_tx_buff[SPI_size];  
extern unsigned char rx_wr_index,rx_rd_index,rx_counter,rx_buffer_overflow;  
extern unsigned char tx_wr_index,tx_rd_index,tx_counter,SPI_ok,SPI_datain;
extern int	qep_cnt[QEP_size];
extern unsigned char time_flag;
extern unsigned int AD_value[AD_size]; 
extern unsigned char ad_index; 

extern const unsigned char ad_channel[AD_size];

void port_init(void)
{
 PORTA = 0xFF;
 DDRA  = 0x00;
 PORTB = 0x00;
 DDRB  = 0x40;
 PORTC = 0x00; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x30;
} 

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();
 timer1_init();
 timer2_init();
 spi_init();
 adc_init();

 MCUCR = 0x0F;
 GICR  = 0xC0;
 TIMSK = 0x40; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
 }
void main(void)  
{  
  unsigned char i=0;    
  while(1)
  {
   time_flag=0;
   while(!time_flag)  
   {  
  	  
	  if(SPI_datain)
	  {
	  	switch(getSPIchar())
		 {
		    case 0xaa:
				if(i<4)
				{
				 putSPIchar(*((unsigned char*)(qep_cnt)+i));
				 i++;
				 }
				 else
				 i=0;
				break;
		
			default:
		  	putSPIchar(0xee);break;
		  }
		 SPI_datain=0;
	  }
    }
  
  }  
}  

⌨️ 快捷键说明

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