#i nclude
#i nclude
#i nclude
#i nclude
#i nclude
#pragma NOAREGS
//STC ISP_V2.0 PCB The crystal oscillator is 18.432MHz
#define WdtTime_71_1mS 0x30 //71.1mS
#define WdtTime_141_2mS 0x31 //141.2mS
#define WdtTime_284_4mS 0x32 //284.4mS
#define WdtTime_568_8mS 0x33 //568.8mS
# define WdtTime_1_1377S 0x34 //1.1377S
#define WdtTime_2_755S 0x35 //2.755S
#define T2_5mS -1536*5//5ms 18.432MHz
sfr AUXR = 0x8e;
sfr WDTRST = 0xa6;
sfr16 TIMEER2 = 0xcc;
sfr16 RCAP = 0xca;
sfr WDT_CONTR = 0x0e1;
//Global variable definition
typedef struct Systemstruct {//System data structure
unsigned char TimeCount;
unsigned int RamTest;
unsigned char SioTxCount;
unsigned char SioTxSum;
unsigned char SioRxCount;
unsigned char SioTxBuff[32];
// unsigned char SioRxBuff[32];
}SystemData;
data SystemData SystemBuffers;/ /Apply for system data structure
void MainInit(void); //System initialization
void SystemInit(void);//System initialization
void SystemSetup(void);//System settings
void SystemIoInit(void);//System interface initialization
void TimeInit(void);//Timer timing parameter settings
void UserSetup(void);/ /User operating environment settings
void ClrWdt(void); //Feed the dog
void IoPinTest(void);
unsigned char Port0Test(void);
unsigned char Port1Test(void);
unsigned char Port2Test(void);
unsigned char Port3Test(void);
void main(void)
{
MainInit(); //System initialization
while (1) { //Main loop
IE |= 0xb2; //Ensure reliable interrupt EA, ET2, ES, ET0
TCON |= 0x55; //Ensure timer is on
PCON |= SMOD_ + GF0_ + IDL_; //Enter idle state and feed the dongle_nop_
();
_nop_();
}
}
void MainInit(void) using 0 //System initialization
{
ClrWdt(); //Clear watchdog counter
SystemIoInit(); //System interface initialization
SystemInit(); //System power-on initialization
SystemSetup( );//System operating environment settings
UserSetup();//User operating environment settings
}
void SystemInit(void) using 0//System initialization
{
if (SystemBuffers.RamTest != 0x55aa) {//Memory initialization
SystemBuffers.RamTest = 0x55aa ;
}
else {
}
}
void SystemSetup(void) using 0//System settings
{
TimeInit();
}
void SystemIoInit(void) using 0
{
IE = 0x00;//Disable interrupt
P2 = 0xff;//Initialize P2 port
P0 = 0xff; //P0 port initialization
P1 = 0xff; //P1 port initialization
P3 = 0xff; //P3 port initialization
}
void TimeInit() using 0
{
// TCON = 0x55; //Start timer
TL0 = 0;
TH0 = 0;
TR0 = 1; //Start timer 0
TMOD = 0x20;
TH1 = 0xfb; //Fosc=18.432MHz th1=tl1=0xfb bps=9600
TL1 = TH1;
SCON = 0x58;
PCON = 0x80; //2*bps=9600*2=19200
TR1 = 1; //Start timer 1
TIMEER2 = T2_5mS;
RCAP = T2_5mS;
TR2 = 1; //Start timer 2
}
void UserSetup(void) using 0 //User operating environment settings
{
SystemBuffers.SioTxCount = 0;
}
void ClrWdt(void) using 0 //Feed the dog
{
WDT_CONTR = WdtTime_1_1377S; //1.1377S feeds the dog
}
unsigned char Port0Test(void)
{
unsigned char testval;
P0 = 0x55; //Odd pin sends low level
_nop_(); //Delay
testval = P0 ^ 0x55; //Compare the sending and receiving results
P0 = 0xaa; //Even pin sends low level
_nop_(); //Delay
testval |= P0 ^ 0xaa; //Compare the sending and receiving results (2 times)
P0 = 0xff; //Release P0 port to prevent external power supply
return testval; //Test successful returns 0
}
unsigned char Port1Test(void)
{
unsigned char testval;
P1 = 0x55;//Odd pin sends low
level_nop_();//Delay
testval = P1 ^ 0x55;//Compare the sending and receiving results
P1 = 0xaa;//Even pin sends low
level_nop_();//Delay
testval |= P1 ^ 0xaa;//Compare the sending and receiving results (2 times)
P1 = 0xff;//Release P1 port to prevent external power supply
return testval;//Test successful returns 0
}
unsigned char Port2Test(void)
{
unsigned char testval;
P2 = 0x55;//Odd pin sends low
level_nop_();//Delay
testval = P2 ^ 0x55;//Compare the sending and receiving results
P2 = 0xaa;//Even pin sends low
level_nop_();//Delay
testval |= P1 ^ 0xaa;//Compare the results of sending and receiving (2 times)
P2 = 0xff;//Release P2 port to prevent external power supply
return testval;//Test successfully returns 0
}
unsigned char Port3Test(void)
{
unsigned char testval;
P3 = 0x55;//Odd pin sends low level
_nop_();//Delay
testval = P3 ^ 0x55;//Compare the results of sending and receiving
P3 = 0xaa;//Even pin sends low level
_nop_();//Delay
testval |= P3 ^ 0xaa;//Compare the results of sending and receiving (2 times)
P3 = 0xff;//Release P1 port to prevent external power supply
return testval;//Test successfully returns 0
}
void IoPinTest(void)
{
unsigned char i, err = 0, pin = 0;
// if (pin = Port0Test()) err = 1;//If P0 port is pulled up, this line can be opened
if (pin = Port1Test()) err = 2;
if (pin = Port2Test()) err = 3;
if (pin = Port3Test()) err = 4;
if (err) {
if ((TI == 0) && (SystemBuffers.SioTxCount == 0)) {
for (i = 0; i < 8; i++) {
if (pin & 1) break;
pin >>= 1;
}
strcpy(SystemBuffers.SioTxBuff, "P0_0 is Bad!!! ");
SystemBuffers.SioTxBuff[1] += err - 1;
SystemBuffers.SioTxBuff[3] += pin;
SystemBuffers.SioTxCount = strlen(SystemBuffers.SioTxBuff);
SystemBuffers.SioTxSum = SystemBuffers.SioTxCount;
TI = 1;
}
}
}
void t0proc() interrupt TF0_VECTOR using 1
{
}
void t1proc() interrupt TF1_VECTOR using 1
{
}
void t2proc() interrupt TF2_VECTOR using 0
{
TF2 = 0;
if (PCON & GF0_) {//The interrupt must be entered from the main loop to feed the dog
ClrWdt();//Clear the watchdog counter
PCON &= ~GF0_;//Clear the flag
}
IoPinTest();
}
void sioproc() interrupt SIO_VECTOR using 1
{
//unsigned char i;
if (RI) {//Receive interrupt
RI = 0;
}
if (TI) {//Send interrupt
TI = 0;
if (SystemBuffers.SioTxCount) {//Allow serial port to send data
SBUF = SystemBuffers.SioTxBuff[SystemBuffers.SioTxSum - SystemBuffers.SioTxCount];//Serial port displays
SystemBuffers.SioTxCount --;
}
}
}
void int0proc() interrupt IE0_VECTOR using 0
{
}
void int1proc() interrupt IE1_VECTOR using 0
{
}
Reference address:STC MCU IO pin damage dynamic self-test program
#i nclude
#i nclude
#i nclude
#i nclude
#pragma NOAREGS
//STC ISP_V2.0 PCB The crystal oscillator is 18.432MHz
#define WdtTime_71_1mS
#define WdtTime_141_2mS
#define WdtTime_284_4mS
#define WdtTime_568_8mS
# define WdtTime_1_1377S
#define WdtTime_2_755S
#define T2_5mS -1536*5//5ms 18.432MHz
sfr
sfr
sfr16 TIMEER2
sfr16 RCAP
sfr
//Global variable definition
typedef struct Systemstruct {//System data structure
//
}SystemData;
data SystemData SystemBuffers;/ /Apply for system data structure
void MainInit(void); //System initialization
void SystemInit(void);//System initialization
void SystemSetup(void);//System settings
void SystemIoInit(void);//System interface initialization
void TimeInit(void);//Timer timing parameter settings
void UserSetup(void);/ /User operating environment settings
void ClrWdt(void); //Feed the dog
void IoPinTest(void);
unsigned char Port0Test(void);
unsigned char Port1Test(void);
unsigned char Port2Test(void);
unsigned char Port3Test(void);
void main(void)
{
}
void MainInit(void) using 0 //System initialization
{
}
void SystemInit(void) using 0//System initialization
{
}
void SystemSetup(void) using 0//System settings
{
}
void SystemIoInit(void) using 0
{
}
void TimeInit() using 0
{
//
}
void UserSetup(void) using 0 //User operating environment settings
{
}
void ClrWdt(void)
{
}
unsigned char Port0Test(void)
{
unsigned char testval;
}
unsigned char Port1Test(void)
{
unsigned char testval;
}
unsigned char Port2Test(void)
{
unsigned char testval;
}
unsigned char Port3Test(void)
{
unsigned char testval;
}
void IoPinTest(void)
{
unsigned char i, err = 0, pin = 0;
//
}
void t0proc() interrupt TF0_VECTOR using 1
{
}
void t1proc() interrupt TF1_VECTOR using 1
{
}
void t2proc() interrupt TF2_VECTOR using 0
{
}
void sioproc() interrupt SIO_VECTOR using 1
{
//unsigned char i;
}
void int0proc() interrupt IE0_VECTOR using 0
{
}
void int1proc() interrupt IE1_VECTOR using 0
{
}
Previous article:STC MCU internal FLASH reading and writing program
Next article:MCU Learning: Introduction to MCU Programming 19
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- 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)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Can the highest main frequency of DSP be obtained from the chip model?
- Qualcomm launches next-generation cellular chipsets designed for the Internet of Things
- The ultimate PCB material for entry-level nanny
- After the zstack coordinator is powered off and restarted, the node cannot access the network?
- High-performance lossless data decompression IP based on LZO
- Newcomer Report
- Benefits of IoT
- Application suggestions for 2.1GHz and 3.5GHz frequency bands in 5G networks
- 【NUCLEO-WL55JC2 Review】Summary
- Flathead RVB2601 LED light