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

📄 init.c

📁 avr单片机与flash存储器通信程序,调试通过,希望对大家有所帮助.
💻 C
字号:
//ICC-AVR application builder : 2006-4-29 3:07:04
// Target : M8515
// Crystal: 11.059Mhz

#include <iom8515v.h>
#include <macros.h>

#define uchar unsigned char
void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0xFF;
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x00;
 DDRC  = 0xC0;
 PORTD = 0x00;
 DDRD  = 0x00; 
 PORTE = 0x00;
 DDRE  = 0x00; 
}

//Watchdog initialize
// prescale: 2048K
void watchdog_init(void)
{
 WDR(); //this prevents a timout on enabling
 WDTCR = 0x0F; //WATCHDOG ENABLED - dont forget WDR
}

//TIMER1 initialize - prescale:1
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1mSec
// actual value:  1.000mSec (0.0%)
void timer1_init(void)
{
 TCCR1B = 0x00; //stop
 TCNT1H = 0xD4; //setup
 TCNT1L = 0xCE;
 OCR1AH = 0x2B;
 OCR1AL = 0x32;
 OCR1BH = 0x2B;
 OCR1BL = 0x32;
 TCCR1A = 0x00;
 TCCR1B = 0x01; //start Timer
}

uchar count=0;
extern uchar shuma;
#pragma interrupt_handler timer1_ovf_isr:7
void timer1_ovf_isr(void)
{
 TCNT1H = 0xD4; //reload counter high value
 TCNT1L = 0xCE; //reload counter low value
 if(count++==500){count=0;shuma++;}
}

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

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

⌨️ 快捷键说明

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