leaveme
Newbie
- Joined
- Oct 28, 2010
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,306
Hi,
I'm experimenting a project using PIC to fire the TRIAC. But I do not really understand to setup the TIMER interrupt. I'm using CCS C.
Any help will be appreciated.
I'm experimenting a project using PIC to fire the TRIAC. But I do not really understand to setup the TIMER interrupt. I'm using CCS C.
Any help will be appreciated.
Code:
//Compiler: CCS C - v4.14
#include <16F886.h>
#fuses HS
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin NOT enabled
#FUSES BROWNOUT //Reset when brownout detected
#use delay(clock=20M)
#define DIM_LEVEL 65535
int1 ZC=FALSE;
#INT_EXT //External Interrupt
void EXT_isr(void)
{
output_low(PIN_C0); //make sure gate is OFF
set_timer0(DIM_LEVEL); //preload_time into Timer0
enable_interrupts(INT_TIMER0); //start Timer0
ZC = TRUE;
}
#int_TIMER0
void TIMER0_isr(void)
{
if (ZC) //execute if zero crossing occures
{
set_timer0(0); //stop Timer0
output_high(PIN_C0); //turn the gate ON
delay_uS(100);
output_low(PIN_C0); //turn the gate OFF
clear_interrupt(INT_TIMER0); //clear Timer0
ZC = FALSE;
}
}
void main( void ) {
//drive all pins low, except B0, set as input
output_b(0);
output_c(0);
output_float(PIN_B0);
setup_timer_0( T0_INTERNAL | T0_DIV_1 );
//ext_int_edge(H_TO_L); //set the falling edge to trigger on the ZC signal
ext_int_edge(L_TO_H); //set the rising edge to trigger on the ZC signal
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while (1);
}
Attachments
Last edited: