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

📄 initial._c

📁 iic for avr very good
💻 _C
字号:
//ICC-AVR application builder : 2007-1-9 14:28:21
// Target : M8
// Crystal: 8.0000Mhz

#include <iom8v.h>
#include <macros.h>

void port_init(void)
{
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x30; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
}
//Watchdog initialize
// prescale: 2048K
void watchdog_init(void)
{
 WDR(); //this prevents a timout on enabling
 WDTCR = 0x0f; //WATCHDOG ENABLED - dont forget to issue WDRs
 /*
 //关闭看门狗
 //置位WDCE 和 WDE 
 WDTCR |= (1<<WDCE) | (1<<WDE);
 //关闭WDT
 WDTCR = 0x00;
 */
}

//TWI initialize
// bit rate:72
//50KHZ
void twi_init(void)
{
 TWCR= 0X00; //disable twi
 TWBR= 0x48; //set bit rate
 TWSR= 0x00; //set prescale
 TWAR= 0x01; //set slave address
 TWCR= 0x45; //enable twi
}

#pragma interrupt_handler twi_isr:18
void twi_isr(void)
{
 //twi event
}

//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
 UCSRB = 0x00; //disable while setting baud rate
 UCSRA = 0x02;
 UCSRC = BIT(URSEL) | 0x06;
 UBRRL = 0x67; //set baud rate lo
 UBRRH = 0x00; //set baud rate hi
 UCSRB = 0x18;
}

//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();
 twi_init();
 uart0_init();


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

⌨️ 快捷键说明

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