001/*****************************************
002 * Program for controlling 8 lights *
003 * by serial interface *
004 * (c) 2005 by Rtm-electronics *
005 *****************************************/
006//#include <math.h>
007//#include <stdio.h>
008//#include "i2c_ll.h" // Low-Level Routines
009#include "reg51.h"
010#include "irq52.h"
011#include "rc5.h"
012
013#pragma cpu51 -small //CPU has only internal RAM
014
015//P(out)=P(max)*((a-1/2*sin(a))/pi) where a is the ignition fase
016
017near char PWM_count [8];
018near char PWM_max [8]={200,200,200,200,200,200,200,200};
019
020code char PWM_KittScanner[15]={180,180,180,180,180,180,140,100,140,180,180,180,180,180,180};
021code char PWM_Wave[15]={170,140,110,100,110,140,170,180,170,140,110,100,110,140,170};
022
023near int Speed=100;
024near char Intensitie=1;
025near char t,t2;
026near char Command, Effect=255, Peek;
027
028unsigned char bit Direction=0;
029unsigned char bit FirstRun=0;
030
031IRQ_VECTOR(int0,IRQ_INT0)
032
033void int0 (void) interrupt //Tension zero-detect
034{
035 //Reset the counters
036 #asm
037 MOV TL0,TH0 //Reset timer 0 for the fase cutting.
038 MOV _PWM_count ,_PWM_max //This seems te be te fastest way to do the job lol...
039 MOV _PWM_count+1,_PWM_max+1 //Total 8*2+2+2+1=21 Cycles = 10.5 uS
040 MOV _PWM_count+2,_PWM_max+2
041 MOV _PWM_count+3,_PWM_max+3
042 MOV _PWM_count+4,_PWM_max+4
043 MOV _PWM_count+5,_PWM_max+5
044 MOV _PWM_count+6,_PWM_max+6
045 MOV _PWM_count+7,_PWM_max+7
046 //Turn gate current off (this happens before zero-crossing, so the triacs keep on conducting)
047 MOV P1,#255
048 #endasm