Jestin_cubetech
Advanced Member level 1
- - - Updated - - -
Code:
#include <pic.h> //triac light dimmer
#define _XTAL_FREQ 20000000
#define TRIAC1 RB3
#define UP RB7
#define DWN RB6
#define MAX_TIME 3500
#define MIN_TIME 1
int k=0,dly=0;
void interrupt isr()
{
/////////////////////////////////////
if(INTF)
{
INTF=0;
while(!RB0);
dly=k;
while(dly--);
TRIAC1=1;
#asm
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
#endasm
TRIAC1=0;
}
}
/////////////// MAIN //////////////////////
void main()
{
TRISD=0x0; TRISB=0xF1;
k=300;
INTE=1; INTEDG=1; PEIE=1;GIE=1;
while(1)
{
if(!UP)
{
__delay_ms(100);
if(!UP)
{
if(k>=MAX_TIME) k=MAX_TIME; k++;
dly=k;
}
}
else if(!DWN)
{
__delay_ms(100);
if(!DWN)
{
if(k<=MIN_TIME) k=MIN_TIME; k--;
dly=k;
}
}
}
}
/////////////////////////////////////////////////