Mấy cao thủ nào đã làm với con STC chỉ e với.
#include<reg51.h>
#include<intrins.h>
sfr ISP_CONTR = 0xE7;
sbit MCU_Start_Led = P1^7;
//unsigned char self_command_array[4] = {0x22,0x33,0x44,0x55};
#define Self_Define_ISP_Download_Command 0x22
#define RELOAD_COUNT 0xfb //18.432MHz,12T,SMOD=0,9600bps
void serial_port_initial();
void send_UART(unsigned char);
void UART_Interrupt_Receive(void);
void soft_reset_to_ISP_Monitor(void);
void delay(void);
void display_MCU_Start_Led(void);
void main(void)
{
unsigned char i = 0;
unsigned char j = 0;
unsigned char idata *idata_point;
serial_port_initial(); //initialize serial port
// display_MCU_Start_Led(); //MCU begin to run when LED is be lighted
// send_UART(0x34);
// send_UART(0xa7);
idata_point = 0xF1;
for(j=0;j<=6; j++)
{
i = *idata_point;
send_UART(i);
idata_point++;
}
while(1);
}
void serial_port_initial()
{
SCON = 0x50; //0101,0000 8-bit variable baud rate,No parity
TMOD = 0x21; //0011,0001 Timer1 as 8-bit auto-reload Timer
TH1 = RELOAD_COUNT; //Set the auto-reload parameter
TL1 = RELOAD_COUNT;
TR1 = 1;
ES = 1;
EA = 1;
}
void send_UART(unsigned char i)
{
ES = 0;
TI = 0;
SBUF = i;
while(TI ==0);
TI = 0;
ES = 1;
}
void UART_Interrupt_Receive(void) interrupt 4
{
unsigned char k = 0;
if(RI==1)
{
RI = 0;
k = SBUF;
STC MCU Limited.
if(k==Self_Define_ISP_Download_Command) //Self-define download command
{
delay(); //just delay 1 second
delay();
soft_reset_to_ISP_Monitor(); //Soft rese to ISP Monitor
}
send_UART(k);
}
else
{
TI = 0;
}
}
void soft_reset_to_ISP_Monitor(void)
{
ISP_CONTR = 0x60; //0110,0000 Soft rese to ISP Monitor
}
void delay(void)
{
unsigned int j = 0;
unsigned int g = 0;
for(j=0;j<5;j++)
{
for(g=0;g<60000;g++)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
void display_MCU_Start_Led(void)
{
unsigned char i = 0;
for(i=0;i<3;i++)
{
MCU_Start_Led = 0;
delay();
MCU_Start_Led = 1;
delay();
MCU_Start_Led = 0;
}
}
#include<reg51.h>
#include<intrins.h>
sfr ISP_CONTR = 0xE7;
sbit MCU_Start_Led = P1^7;
//unsigned char self_command_array[4] = {0x22,0x33,0x44,0x55};
#define Self_Define_ISP_Download_Command 0x22
#define RELOAD_COUNT 0xfb //18.432MHz,12T,SMOD=0,9600bps
void serial_port_initial();
void send_UART(unsigned char);
void UART_Interrupt_Receive(void);
void soft_reset_to_ISP_Monitor(void);
void delay(void);
void display_MCU_Start_Led(void);
void main(void)
{
unsigned char i = 0;
unsigned char j = 0;
unsigned char idata *idata_point;
serial_port_initial(); //initialize serial port
// display_MCU_Start_Led(); //MCU begin to run when LED is be lighted
// send_UART(0x34);
// send_UART(0xa7);
idata_point = 0xF1;
for(j=0;j<=6; j++)
{
i = *idata_point;
send_UART(i);
idata_point++;
}
while(1);
}
void serial_port_initial()
{
SCON = 0x50; //0101,0000 8-bit variable baud rate,No parity
TMOD = 0x21; //0011,0001 Timer1 as 8-bit auto-reload Timer
TH1 = RELOAD_COUNT; //Set the auto-reload parameter
TL1 = RELOAD_COUNT;
TR1 = 1;
ES = 1;
EA = 1;
}
void send_UART(unsigned char i)
{
ES = 0;
TI = 0;
SBUF = i;
while(TI ==0);
TI = 0;
ES = 1;
}
void UART_Interrupt_Receive(void) interrupt 4
{
unsigned char k = 0;
if(RI==1)
{
RI = 0;
k = SBUF;
STC MCU Limited.
if(k==Self_Define_ISP_Download_Command) //Self-define download command
{
delay(); //just delay 1 second
delay();
soft_reset_to_ISP_Monitor(); //Soft rese to ISP Monitor
}
send_UART(k);
}
else
{
TI = 0;
}
}
void soft_reset_to_ISP_Monitor(void)
{
ISP_CONTR = 0x60; //0110,0000 Soft rese to ISP Monitor
}
void delay(void)
{
unsigned int j = 0;
unsigned int g = 0;
for(j=0;j<5;j++)
{
for(g=0;g<60000;g++)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
void display_MCU_Start_Led(void)
{
unsigned char i = 0;
for(i=0;i<3;i++)
{
MCU_Start_Led = 0;
delay();
MCU_Start_Led = 1;
delay();
MCU_Start_Led = 0;
}
}