T0ISRcode SEGMENT CODE ;Segment for interrupt function
RSEG T0ISRcode ;Switch to this code segment
USING 1 ;Register bank for interrupt routine
; Tick the system counter[Tick5ms] in every 5ms
TF0_ISR: CLR TR0 ;Pause timer0
PUSH PSW
PUSH ACC
;MOV PSW,#08H ;Select register bank 1
;Reload timer0 offset for 5ms overflow rate. 0DC00H for
;1.8432MHz RC clock and 2800H for external 11.0592MHz.
MOV TL0,#(00H+18+2) ;Compensate for 10 ISR + 8 INTR cycles
MOV TH0,#0DCH
SETB TR0 ;Restart timer0
;INC Tick5ms+1
;MOV A, Tick5ms+1
;JNZ $+2+2
;INC Tick5ms+0
T0ISRcode SEGMENT CODE ;Segment for interrupt function
RSEG T0ISRcode ;Switch to this code segment
USING 1 ;Register bank for interrupt routine
; Tick the system counter[Tick5ms] in every 5ms
TF0_ISR: CLR TR0 ;Pause timer0
PUSH PSW
;MOV PSW,#08H ;Select register bank 1
;Reload timer0 offset for 5ms overflow rate. 0DC00H for
;1.8432MHz RC clock and 2800H for external 11.0592MHz.
MOV TL0,#(00H+18) ;Compensate for 10 ISR + 8 INTR cycles
MOV TH0,#0DCH
SETB TR0 ;Restart timer0
INC Tick5ms ;System tick by 5ms
; Produce a few reference time
DJNZ ref_100ms,ref_time_end;
MOV A,#20;
MOV ref_100ms,A
SETB flag_100ms;
DJNZ ref_1s,ref_time_end;
MOV A,#5;
MOV ref_500ms,A
SETB flag_500ms;
DJNZ ref_1s,ref_time_end
MOV A,#2;
MOV ref_1s,A;
SETB flag_1s;
ref_time_end:
nop;
POP PSW
RETI
但是这样的话就要浪费几个字节的内存,而且如果要改变时间间隔都要在中断函数里改,不知道有没有更好的办法!
#define uint unsigned int
#define uchar unsigned char
/*-------------------------------------------------------------*/
/****************Ports and variations dellarations**************/
/*-------------------------------------------------------------*/
sbit LED_PORT = P3^6;
uchar ADS1115_BUF[9];
uchar Tick5ms_Num;
uchar channel_1, channel_2, channel_3;
unsigned long temperature, windspeed, humidity;
float WS, RH, Pr, Te;
idata uchar Result1[17] = " C m/s";
idata uchar Result2[17] = " % hP";
bit k = 0;
extern bit flag_100ms;
extern bit flag_500ms;
extern bit flag_1s;
extern bit RS485LSTN;
extern bit RS485TALK;
extern bit RS485DGrecv(void);
extern bit RS485DGsend(void);
extern bit RS485CheckDG(void);
extern uchar RS485BUFidx;
extern void RS485ParseDG(uchar *);
//*************************************************************/
//*Function Name:RS484_Check(void)
//*Function :Do the RS485 task
//*Parameter :None
//*Return Value :None
//*************************************************************/
void RS484_Check(void)
{
if(RS485LSTN) //Client in LISTEN mode?
{
if(!RS485DGrecv()) //Receive one datagram
{
LED_PORT = !LED_PORT;
if(!RS485CheckDG()) //Check IDN and CKS...
{
if(k == 0) //Send the first datagram(Temperature & Wind speed)
{
k = 1;
RS485ParseDG(Result1); //Processing the datagram and prepare the firt 16 bytes data to response
RS485LSTN = 0; //Pause datagram listen
RS485TALK = 1; //Ready to send the response datagram
}
else //Send the second datagram(Humidity & Presure)
{
k = 0;
RS485ParseDG(Result2); //Processing the datagram and prepare the firt 16 bytes data to response
RS485LSTN = 0; //Pause datagram listen
RS485TALK = 1; //Ready to send the response datagram
}
}
RS485BUFidx = 0; //Reset datagram buffer
}
}
if(RS485TALK)
{
if(!RS485DGsend())
{
LED_PORT = !LED_PORT;
}
RS485LSTN = 1;
RS485TALK = 0;
}
}
//*************************************************************/
//*Function Name:void Time_Event(void)
//*Function :execute task of different time interval
//*Parameter :None
//*Return Value :None
//*************************************************************/
void Time_Event(void)
{
//Set CPU into IDLE mode when no task to do
//it will be woke up by interrupt every 5ms
/***********Task in each 5ms interval************/
PCON |= 0X01;
Get_Data();
RS484_Check();
/************************************************/
if(flag_500ms == 1)
{
/********Task in each 500ms interval*********/
flag_500ms = 0;
MS5607_calTP();
Data_Prepare();
// j++;
// if(j < 5)
// {
// Send2OLED(Result1);
// }
// else
// {
// Send2OLED(Result2);
// if(j == 10)
// j = 0;
/********************************************/
}
if(flag_1s == 1)
{
/*********Task in each 1s interval***********/
flag_1s = 0;
LED_PORT =! LED_PORT; //working station indicator
/********************************************/
}
}
//*************************************************************/
//*Function Name:void Delay_5ms(uint delay4msval)
//*Function :Delay 0~65536*5ms
//*Parameter :The number of 5ms
//*Return Value :None
//*************************************************************/
void Delay_5ms(uint delay4msval)
{
while(delay4msval)
{
PCON |= 0X01;
--delay4msval;
Time_Event();
}
}