//Power-up sequence
//Set port 1 high
P1 = 0xff;
//Apply power (Vcc+Vpp)
portb = 0x4;
//Set RST and XTAL1 to GND
portb = 0x7;
DXTAL1 = 0;
//Set RST to H
portb = 0x4;
//Set P3.2 to H
DP32 = 1;

//Read signature byte
_nop_();
c = P1;
uln(10);
if (c == 0x1e) strcpy(chvendor, "Atmel");
else
	{
	strcpy(chvendor, "unknown ");
	sprintf(str, "%i", (int)c);
	strcat(chvendor, str);
	}
udskrivs("                        The chip is an ");
udskrivs(chvendor);
udskrivs(" ");

//Increment address counter
DXTAL1 = 1;
_nop_();
pause(1);
DXTAL1 = 0;
_nop_();

//Read signature byte
c = P1;
if (c == 0x41)
	{
	strcpy(chtype, "AT89C4051");
	chsize = 4096;
	}
else if (c == 0x21)
	{
	strcpy(chtype, "AT89C2051");
	chsize = 2048;
	}
else if (c == 0x12)
	{
	strcpy(chtype, "AT89C1051U");
	chsize = 1024;
	}
else if (c == 0x11)
	{
	strcpy(chtype, "AT89C1051");
	chsize = 1024;
	}
else
	{
	strcpy(chtype, "unknown ");
	sprintf(str, "%i", (int)c);
	strcat(chtype, str);
	chsize = 4096;
	}
udskrivs(chtype);
udskrivs("rn");

//Power down sequence
//Set XTAL1 to L
DXTAL1 = 0;
//Set RST to L
portb = 0x7;
//Turn Vcc power off
portb = 0x47;
//Set port 1 low
P1 = 0x00;
DP31 = 0;
DP32 = 0;

udskrivs("nn   * * * Press any key to continue * * *");

uln(11);

while (! RI);
c = SBUF;
RI = 0;
