93c66.c

来自「嵌入式C语言程序设计——使用MCS-51」· C语言 代码 · 共 66 行

C
66
字号
#include	<intrins.h>
#include	<REGX51.h>
//
#define 	READ    	0x0C00	/* xxxx110A8,A7-A0 */
#define 	EWEN    	0x0980	/* xxxx1001 ,1xxxxxxx */
#define 	WRITE   	0x0A00	/* xxxx101A8,A7-A0 */
#define 	EWDS    	0x0800	/* xxxx1000,0xxxxxxx */
//
#define 	ShiftBit 	4
//
#define		CS			P2_3
#define		SK			P2_2
#define		DI			P2_1
#define		DO			P2_0
//
char code int2charx[]="0123456789ABCDEF";
void 			write_command(int);
unsigned char	read_byte(int);
void 			write_byte(int,unsigned char);
void 			check_busy(void);
//
unsigned char read_byte(int address)
{ 
	int i,command;	
	unsigned char temp;

	CS=1;
	command=(READ|address);  
	write_command(command);
	for(i=0;i<8;i++)		
	{
		SK=1;
		SK=0;
		temp= (temp << 1);
		if(DO==1)
			temp=(temp | 0x01); 
	}	
	CS=0; 
	return(temp);	    
} 
void write_enable()
{
	int command;	
	CS=1;
	command=EWEN;
	write_command(command); 	
	CS=0;
}
void write_disable()
{
	int command;	

	CS=1;
	command=EWDS;
	write_command(command); 	
	CS=0;
}
void write_byte(int address,unsigned char write_data)
{ 
	int i,command;	

	write_enable();
 	CS=1;
	command=(WRITE|address);
	write_command(command);
	for(i=0;i<8;i++)		/* 糶

⌨️ 快捷键说明

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