main.c

来自「用51单片机的io口模拟iic操作.不是采用中断的方式」· C语言 代码 · 共 61 行

C
61
字号

#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 + =
减小字号Ctrl + -
显示快捷键?