89C51 programmer,89C51 programmer

Publisher:创新之星Latest update time:2023-10-20 Source: elecfansKeywords:89C51  programmer Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The programmer for the 89c51 chip, the picture is a bit small, just look at it, it comes with the program

program:

#include "at89x52.h"
#include "stdio.h"
#include "intrins.h"
#include "ctype.h"

sbit rdy=P3^2;
sbit vpp=P3^3;
sbit p26=P3^4;
sbit p27=P3^5;
sbit p36=P3^6;
sbit p37=P3^7;
sbit prog=P2^7;

void init_serial()
{
SCON=0x50; /*mode 1*/
TMOD=0x20;
TH1=0xfd;
PCON=0x80; /*38400bps*/
TR1=1; /*load tmr1*/
TI=1;
ES=1;}

void init_pro()
{
p26=0;
p27=0;
p36=0;
p37=0;
vpp=1;
prog=1;
}

void sendbyte(unsigned char da) /*send a byte*/
{
while(!TI);
TI=0;
SBUF=da;}

unsigned char IntToAscii(unsigned char a) /*change DEC to ASCII HEX code*/
{
if(a<10) return a+48;
if(a>9) return a+55;}

unsigned int getadr() /*get 5 diti DEC adr*/
{
unsigned char i,a[5];
for(i=0;i<5;i++)
{
while(!RI);
RI=0;
a[i]=SBUF-48;
}
return a[0]*10000+a[1]*1000+a[2]*100+a[3]*10+a[4];}

unsigned char getdata() /*get 2 diti HEX data*/
{
unsigned char d1,d2;
while(!RI);
RI=0;
d1=toint(SBUF);
while(!RI);
RI=0;
d2=toint(SBUF);
return d1*16+d2;}

unsigned int detchip(int adr)
{
P0=0xff;
P1=adr%256;P2=adr/256;
init_pro();
_nop_();_nop_();_nop_();_nop_();_nop_(); /*delay 10 us*/
_nop_();_nop_();_nop_();_nop_();_nop_();
return P0;}

void read()
{
unsigned int adr,maxadr;
unsigned char h,l;
P0=0xff;
maxadr=getadr();
for(adr=0;adr{
P1=adr%256;P2=adr/256;
p26=0;
p27=0;
p36=1;
p37=1;
vpp=1;
prog=1;
h=IntToAscii(P0/16);
sendbyte(h);
l=IntToAscii(P0%16);
sendbyte(l);}
init_pro();}

unsigned int test(unsigned int nn)
{
unsigned int adr,counter=0;
P0=0xff;
for(adr=0;adr{
P1=adr%256;P2=adr/256;
p26=0;
p27=0;
p36=1;
p37=1;
vpp=1;
prog=1;
_nop_();_nop_();_nop_();_nop_();_nop_(); /*delay 10 us*/
_nop_();_nop_();_nop_();_nop_();_nop_();
if(P0!=0xff) counter++;}
init_pro();
return counter;}

unsigned char erase(unsigned int nn,unsigned int p)
{
unsigned int i;
P0=0xff;
p26=1;
p27=0;
p36=0;
p37=0;
vpp=0;
prog=1;
for(i=0;i<50000;i++) _nop_();
switch(p)
{
case 0 : prog=0;
prog=1;
break;
case 1 : prog=0;
_nop_();
prog=1;
break;
case 2 : prog=0;
_nop_();_nop_();
prog=1;
break;
case 3 : prog=0;
_nop_();_nop_();_nop_();
prog=1;
break;
case 4 : prog=0;
_nop_();_nop_();_nop_();_nop_();
prog=1;
break;
case 5 : prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_();

prog=1;
break;
case 6 : prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
prog=1;
break;
case 7 : prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
prog=1;
break;
case 8 : prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
prog=1;
break;
default: prog=0;
for(i=0;i

prog=1;
break;}
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
vpp=1;
for(i=0;i

if(test(nn)==0) return 's';
else return 'f';}

unsigned char write()
{
unsigned int adr,d,i;
p26=0;
p27=1;
p36=1;
p37=1;
vpp=0;
prog=1;
for(i=0;i<4000;i++) _nop_();
adr=getadr();
d=getdata();
while(1)
{
if(adr>50000) break;
P1=adr%256;P2=(adr/256)|0x80;
P0=d;
TI=0;
SBUF='s';
prog=0;
_nop_();_nop_();_nop_();
prog=1;
adr=getadr();
d=getdata();
while(!rdy);}
init_pro();
return 'f';}

unsigned char lock(unsigned char level)
{
unsigned int i;
vpp=0;
if(level==1) {p26=1;p27=1;p36=1;p37=1;}
if(level==2) {p26=1;p27=1;p36=0;p37=0;}
if(level==3) {p26=1;p27=0;p36=1;p37=0;}
for(i=0;i<4000;i++) _nop_();
prog=1;
_nop_();_nop_();_nop_();_nop_();_nop_(); /*delay 10 us*/
_nop_();_nop_();_nop_();_nop_();_nop_();
prog=0;
_nop_();_nop_();_nop_();_nop_();_nop_(); /*delay 10 us*/
_nop_();_nop_();_nop_();_nop_();_nop_();
prog=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
while(!rdy);
init_pro();
return 'o';}

void main()
{
unsigned char data c;
unsigned int data adr,l,dx;
init_pro();
init_serial();
while(1)
{
init_pro();
scanf("%c",&c);
switch(c)
{
case 'c' : printf("%c",'o');
break;
case 'd' : scanf("%x",&adr);
printf("%x",detchip(adr));
break;
case 't' : scanf("%u",&dx);
printf("%u",test(dx));
break;
case 'r' : read();
break;
case 'e' : scanf("%u,%u",&adr,&dx);
printf("%c",erase(adr,dx));
break;
case 'w' : printf("%c",write());
break;
case 'l' : scanf("%u",&l);
printf("%c",lock(l));
break;
case 'h' : printf("**********Er6y Programmer Help Window***********n");
break;
default : break;}


}
}

Schematic:


Keywords:89C51  programmer Reference address:89C51 programmer,89C51 programmer

Previous article:Application circuit based on 89C51 and 82C53 to control TA8435H
Next article:Interface circuit between X25165 and 89C51

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号