拿新塘的范例用死机和无功能。
程序如下:
#include <stdio.h>
#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_Define.h"
sbit P15 = P1^5;
//sbit P14 = P1^4;
xdata long d=0;
//***************** The Following is in define in Fucntion_define.h ***************************
//****** Always include Function_define.h call the define you want, detail see main(void) *******
//***********************************************************************************************
#if 0
//#define TIMER0_MODE0_ENABLE TMOD&=0x0F
//#define TIMER0_MODE1_ENABLE TMOD&=0x0F;TMOD|=0x10
//#define TIMER0_MODE2_ENABLE TMOD&=0x0F;TMOD|=0x20
//#define TIMER0_MODE3_ENABLE TMOD&=0x0F;TMOD|=0x3F
//#define TIMER1_MODE0_ENABLE TMOD&=0xF0
//#define TIMER1_MODE1_ENABLE TMOD&=0xF0;TMOD|=0x01
//#define TIMER1_MODE2_ENABLE TMOD&=0xF0;TMOD|=0x02
//#define TIMER1_MODE3_ENABLE TMOD&=0xF0;TMOD|=0xF3
#endif
#define TH0_INIT 50000
#define TL0_INIT 50000
#define TH1_INIT 5000
#define TL1_INIT 5000
UINT8 u8TH0_Tmp,u8TL0_Tmp,u8TH1_Tmp,u8TL1_Tmp,aa,bb;
/************************************************************************************************************
* TIMER 0 interrupt subroutine
************************************************************************************************************/
void Timer0_ISR (void) interrupt 1 //interrupt address is 0x000B
{
TH0 = u8TH0_Tmp;
TL0 = u8TL0_Tmp;
// P15 = ~P15; // GPIO1 toggle when interrupt
}
/************************************************************************************************************
* TIMER 1 interrupt subroutine
************************************************************************************************************/
void Timer1_ISR (void) interrupt 3 //interrupt address is 0x001B
{
TH1 = u8TH1_Tmp;
TL1 = u8TL1_Tmp;
P13 = ~P13;
P15 = ~P15;
P03 = ~P03; //P0.3 toggle when interrupt
}
void Timer2_ISR (void) interrupt 5
{
clr_TF2; //Clear Timer2 Interrupt Flag
// P12 = ~P12; // GPIO1 toggle
}
void Capture_ISR (void) interrupt 12
{
clr_CAPF0; // clear capture0 interrupt flag
aa = C0L; // For capture mode CxL/CxH with data capture from I/O pin
bb = C0H; //得不到数字
P14 = ~P14; //toggle GPIO1 to show int
}
/************************************************************************************************************
* Main function
************************************************************************************************************/
void main (void)
{
Set_All_GPIO_Quasi_Mode;
TIMER0_MODE1_ENABLE;
TIMER1_MODE1_ENABLE;
TIMER2_Compare_Capture_Mode;
IC3_P00_CAP0_BothEdge_Capture; //还是下降沿为什么?
// set_ET2; //Enable Timer2 interrupt 加上它就死机
set_ECAP; //Enable Capture interrupt
set_TR2; //Triger Timer2
clr_T1M;
//set_T1M;
CKDIV=0;
CKCON=CKCON|0X18;
u8TH0_Tmp = (65536-TH0_INIT)/256;
u8TL0_Tmp = (65536-TL0_INIT)%256;
u8TH1_Tmp = (65536-TH1_INIT)/256;
u8TL1_Tmp = (65536-TL1_INIT)%256;
TH0 = u8TH0_Tmp;
TL0 = u8TL0_Tmp;
TH1 = u8TH1_Tmp;
TL1 = u8TL1_Tmp;
set_ET0; //enable Timer0 interrupt
set_ET1; //enable Timer1 interrupt
set_EA; //enable interrupts
set_TR0; //Timer0 run
set_TR1; //Timer1 run
while(1);
}
|