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

📄 motor_salve.c

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

#include "qep.h"
#include "SPI_slave.h"
#include "pwm.h"


extern unsigned char SPI_rx_buff[SPI_size];  
extern unsigned char SPI_tx_buff[SPI_size];  
extern unsigned char rx_index;  
extern unsigned char tx_index,SPI_tx_flag;
extern int	qep_cnt[QEP_size];
extern unsigned char pwm_value[2];
extern unsigned char pwm_flag;


void port_init(void)
{
 PORTA = 0xFF;
 DDRA  = 0x00;
 PORTB = 0xFF;
 DDRB  = 0x00;
 PORTC = 0x00; 
 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();
 pwm_init();
 spi_init();

 MCUCR = 0x0A;
 GICR  = 0xC0;
 TIMSK = 0x00; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
 }
void main(void)  
{   
  init_devices();
  
  while(1)
 {
 if(pwm_flag)
  {
  pwm_change();
  pwm_flag=0;
  }
    
 }  
}

⌨️ 快捷键说明

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