main._c

来自「avr 基于i2c接口的电源管理协议。包括主机发送主机接受从机发送接收。」· _C 代码 · 共 73 行

_C
73
字号
//ICC-AVR application builder : 2007-1-8 15:26:42
// Target : M8
// Crystal: 8.0000Mhz

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

#include "uart.h"
#include "function.h"
#include "port.h"
#include "twi.h"

//


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

 //close watch dog
 //set WDCE and WDE 
 WDTCR |= (1<<WDCE) | (1<<WDE);
 //close WDT
 WDTCR = 0x00;

}
//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
}
//
void main(void)
{
 //initial device
 init_devices();
 //insert your functional code here...

 while(1)
 {

  strTWI.STATUS=TW_OK;
  putchar(TWI_RW(0x30+TW_WRITE,&ORGDATA[0],8));
  while(strTWI.STATUS==TW_BUSY);//wait 
  if (strTWI.STATUS==TW_FAIL)
    {
        //operate faile
		putchar(0xff);
    }
  delay_100ms(0x10);
	


  } 
}

⌨️ 快捷键说明

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