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

📄 temp

📁 用ICC编写的程序包括SPI
💻
字号:
//ICC-AVR application builder : 2005-4-1 9:40:07
// Target : M16
// Crystal: 7.3728Mhz

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

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

//TIMER1 initialize - prescale:1
// WGM: 8) PWM phz freq correct, TOP=ICRn
// desired value: 14.4KHz
// actual value: 14.456KHz (0.4%)
void timer1_init(void)
{
 TCCR1B = 0x00; //stop
 TCNT1H = 0xFF; //setup
 TCNT1L = 0x01;
 OCR1AH = 0x00;
 OCR1AL = 0xFF;
 OCR1BH = 0x00;
 OCR1BL = 0xFF;
 OCR1CH = $OCR1CH$;
 OCR1CL = $OCR1CL$;
 ICR1H  = 0x00;
 ICR1L  = 0xFF;
 TCCR1A = 0x50;
 TCCR1B = 0x11; //start Timer
}

//TIMER2 initialize - prescale:256
// WGM: Normal
// desired value: 5mSec
// actual value:  4.965mSec (0.7%)
void timer2_init(void)
{
 TCCR2 = 0x00; //stop
 ASSR  = 0x00; //set async mode
 TCNT2 = 0x71; //setup
 OCR2  = 0x8F;
 TCCR2 = 0x06; //start
}

#pragma interrupt_handler timer2_ovf_isr:5
void timer2_ovf_isr(void)
{
 TCNT2 = 0x71; //reload counter value
}

//SPI initialize
// clock rate: 1843199hz
void spi_init(void)
{
 SPCR = 0xCC; //setup SPI
 SPSR = 0x00; //setup SPI
}

#pragma interrupt_handler spi_stc_isr:11
void spi_stc_isr(void)
{
 //byte in SPDR has been sent/received
}

//ADC initialize
// Conversion time: 7uS
void adc_init(void)
{
 ADCSR = 0x00; //disable adc
 ADMUX = 0x00; //select adc input 0
 ACSR  = 0x00;
 ADCSR = 0x8A;
}

#pragma interrupt_handler adc_isr:15
void adc_isr(void)
{
 //conversion complete, read value (int) using...
 // value=ADCL;            //Read 8 low bits first (important)
 // value|=(int)ADCH << 8; //read 2 high bits and shift into top byte
}

#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
 //external interupt on INT0
}

//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 = 0x00;
 GICR  = 0x40;
 TIMSK = 0x40; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

⌨️ 快捷键说明

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