⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getbyte.c

📁 一个AVR单片机at17c85的系统程序
💻 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 + -