unsigned char d[10]; //10-bit display buffer for display
//==========================================================
//Hexadecimal to decimal output subroutine: display data, start bit, end bit, whether there is a decimal point
//==============================================================
void output(unsigned long dd,unsigned char s,unsigned char
e,unsigned char dip) {
unsigned long div;
unsigned char tm[8],i,j;
div=10000000;
for (i=0;i<8;i++) {
tm[i]=dd/div;
dd%=div;
div/=10;
}
for (i=0;i<6;i++) {
if (tm[i]!=0) break;
tm[i]=nul;
}
tm[5]|=dip; //Decimal point control, please refer to "Serial LED Digital Tube Display Driver"
j=7;
for (i=s;i
j--;
}
}
//Convert the decimal number of display digits 5-9 into hexadecimal number
unsigned int input(void) {
unsigned int dd,dat;
dd=10000;dat=0;
for (i=5;i<10;i++) {
dat+=dd*temp;
dd/=10;
}
return(dat);
}
/* 89C51 series CPU programmer receives CPU program*/
#i nclude
#i nclude
#i nclude
#define e 8
#define p 9
#define l 10
sbit led=P3^2;
sbit p27=P2^7;
sbit p26=P2^6;
sbit p36=P3^6;
sbit p37=P3^7;
sbit rst=P3^3;
sbit ale=P3^5;
sbit vpp=P3^4;
bit b_break;
unsigned int adds;
// 13.8mS
void int_t0(void) interrupt 1 {
TH0=-100;
b_break=1;
}
void wait(unsigned char w) {
unsigned int t=w*184;
b_break=0;
TL0=-t%256-1;TH0=-t/256;
while (b_break==0) {}
}
void nop(void) {
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
}
unsigned char command(void) {
TH0=-100;b_break=0;
while (RI==0) {if (b_break==1) return(0);}
RI=0;
return(SBUF);
}
void earsure(unsigned char cpu) {
switch (cpu) {
case 1: //89C51
case 2:rst=p26=1;p27=p36=p37=0;nop();vpp=1;nop();
ale=0;wait(110);ale=1;nop();
break;
case 3:
case 4:break;
case 5:
case 6:break;
}
}
void program(unsigned char cpu) {
unsigned int bdata adds=0;
unsigned char d;
switch (cpu) {
case 1: //89C51
case 2:
p36=p37=1;rst=1;
while (1) {
TH0=-100;b_break=0;
while (RI==0) {if (b_break==1) return;}
RI=0;
d=SBUF;
//address
P0=adds%256;
P2=adds/256;
p27=1;
//data
P1=d;
nop(); //48clcl
//vpp
vpp=1;
nop(); //48clcl
//ale
ale=0;
wait(1);//100uS
ale=1;
nop(); //10uS
vpp=0;
nop(); //48clcl
p27=0;
nop(); //48clcl
P1=0xff;
TH0=-100;b_break=0;
while (d!=P1) {if (b_break==1) return;} //data
polling
SBUF=d;
adds++;
}
break;
case 3:
case 4:
case 5:
case 6:break;
}
}
void lock(unsigned char cpu) {
unsigned char i;
switch (cpu) {
case 1: //89c51
case 2:
//lock 1
rst=p26=p36=p27=p37=1;nop();
vpp=1;
nop();
ale=0;
// for (i=0;i<6;i++) wait(100);
wait(1);
ale=1;
nop();
vpp=0;
nop();
//lock 2
rst=p26=p27=1;p36=p37=0;nop();
vpp=1;
nop();
ale=0;
// for (i=0;i<6;i++) wait(100);
wait(1);
ale=1;
nop();
vpp=0;
nop();
//lock 3
rst=p26=p36=1;p27=p37=0;nop();
vpp=1;
nop();
ale=0;
// for (i=0;i<6;i++) wait(100);
wait(1);
ale=1;
nop();
vpp=0;
nop();
break;
case 3:
case 4:
case 5:
case 6:break;
}
}
void main(void) {
unsigned char disp,flash,temp,cpu;
EA=1;
SCON=0xd8;PCON=0x80;
TMOD=0x21;
TL1=TH1=0xff;TR1=1;
TH0=-100;ET0=TR0=1;
flash=0x80;
while (1) {
temp=command();
switch (temp) {
case 0:
case 1: //89c51
case 2: //89C52
case 3: //80f51
case 4: //80F52
case 5: //87F51
case 6:cpu=temp;SBUF=temp;break;//87f52
case e:SBUF=temp;earsure(cpu);break; //erasure
case p:SBUF=temp;program(cpu);break; //program
case l:lock(cpu);SBUF=temp;break; //lock
default:SBUF=temp;break;
}
b_break=0;
if ((++disp)>flash) {disp=0;led=!led;}
}
}
//HT1380实时时钟驱动程序
sbit clock_dat=P0^1;
sbit clock_clk=P0^2;
sbit clock_rst=P0^3;
sbit a0=ACC^0;
sbit a1=ACC^1;
sbit a2=ACC^2;
sbit a3=ACC^3;
sbit a4=ACC^4;
sbit a5=ACC^5;
sbit a6=ACC^6;
sbit a7=ACC^7;
void clock_out(unsigned char dd) {
ACC=dd;
clock_dat=a0;clock_clk=1;clock_clk=0;
clock_dat=a1;clock_clk=1;clock_clk=0;
clock_dat=a2;clock_clk=1;clock_clk=0;
clock_dat=a3;clock_clk=1;clock_clk=0;
clock_dat=a4;clock_clk=1;clock_clk=0;
clock_dat=a5;clock_clk=1;clock_clk=0;
clock_dat=a6;clock_clk=1;clock_clk=0;
clock_dat=a7;clock_clk=1;clock_clk=0;
}
unsigned char clock_in(void) {
clock_dat=1;
a0=clock_dat;
clock_clk=1;clock_clk=0;a1=clock_dat;
clock_clk=1;clock_clk=0;a2=clock_dat;
clock_clk=1;clock_clk=0;a3=clock_dat;
clock_clk=1;clock_clk=0;a4=clock_dat;
clock_clk=1;clock_clk=0;a5=clock_dat;
clock_clk=1;clock_clk=0;a6=clock_dat;
clock_clk=1;clock_clk=0;a7=clock_dat;
return(ACC);
}
unsigned char read_clock(unsigned char ord) {
unsigned char dd=0;
clock_clk=0;
clock_rst=0;
clock_rst=1;
clock_out(ord);
dd=clock_in();
clock_rst=0;
clock_clk=1;
return(dd);
}
void write_clock(unsigned char ord,unsigned char dd) {
clock_clk=0;
clock_rst=0;
clock_rst=1;
Previous article:Design of single chip microcomputer in solar street light controller
Next article:Multisim MCU Co-simulation
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Last week: 100 sets of Pingtouge RISC-V development boards, invite you to play ~ Come quickly ~ Share with friends and win red envelopes
- HP laser printer original toner cartridges are useless if you don't open them after using them up.
- Problems caused by macros that IAR cannot find defaulting to 0
- help
- FPGA technology introduction and FPGA application fields
- Learn MSP430F5529 programming routines
- Diode as a temperature compensation circuit for transistors
- TL431 as a voltage regulator
- Is the product on Taobao claiming to be an energy saver genuine?
- How to deal with this?