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

📄 main.c

📁 用51单片机的io口模拟iic操作.不是采用中断的方式
💻 C
字号:

#include<At89X51.h>
#include <intrins.h>
#include <stdio.h>
#include <string.h>

//sbit SDA = 0xB0^5;	//P3_5 connect the SDA footprint
//sbit SCL = 0xB0^4;	//P3_4 connect the CLK footprint


extern void WriteByte(char nData, const unsigned char nAdress);
extern char ReadByte(const unsigned char nAddress);
extern void ClearAll(void);

/**************************** MAIN FUNC*****************************************/

void Main()
{

	unsigned short i = 0;

	char nReceive[32];
	char nStore[] = "ZZH is an excellent boy.\0";
	const unsigned char nAdress = 0x10;		//start adress when store data.(0 - 256)


	//random write each byte of the nStore[] into 24c02-----------------------------------
	for(i = 0; i <= sizeof(nStore) - 1; i++)	//will be failue if ignore 6ms
	{
		WriteByte(nStore[i], nAdress + i);		
	}
	


	
	//read the data in 24c02----------------------------------------
	for(i = 0; i <= sizeof(nStore) - 1; i++)
	{
		nReceive[i] = ReadByte(nAdress + i);
	}


	//validate the write-operation
	if(0 == strcmp(nReceive, nStore)) // should be equal
	{
		P1 = 0;	//YES!
	}




	//clear all data in 24c02----------------------------------------
	ClearAll();
	//validate the clear-operation
	P1 = ReadByte(123);
	
	

	while(1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -