标签:解决 响应时间 结束 c51 先后 int second 标识 控制
SETB IT1 SETB EX1 SETB PX1 ;设定外部中断1为高级中断 SETB EA
IT1 = 1; EX1 = 1; PX1 = 1; EA = 1;
MOV TMOD, #00000001B MOV TH0, #0ECH MOV TL0, #78H SETB ET0 SETB TR0 SETB EA
TMOD = 0x01; TH0 = 0xEC; TL0 = 0x78; ET0 = 1; TR0 = 1; EA = 1;
ORG 0000H LJMP MAIN ORG 0100H MAIN: MOV IP, #014H ; PS:PT1:PX1:PT0:PX0 = 10100(INT1高级中断,串口高级中断) SETB IT1 ;外部中断下降沿触发 SETB EX1 ;允许外部中断1 SETB ET1 ;允许定时器中断1 SETB ES ;打开串口中断 SETB EA END ;写汇编程序千万不要忘记写END
int main() { IP = 0x14; IT1 = 1; EX1 = 1; ET1 = 1; ES = 1; EA = 1; return 0; }
解:方式0:2^13 - (6*10^6 * 10 *10^-3 )/12 = 3192 -> TH0(063H) TL0(018H)(注意TH0放高8位,TL0放低5位)。方式1:2^16 - (6*10^6 * 10 *10^-3 )/12 = 60536 -> TH0(0ECH) TL0(078H)方式2:2^8 - (6*10^6 * 10 *10^-3 )/12 < 0 (溢出不能设置)
ORG 0000H LJMP MAIN ORG 000BH LJMP EVENT_OCCUR ORG 0100H MAIN: MOV R0, #00H ;设定队列初值0 MOV P1, #01H MOV TMOD, #00000001B MOV TH0, #0ECH MOV TL0, #78H SETB ET0 SETB TR0 SETB EA AJMP $ EVENT_OCCUR: CLR EA PUSH ACC ;保护现场,虽然在这一题没必要 INC R0 CJNE R0, #100, NEXT_EVENT RL A MOV P1, A MOV R0, #00H NEXT_EVENT: MOV TH0, #0ECH ;一定要记得重设初值 MOV TL0, #78H POP ACC ;恢复现场 RETI END
_CODE_SEGMENT: ORG 0000H LJMP START ORG 000BH LJMP BUTTON_HASED_PUSHED ORG 001BH LJMP EVENTLOOP_OCCUR ORG 0100H START: ;crystal oscillator frequency is 12MHZ ;Register 0 is uesd to log the number pushing actions MOV R0,#00H ;register 1 is uesd to log the microsecond event times MOV R1,#00H MOV TH0,#0FFH MOV TL0,#0FFH MOV TH1,#0D8H MOV TL1,#0F0H MOV TMOD,#00010101B ;we must make time interrupt 1 is the advance interrupt MOV IP,#02H SETB ET0 SETB TR0 SETB ET1 SETB TR1 SETB EA LCALL DISPLAY_DIGITAL_NUM AJMP $ BUTTON_HASED_PUSHED: INC R0 UPDATE_DIGITL_NUM: LCALL DISPLAY_DIGITAL_NUM MOV TH0,#0FFH MOV TL0,#0FFH RETI EVENTLOOP_OCCUR: PUSH ACC INC R1 CJNE R1,#200,NEXT_EVENT MOV R0,#00H LCALL DISPLAY_DIGITAL_NUM MOV R1,#00H NEXT_EVENT: MOV TH1,#0D8H MOV TL1,#0F0H POP ACC RETI DISPLAY_DIGITAL_NUM: CLR EA PUSH ACC MOV A, R0 MOV DPTR, #DIGITAL_NUM MOVC A, @A + DPTR MOV P2, A POP ACC SETB EA RET _DATA_SEGMENT: DIGITAL_NUM: DB 0C0H, 0F9H, 0A4H,0B0H,99H,92H,82H,0F8H,00H,90H DB 88H, 83H, 0C6H, 0A1H, 86H, 8EH END
#include<reg51.h> #define FinalOuccr 200 unsigned char const digitalNumsSet[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x00, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E}; enum StarterTime{ TH0_Start = 0xFF, TL0_Start = 0xFF, TH1_Start = 0xD8, TL1_Start = 0xF0}; //----------------------------------------------------- void updateDigitalNumber(unsigned char const digitalNum); static int eventOccurTimes = 0, BtnPushedTimes = 0; void ButtonPushed()interrupt 1 using 0//中断1(定时器0中断),使用寄存器组0 { BtnPushedTimes++; updateDigitalNumber(digitalNumsSet[BtnPushedTimes]); TH0 = TH0_Start; TL0 = TL0_Start; } void EventOccur()interrupt 3 using 1//中断3(定时器1中断),使用寄存器组1 { eventOccurTimes++; if(eventOccurTimes == FinalOuccr) { BtnPushedTimes = 0; updateDigitalNumber(digitalNumsSet[BtnPushedTimes]); eventOccurTimes = 0; } TH1 = TH1_Start; TL1 = TL1_Start; } int main() { TH0 = TH0_Start; TL0 = TL0_Start; TH1 = TH1_Start; TL1 = TL1_Start; TMOD = 0x15; TCON = 0x50; IP = 0X02; ET0 = 1; ET1 = 1; EA = 1; while(1); return 0; } void updateDigitalNumber(unsigned char const digitalNum) { P2 = digitalNum; }
标签:解决 响应时间 结束 c51 先后 int second 标识 控制
原文地址:http://www.cnblogs.com/Philip-Tell-Truth/p/6264735.html