📄 getbyte.c
字号:
// GetByte.c
// reads a byte from the slave, lastbyte is used to tell slave that the read is over
#include "at17c.h"
extern void WriteSCL(unsigned char state);
extern void WriteSDA(unsigned char state);
extern void BitDelay(void);
extern unsigned char SetSCLHigh(void);
unsigned char GetByte(unsigned char lastbyte) {
// lastbyte == 1 for last byte
unsigned char i, bit;
unsigned char result = 0;
DDRB &= 0xfe; // SDA to input
for (i = 0;i < 8;i++) { // each bit at a time, LSB first
SetSCLHigh();
BitDelay();
bit = (PINB & 0x01);
result = (bit << (i)) | result;
WriteSCL(0);
BitDelay();
}
// send ACK
WriteSDA(lastbyte); // no ack on last byte ... lastbyte = 1 for the last byte
BitDelay();
SetSCLHigh();
BitDelay();
WriteSCL(0);
BitDelay();
WriteSDA(1);
BitDelay();
return(result);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -