eeprom.c

来自「EPPROM应用,测试程序,AVR内核,供初学者参考」· C语言 代码 · 共 67 行

C
67
字号
//ICC-AVR application builder : 2008-5-10 上午 09:22:27
// Target : m48
// Crystal: 8.0000Mhz

#include <iom48v.h>
#include <macros.h>

void port_init(void)
{
 PORTB = 0x10;
 DDRB  = 0x00;
 PORTC = 0x02; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
}

//TIMER0 initialize - prescale:1024
// WGM: Normal
// desired value: 64Hz
// actual value: 64.037Hz (0.1%)
void timer0_init(void)
{
 TCCR0B = 0x00; //stop
 TCNT0 = 0x86; //set count
 TCCR0A = 0x00; 
 TCCR0B = 0x05; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
 //TIMER0 has overflowed
}

#pragma interrupt_handler int0_isr:iv_INT0
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();
 timer0_init();

 MCUCR = 0x00;
 EICRA = 0x02; //extended ext ints
 EIMSK = 0x01;
 
 TIMSK0 = 0x01; //timer 0 interrupt sources
 TIMSK1 = 0x00; //timer 1 interrupt sources
 TIMSK2 = 0x00; //timer 2 interrupt sources
 
 PCMSK0 = 0x00; //pin change mask 0 
 PCMSK1 = 0x00; //pin change mask 1 
 PCMSK2 = 0x00; //pin change mask 2
 PCICR = 0x00; //pin change enable 
 PRR = 0x00; //power controller
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

⌨️ 快捷键说明

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