};
struct TIMER_STRUCT
{
unsigned int Interval;
unsigned char Enable;
};
struct TIMER_STRUCT Timer1S;
struct CAPTURE_STRUCT
{
unsigned char Flag;
unsigned char Pointer;
unsigned int LowData;
unsigned char HighData;
};
struct CAPTURE_STRUCT MyTMR1;
unsigned char High_TMR1;
struct LED_STRUCT
{
unsigned char DotPointer;
unsigned char ScanPointer;
unsigned char Buffer[8];
};
struct LED_STRUCT NumberLED;
void PIC18F_High_isr (void);
void PIC18F_Low_isr (void);
#pragma code high_vector_section=0x8
void high_vector (void)
{
_asm goto PIC18F_High_isr _endasm
}
#pragma code low_vector_section=0x18
void low_vector (void)
{
_asm goto PIC18F_Low_isr _endasm
}
#pragma code
//---中断高优先级---//
#pragma interrupt PIC18F_High_isr
void PIC18F_High_isr (void)
{
if(TRUE==PIR1bits.TMR1IF)
{
PIR1bits.TMR1IF=FALSE;
High_TMR1++;
}
if(TRUE==PIR1bits.CCP1IF)
{
PIR1bits.CCP1IF=FALSE;
if(FALSE==MyTMR1.Flag)
{
if(0==MyTMR1.Pointer)
{
MyTMR1.Pointer++;
TMR1L=0;
TMR1H=0;
High_TMR1=0;
T1CONbits.TMR1ON=TRUE;
}
else
{
MyTMR1.Pointer=0;
T1CONbits.TMR1ON=FALSE;
MyTMR1.LowData=CCPR1H;
MyTMR1.LowData《《=8;
MyTMR1.LowData|=CCPR1L;
MyTMR1.HighData=High_TMR1;
MyTMR1.Flag=TRUE;
}
}
}
}
//---中断低优先级---//
#pragma interruptlow PIC18F_Low_isr
void PIC18F_Low_isr (void)
{
if(TRUE==PIR2bits.TMR3IF)
{
PIR2bits.TMR3IF=FALSE;
TMR3H=(65536-11962)/256;
TMR3L=(65536-11962)%256;
if(FALSE==Timer1S.Enable)
{
Timer1S.Interval++;
if(250==Timer1S.Interval)
{
Timer1S.Interval=0;
Timer1S.Enable=TRUE;
}
}
if(LOW==LATAbits.LATA0)LATAbits.LATA0=HIGH;
else LATAbits.LATA0=LOW;
LATD=LEDDATA[NumberLED.Buffer[NumberLED.ScanPointer]];
if(NumberLED.ScanPointer==NumberLED.DotPointer)LATD|=0x80;
LATE=NumberLED.ScanPointer;
NumberLED.ScanPointer++;
if(NumberLED.ScanPointer==sizeof(NumberLED.Buffer))
NumberLED.ScanPointer=0;
}
}
void main(void)
{
unsigned char i;
unsigned long temp;
float calctemp;
for(i=0;i NumberLED.ScanPointer=0;
NumberLED.DotPointer=0;
MyTMR1.Pointer=0;
MyTMR1.Flag=FALSE;
MyTMR1.HighData=0;
MyTMR1.LowData=0;
High_TMR1=0;
Timer1S.Interval=0;
Timer1S.Enable=FALSE;
TRISAbits.TRISA0=0;
LATAbits.LATA0=0;
TRISD=0;
LATD=0;
TRISE=0;
LATE=0;
TRISCbits.TRISC0=0;
LATCbits.LATC0=1;