twi_master_polling.h

来自「AVR单片机的T_TO_TWI通讯方式」· C头文件 代码 · 共 36 行

H
36
字号
#ifndef _TWI_MASTER_POLLING_H
#define _TWI_MASTER_POLLING_H

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

//TWI状态定义
//MT 主方式传输  MR 主方式接收
#define START 0x08 
#define RE_START 0x10
#define MT_SLA_ACK 0x18
#define MT_SLA_NOACK 0x20
#define MT_DATA_ACK  0x28
#define MT_DATA_NOACK 0x30
#define MR_SLA_ACK  0x40
#define MR_SLA_NOACK 0x48
#define MR_DATA_ACK 0x50
#define MR_DATA_NOACK 0x58
//常用TWI操作(主模式写和主模式读)
#define Start()    	  (TWCR=(1<<TWINT)|(1<<TWSTA)|(1<<TWEN))
#define Stop()     	  (TWCR=(1<<TWINT)|(1<<TWSTO)|(1<<TWEN))
#define Wait()	   	      {while(!(TWCR&(1<<TWINT)));}//while(!(TWCR&(1<<TWINT)))WDR()
#define TestAck() 	  (TWSR&0xf8)
#define SetAck()	      (TWCR|=(1<<TWEA))
#define SetNoAck()      (TWCR&=~(1<<TWEA))
#define Twi()	  	      (TWCR=(1<<TWEA)|(1<<TWINT)|(1<<TWEN))//含有响应位
#define Write8Bit(x)    {TWDR=(x);TWCR=(1<<TWINT)|(1<<TWEN);}
#endif

extern void twi_init(void);
extern unsigned char twi_write_byte(unsigned char device_adr,unsigned char RomAddress,unsigned char Wdata);
extern unsigned char twi_read_byte( unsigned char device_adr, unsigned char RomAddress);

extern unsigned char Write_Succsee_Flag;
extern unsigned char Read_Succsee_Flag;

⌨️ 快捷键说明

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