📄 sendisp.c
字号:
#include<reg52.h>
#include<stdio.h>
#include <intrins.h>
#define READ_ISP 0x01
#define WRITE_ISP 0x02
#define ERASE_ISP 0x03
sfr isp_data = 0xe2;
sfr isp_addrh = 0xe3;
sfr isp_addrl = 0xe4;
sfr isp_cmd = 0xe5;
sfr isp_trig = 0xe6;
sfr isp_contr = 0xe7;
unsigned short address=0x2000;
unsigned char last = 0x00;
bit flag = 0;
void delay(unsigned short time)
{
unsigned char i,j,a;
unsigned short k;
for(k=0;k<time;k++)
for(i=0;i<8;i++)
for(j=0;j<91;j++)
{
a=a+2;
}
}
void serial(void) interrupt 4
{
unsigned char receive,high,low;
if(RI)
{
receive = SBUF;
high = address/256;
low = address%256;
isp_contr = 0x80; //依次为:(开机)年、月、日、时、分、秒、(关机)年、月、日、时、分、秒、0x2e
isp_cmd = WRITE_ISP;
isp_addrh = high;
isp_addrl = low;
isp_data = receive;
EA = 0;
isp_trig = 0x46;
isp_trig = 0xb9;
_nop_();
EA = 1;
isp_contr = 0x00;
isp_cmd = 0x00;
isp_trig = 0x00;
address++;
RI = 0;
if(receive==0x50) last++;
if(last==3) flag = 1;
SBUF =receive;
while(!TI);
TI = 0;
}
}
void main(void)
{
code unsigned char buf[3]="ISP"; //debug mode
unsigned char j,temp;
//unsigned short day,minute,bgday,bgminute,enday,endminute;
TMOD = 0x20; //串口初始化
TH1 = 0xf4;
TL1 = 0xf4;
PCON = 0x00;
TR1= 1;
SCON = 0x50;
EA = 1;
ES = 1;
//watch_dog = 0x37; //初始化看门狗,溢出时间为2.2755s
for(j=0;j<3;j++)
{
temp = buf[j];
SBUF = temp;
while(!TI);
TI = 0;
}
SBUF = '\n';
while(!TI);
TI = 0;
delay(1000);
while(!flag);
SBUF = 'K';
while(!TI);
TI = 0;
isp_contr = 0x60;
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -