Software watchdog softdog.c

Publisher:温柔之风Latest update time:2017-11-29 Source: eefocusKeywords:softdog.c Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

汇编
ERRORP SEGMENT CODE
PUBLIC error
RSEG ERRORP
error:
CLR EA
MOV DPTR,#ERR1
PUSH DPL
PUSH DPH
RETI
ERR1:
CLR A
PUSH ACC
PUSH ACC
RETI
END

//The following program is just an example 

void error(void);

//Timer 0, clear the timing of timer 1
void int_t0(void) interrupt 1 {
TL0=TL0+68;TH0=0xfd; //700
TH1=0xfb;
}
//Timer 1, interrupt as watchdog
void int_t1(void) interrupt 3 {
error(); //reset
}

unsigned char adds;
unsigned char b_job0[5][3]; //Data used by job0, such as data collected by A/D, a total of 5 groups, 3 in each group, one of which is valid and the other 2 are spare
unsigned char b_job1[5][3];    
unsigned char b_job2[5][3];

void job0(void) {
unsigned char i;
adds=0;
for (i=0;i<5;i++) { //Data collection part, the process is simplified here
  b_job0[i][0]=b_job0[i][1]=b_job0[i][2]=123;
}
while (1) {}
}
void job1(void) {
unsigned char i;
adds=1;
for (i=0;i<5;i++) { //Data collection part, the process is simplified here
  b_job0[i][0]=b_job0[i][1]=b_job0[i][2]=23;
}
while (1) {}
}
void job2(void) {
unsigned char i;
adds=2;
for (i=0;i<5;i++) { //Data collection part, the process is simplified here
  b_job0[i][0]=b_job0[i][1]=b_job0[i][2]=12;
}
while (1) {}
}

//In order not to clear b_power when resetting, it must be connected with nostart.obj when connecting
void main(void) {
unsigned int b_power;
unsigned char b_test_ram,i,j;
TMOD=0x11;
TH0=0xfd;TH1=0xfb;
ET0=TR0=1;
ET1=TR1=1;
EA=1;
if (b_power!=0x1234) { //b_power is not equal to 0x1234, which means it has just been turned on
  b_power=0x1234;
  adds=0; //First execution of job0
} else { //Software reset handler, mainly continues to execute according to the address that generates the reset
      //RAM data error detection and recovery, 2 out of 3 equal method
  for (i=0;i<5;i++) {
  for (j=0;j<2;j++) {
   b_test_ram=job0[i][j];
   if (b_test_ram==job0[i][j+1]) break;
   b_test_ram=job0[i][j+1];
  }
  if (j==2) break;
  }
  if (i!=5) {}//Error in processing job0 data

  for (i=0;i<5;i++) {
  for (j=0;j<2;j++) {
   b_test_ram=job1[i][j];
   if (b_test_ram==job1[i][j+1]) break;
   b_test_ram=job1[i][j+1];
  }
  if (j==2) break;
  }
  if (i!=5) {}//处理job1数据出错

  for (i=0;i<5;i++) {
  for (j=0;j<2;j++) {
   b_test_ram=job2[i][j];
   if (b_test_ram==job2[i][j+1]) break;
   b_test_ram=job2[i][j+1];
  }
  if (j==2) break;
  }
  if (i!=5) {}//处理job2数据出错

  switch (adds) {
  case 0:job0();break;
  case 1:job1();break;
  case 2:job2();break;
  }
}
while (1) {}
}


Keywords:softdog.c Reference address:Software watchdog softdog.c

Previous article:Introduction to various burning file formats
Next article:Some basic concepts of stack

Latest Microcontroller Articles
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号