96 lines
3.2 KiB
C
96 lines
3.2 KiB
C
|
#ifndef __24CXX_H
|
|||
|
#define __24CXX_H
|
|||
|
|
|||
|
#include <stdint.h>
|
|||
|
#include "stm32f10x.h"
|
|||
|
#define AT24C01 127
|
|||
|
#define AT24C02 255
|
|||
|
#define AT24C04 511
|
|||
|
#define AT24C08 1023
|
|||
|
#define AT24C16 2047
|
|||
|
#define AT24C32 4095
|
|||
|
#define AT24C64 8191
|
|||
|
#define AT24C128 16383
|
|||
|
#define AT24C256 32767
|
|||
|
|
|||
|
#define EE_TYPE AT24C32 //ʹ<>õ<EFBFBD><C3B5><EFBFBD>AT24C16
|
|||
|
#define EE_DEV_ADDR 0xA0
|
|||
|
|
|||
|
#if EE_TYPE == AT24C01
|
|||
|
#define EE_PAGE_SIZE 8 //<2F>ֽ<EFBFBD>/ҳ
|
|||
|
#define EE_SIZE 0x007F //eeprom<6F><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
#elif EE_TYPE == AT24C02
|
|||
|
#define EE_PAGE_SIZE 16
|
|||
|
#define EE_SIZE 0x00FF
|
|||
|
#elif EE_TYPE == AT24C04
|
|||
|
#define EE_PAGE_SIZE 16
|
|||
|
#define EE_SIZE 0x01FF
|
|||
|
#elif EE_TYPE == AT24C08
|
|||
|
#define EE_PAGE_SIZE 16
|
|||
|
#define EE_SIZE 0x03FF
|
|||
|
#elif EE_TYPE == AT24C16
|
|||
|
#define EE_PAGE_SIZE 16
|
|||
|
#define EE_SIZE 0x07FF
|
|||
|
#elif EE_TYPE == AT24C32
|
|||
|
#define EE_PAGE_SIZE 32
|
|||
|
#define EE_SIZE 0x0FFF
|
|||
|
#elif EE_TYPE == AT24C64
|
|||
|
#define EE_PAGE_SIZE 32
|
|||
|
#define EE_SIZE 0x1FFF
|
|||
|
#elif EE_TYPE == AT24C128
|
|||
|
#define EE_PAGE_SIZE 64
|
|||
|
#define EE_SIZE 0x3FFF
|
|||
|
#elif EE_TYPE == AT24C256
|
|||
|
#define EE_PAGE_SIZE 64
|
|||
|
#define EE_SIZE 0x7FFF
|
|||
|
#elif EE_TYPE == AT24C512
|
|||
|
#define EE_PAGE_SIZE 128
|
|||
|
#define EE_SIZE 0xFFFF
|
|||
|
#endif
|
|||
|
|
|||
|
#define EEPROM_I2C_WR 0 /* д<><D0B4><EFBFBD><EFBFBD>bit */
|
|||
|
#define EEPROM_I2C_RD 1 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bit */
|
|||
|
|
|||
|
// void AT24cxx_init(void);//<2F><><EFBFBD>Ի<EFBFBD>IIC
|
|||
|
// u8 AT24cxx_ReadOneByte(u16 ReadAddr);//ָ<><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ȡһ<C8A1><D2BB><EFBFBD>ֽ<EFBFBD>
|
|||
|
// void AT24cxx_WriteOneByte(u16 WriteAddr,u8 data);//ָ<><D6B8><EFBFBD><EFBFBD>ַдһ<D0B4><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// void AT24cxx_WriteLenByte(u16 WriteAddr,u32 data,u8 len);//<2F><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼд<CABC><D0B4>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// u32 AT24cxx_ReadLenByte(u16 ReadAddr,u8 len);//<2F><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// void AT24cxx_Write(u16 WriteAddr,u8 *buf,u16 len);//<2F><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼд<CABC><D0B4>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// void AT24cxx_Read(u16 ReadAddr,u8 *buf,u16 len);//<2F><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// u8 AT24cxx_Check(void);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
void ee_Init(void);
|
|||
|
u8 ee_ReadOneByte(u16 ReadAddr);
|
|||
|
void ee_WriteOneByte(u16 WriteAddr, u8 data);
|
|||
|
uint8_t ee_WriteBytes(uint8_t *_pWriteBuf, uint16_t _usAddress, uint16_t _usSize);
|
|||
|
uint8_t ee_ReadBytes(uint8_t *_pReadBuf, uint16_t _usAddress, uint16_t _usSize);
|
|||
|
/* <20><><EFBFBD><EFBFBD>I2C<32><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>GPIO<49>˿<EFBFBD>, <20>û<EFBFBD>ֻ<EFBFBD><D6BB>Ҫ<EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD>д<EFBFBD><D0B4>뼴<EFBFBD><EBBCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>SCL<43><4C>SDA<44><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
|||
|
//IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
#define SDA_IN() //{GPIOB->ODR&=0XFFFF3FFF;GPIOB->ODR|=GPIO_Mode_IN<<14;}//sda<64><61><EFBFBD><EFBFBD>
|
|||
|
#define SDA_OUT() //{GPIOB->ODR&=0XFFFF3FFF;GPIOB->ODR|=GPIO_Mode_OUT<<14;}//sda<64><61><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
|
|||
|
//IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// #define IIC_SDA0 GPIOB->BRR=GPIO_Pin_11;//sda=0
|
|||
|
// #define IIC_SDA1 GPIOB->BSRR=GPIO_Pin_11;//sda=1
|
|||
|
// #define IIC_SCL0 GPIOB->BRR=GPIO_Pin_10;
|
|||
|
// #define IIC_SCL1 GPIOB->BSRR=GPIO_Pin_10;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// #define Read_IIC_SDA() ((GPIOB->IDR&GPIO_Pin_11)!=0)?1:0 //<2F>жϽ<D0B6><CFBD>յ<EFBFBD><D5B5><EFBFBD>λ
|
|||
|
//IIC<49><43><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// void IIC_Init(void);// <09><>ʼ<EFBFBD><CABC>iic<69><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IO<49><4F>
|
|||
|
//void IIC_Start(void); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ź<EFBFBD>
|
|||
|
//void IIC_Stop(void); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3>ź<EFBFBD>
|
|||
|
//void IIC_Write_Byte(u8 dat);//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
|
|||
|
//u8 IIC_Read_Byte(unsigned char ack);//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
|
|||
|
//u8 IIC_Wait_Ack(void);//<2F>ȴ<EFBFBD>ACK<43>ź<EFBFBD>
|
|||
|
//void IIC_Ack(void);//<2F><><EFBFBD><EFBFBD>ACK<43>ź<EFBFBD>
|
|||
|
//void IIC_NAck(void);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ACK<43>ź<EFBFBD>
|
|||
|
|
|||
|
#endif
|