hello all, I am working with AT89C51CC01 which based on 8051. I had write one program of external interrupt. See the code as follows.
void ex0_isr (void) interrupt 0 { CCAP1H = 0x5A; // 35% Duty Cycle } void main (void) { //Configure INT0 (external interrupt 0) to generate an interrupt on the falling-edge of /INT0 (P3.2). //Enable the EX0 interrupt and then enable the global interrupt flag. CMOD = 0x02; // Setup PCA timer CL = 0x00; CH = 0x00; CCAP1H = 0x10; // 75% Duty Cycle CCAPM1 = 0x42; // Setup PCA module 1 in PWM mode. IT0 = 1; // falling edge on /INT0 (P3.2) EX0 = 1; // Enable EX0 Interrupt EA = 1; // Enable Global Interrupt Flag CR = 1; // Start PCA Timer. while (1) { } }
In this code without interrupt Duty cycle of PWM signal is 75% and when interrupt occur then Duty cycle is 35%. This program works perfectly.
Is there possible to after interrupt then after some time program run normally (Same like without interrupt). For example i want after interrupt after 5 min i come again into the same program routin. Please give ur suggestion related to this problem.
Thanks in advance
Why have an external interrupt for a 5 min action? External interrupts are normally used for external events - not for timed events.
But if you really want to, you could draw a GPIO pin to your external interrupt signal, and have your program toggle the GPIO after 5 minutes. That is a very strange and complex way to force an external interrupt - and a quite silly way to design a system.
Isn't it _way_ better to skip the external interrupt handler and just have a timer interrupt? Let's say your timer interrupt ticks every 10ms, i.e. 100 times/second. So after 500 ticks, 5 seconds have passed. Then rewrite the contents of the PWM register - just copy the code line you now have in your external interrupt handler.
hello all, Thanks for ur reply.
I have one another task to do with External interrupt Just see the code
#include "reg_c51.h" unsigned char ex0_count = 0; unsigned char ex1_count = 0; void ex0(void) interrupt 0 { ex0_count++; // Increment the counter } void ex1(void) interrupt 2 { ex1_count++; // Increment the counter } void main (void) { IT0 = 1; // Configure interrupt 0 IT1 = 1; // Configure interrupt 1 EX0 = 1; // Enable EX0 Interrupt EX1 = 1; // Enable EX1 Interrupt EA = 1; // Enable Global Interrupt Flag CMOD = 0x02; // Setup PCA timer CL = 0x00; CH = 0x00; if (ex0_count > ex1_count) { CCAP1H = 0x5A; } // 35% Duty Cycle else if (ex0_count < ex1_count) { CCAP1H = 0x99; } // 60% Duty Cycle else { CCAP1H = 0x10; } // 75% Duty Cycle CCAPM1 = 0x42; // Setup PCA module 0 in PWM mode. CR = 1; // Start PCA Timer. while (1) {} } This program runs but gives only else part which is 75% of PWM. But i want to do like if first time external interrup occurs then both ex0_counter and ex1_counter start to increment..then when 2nd time interrupt occurs then stop the counter increment. So after 2nd interrupt i have fix value in both counters. In main i compare this counter values n generate PWM accourding to comparision. In interrupt function i just write counter increment but i want if first time interrupt occurs then counter start to increment and when 2nd time interrupt occurs then stop the counter incrementation. Can i give both situation for same interrupt..?? I don´t have any idea for this task. Please give me ur idea or suggestion for this question. Thanks in advance