代码如下
char data[20];
char text_buff[20];
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
RS232_buff[RS232_rec_counter] = USART1->DR;//
RS232_rec_counter ++;
if(RS232_buff[RS232_rec_counter - 1] == 'S')
{
strcpy(text_buff,RS232_buff);
while(AT24CXX_Check())
{
delay_ms(500);
}
AT24CXX_Write(0,text_buff,RS232_rec_counter);
AT24CXX_Read(0,data,RS232_rec_counter);
printf("%s\n",data);
RS232_rec_counter = 0;
}
#define SDA_IN() {GPIOB->MODER&=~(3<<(7*2));GPIOB->MODER|=(0<<(7*2));} //PB7输入模式
#define SDA_OUT() {GPIOB->MODER&=~(3<<(7*2));GPIOB->MODER|=(1<<(7*2));} //PB7输出模式
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
#define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414
#define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出数据寄存器的位
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入数据寄存器的位
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //
#define IIC_SCL PBout(6) //PB6用于SCL,将会往该位设置数据
#define IIC_SDA PBout(7) //PB7用于SDA,输出模式下的往输出寄存器这一位写数据
#define READ_SDA PBin(7) //输入模式下往输入寄存器的这一位写数据 |