82C55A software simulation read and write timing based on 51 and Protues simulation


Simulation diagram:

Source code:

/***************   writer:shopping.w   ******************/
#include <reg52.h>
#include <absacc.h>
#define uint unsigned int
#define uchar unsigned char
//#define PA XBYTE[0x0000]
//#define PB XBYTE[0x0001]
//#define PC XBYTE[0x0002]
//#define COM XBYTE[0x0003]
#define ADDR_CMD              0x03
#define ADDR_A_PORT           0x00
#define ADDR_B_PORT           0x01
#define ADDR_C_PORT           0x02


#define C_PORT_LOW_IN_CMD     (0x01<<0)
#define C_PORT_LOW_OUT_CMD    (~(0x01<<0))
#define B_PORT_IN_CMD         (0x01<<1)
#define B_PORT_OUT_CMD        (~(0x01<<1))
#define C_PORT_UP_IN_CMD      (0x01<<3)
#define C_PORT_UP_OUT_CMD     (~(0x01<<3))
#define A_PORT_IN_CMD         (0x01<<4)
#define A_PORT_OUT_CMD        (~(0x01<<4))

#define _LE_L (_LE = 0)
#define _LE_H (_LE = 1)
#define _WR_L  (_WR = 0)
#define _WR_H  (_WR = 1)
#define _RD_L  (_RD = 0)
#define _RD_H  (_RD = 1)
#define _CS_L  (_CS = 0)
#define _CS_H  (_CS = 1)


sbit _LE = P2^7;
sbit _WR = P2^5;
sbit _RD = P2^6;
sbit _CS = P2^4;



uchar code DSY_CODE_Queue[]=
{
	0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
};

uchar code DSY_Index[]=
{
 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80
};

void WriteData8255(uchar addr, uchar dat);
uchar ReadData8255(uchar addr);


void Delay(uint x)
{
 	uchar i;
	while(x--)
	{
	 	for(i=0;i<120;i++);
	}
}

void WriteData8255(uchar addr, uchar dat)
{
		_CS_H;
	  _WR_H;
	  _RD_H;
	  _LE_H;
	  Delay(10);
	  _CS_L;
	  P0 = addr;
	  Delay(10);
	  _LE_L; //Latch address
	  P3 = that;
	  Delay(10);
	  _WR_L;
	  Delay(10);
	  _WR_H;
	  Delay(10);
	  _CS = 1;
}

uchar ReadData8255(uchar addr)
{
	  uchar rval = 0;
	  _CS_H;
		_WR_H;
		_RD_H;
	
		_LE_H;
		Delay(10);
		_CS_L;
		P0 = addr;
		Delay(10);
		_LE_L; //Latch address
		_RD_L; //Start read signal
		P3 = 0xff; //Can only be read after it is set
		rval = P3;  
		Delay(10);
		_RD_H;
		Delay(10);
		_CS_H;
	  return rval;
}


void main()
{
	uchar value = 0;
	uchar i,j,k;


#if 1
	_CS = 1;
	_WR = 1;
	_RD = 1;
	//write control word register address
	_LE = 1;
	Delay(10);
	_CS = 0;
	P0 = ADDR_CMD; //A1A0=11, CS=0, write control word
	Delay(10);
	_LE = 0; //Latch lock address
	P3 = 0x80; //PA,PB,PC full output (mode selection)
	Delay(10);
	_WR = 0;
	Delay(10);
	_WR = 1;
	Delay(10);
	_CS = 1;
#endif
  WriteData8255(ADDR_CMD, 0x80); //Configure 8255 to work in MOD0 mode, PA, PB, PC all output.

 
	while(1)
	{
#if 1
		 	for(k=0;k<8;k++)
			{
				WriteData8255(ADDR_C_PORT, DSY_Index[k]);
				WriteData8255(ADDR_A_PORT, DSY_CODE_Queue[k]);
// /*Write B port data, A1, A0 = 2'b01*/
//				_CS = 1;
//				_WR = 1;
//				_RD = 1;
//				
// _LE = 1;
//				Delay(10);
//				_CS = 0;
//				P0 = ADDR_C_PORT;  
//				Delay(10);
// _LE = 0;
//			  P3 = DSY_Index[k];
//			  Delay(10);
//				_WR = 0;
//				Delay(10);
//				_WR = 1;
//				Delay(10);
//				_CS = 1;
//				Delay(10);
//	
// /*Write A port data, A1, A0 = 2'b00*/
//				_CS = 1;
//				_WR = 1;
//				_RD = 1;
//				
// _LE = 1;
//				Delay(10);
//				_CS = 0;
//				P0 = ADDR_A_PORT;
//				Delay(10);
// _LE = 0;
//				P3 = DSY_CODE_Queue[k]; //PA
//				Delay(10);
//				_WR = 0;
//				Delay(10);
//				_WR = 1;
//				Delay(10);
//				_CS = 1;
				Delay(200);
			}
			
#endif
			
//		_CS = 1;
//		_WR = 1;
//		_RD = 1;
// //Write control word register address
// _LE = 1;
//		Delay(10);
//		_CS = 0;
// P0 = ADDR_CMD; //A1A0=11, CS=0, write control word
//		Delay(10);
// _LE = 0;
// P3 = 0x82; //PB input, PA, PC output (mode selection)
//		Delay(10);
//		_WR = 0;
//		Delay(10);
//		_WR = 1;
//		Delay(10);
//		_CS = 1;
	 WriteData8255(ADDR_CMD, 0x82); //PB input, PA, PC output (mode selection)
   // while(1);
// /*Read B port data, A1, A0 = 2'b02*/
//	  _CS = 1;
//		_WR = 1;
//		_RD = 1;
//		  
// _LE = 1;
//		Delay(10);
//		_CS = 0;
//		P0 = ADDR_B_PORT;
//		Delay(10);
// _LE = 0;
//		_RD = 0;
// P3 = 0xff; // can only be read after it is set
// value = P3; // read the value of PB
//		Delay(10);
//		_RD = 1;
//		Delay(10);
//		_CS = 1;
		value = ReadData8255(ADDR_B_PORT);
		
		P1 = value; //Assign the read value to P1
		Delay(200);
		while(1);
	}


	
	
	
	
	
	
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325999816&siteId=291194637