Serial 3 Channel AC 230V SSR and Dimmer
/*
* Project name:
Serial 3 Channel AC 230V SSR and Dimmer
* Copyright
(c) Researchdesignlab.com
* Test configuration:
MCU: PIC16F877A
Dev.Board: PIC
Oscillator: 20.0 MHz
Software: mikroC PRO for PIC v 4.6
*/
sbit S1 at RB0_bit;
sbit S2 at RB1_bit;
sbit S3 at RB2_bit;
sbit S4 at RB3_bit;
sbit S5 at RB4_bit;
sbit S6 at RB5_bit;
void CONVERT_DISPLAY(unsigned int);
void main(){
unsigned char LOAD1=0,LOAD2=0,LOAD3=0;
Delay_ms(200);
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100);
while(1)
{
if(S1==0)
{
if(LOAD1<100)
LOAD1++;
UART1_Write('A');
CONVERT_DISPLAY(LOAD1);
Delay_ms(300);
}
if(S2==0)
{
if(LOAD1>0)
LOAD1--;
UART1_Write('A');
CONVERT_DISPLAY(LOAD1);
Delay_ms(300);
}
if(S3==0)
{
if(LOAD2<100)
LOAD2++;
UART1_Write('B');
CONVERT_DISPLAY(LOAD2);
Delay_ms(300);
}
if(S4==0)
{
if(LOAD2>0)
LOAD2--;
UART1_Write('B');
CONVERT_DISPLAY(LOAD2);
Delay_ms(300);
}
if(S5==0)
{
if(LOAD3<100)
LOAD3++;
UART1_Write('C');
CONVERT_DISPLAY(LOAD3);
Delay_ms(300);
}
if(S6==0)
{
if(LOAD3>0)
LOAD3--;
UART1_Write('C');
CONVERT_DISPLAY(LOAD3);
Delay_ms(300);
}
}
}
void CONVERT_DISPLAY(unsigned int d)
{
unsigned char dig1,dig2,dig3,dig[3];
unsigned char x;
unsigned char temp;
temp=d;
temp=temp/10;
dig1=d%10;
dig2=temp%10;
dig3=temp/10;
dig[0]=dig3;
dig[1]=dig2;
dig[2]=dig1;
for(x=0;x<3;x++)
{
temp=dig[x]|0x30;
UART1_Write(temp);
}
}