?? 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 + -