Toll-Free Customer Support 24/7

Serial 8 Channel AC 230V SSR and Dimmer


/*
* Project name:
Serial 8 Channel AC 230V SSR and Dimmer
* Copyright
(c) Researchdesignlab.com
* Description:

* Test configuration:
MCU: AT89S52
Dev.Board: 8051
Oscillator: 11.0592 MHz
Software: Keil uVision3

*/

#include"reg51.h"
#include"string.h"
#define LCD_PORT P2
sbit rs=P3^5;
sbit en=P3^7;
sbit D7=P2^7;
sbit rw=P3^6;

sbit S1=P2^0;
sbit S2=P2^1;
sbit S3=P2^2;
sbit S4=P2^3;
sbit S5=P2^4;
sbit S6=P2^5;
sbit S7=P2^6;
unsigned char Channel=0,PER=0,ADD;
void busy();
void CMD_WRT(unsigned char);
void LCD_WRT(unsigned char *);
void DATA_WRT(unsigned char);
void DELAY();
void UART1_Write(unsigned char byte);
void CONVERT_DISPLAY1(unsigned int );
void CONVERT_DISPLAY(unsigned int );


void main() {

unsigned char CMD[]={0x38,0x0F,0x01,0x06,0x80},i,TEMP;

TMOD=0X20;
TH1=0XFD;
SCON=0X50;
TR1=1;
DELAY();
for(i=0;i<=4;i++)
{
TEMP=CMD[i];
CMD_WRT(TEMP);
}
DELAY();
CMD_WRT(0X01);
CMD_WRT(0X80);
LCD_WRT("-- 3 Dimmer--");
DELAY();
DELAY();
DELAY();
DELAY();
Channel=0;
while(1)
{
if(S1==0)
{
if(Channel<8)
Channel++;
ADD=Channel+64;
CMD_WRT(0XC0);
LCD_WRT("Ch= ");
DATA_WRT(ADD);
DELAY();
DELAY();
DELAY();
DELAY();
}
if(S2==0)
{
if(Channel>1)
Channel--;
ADD=Channel+64;
CMD_WRT(0XC0);
LCD_WRT("Ch= ");
DATA_WRT(ADD);
DELAY();
DELAY();
DELAY();
DELAY();
}

if(S3==0)
{
if(PER<100)
PER++;
CMD_WRT(0XC7);
LCD_WRT("Per= ");
CONVERT_DISPLAY(PER);
DELAY();
DELAY();
DELAY();
DELAY();
}
if(S4==0)
{
if(PER>0)
PER--;
CMD_WRT(0XC7);
LCD_WRT("Per= ");
CONVERT_DISPLAY(PER);
DELAY();
DELAY();
DELAY();
DELAY();
}

if(S5==0)
{
ADD=Channel+64;
UART1_Write(ADD);
CONVERT_DISPLAY1(PER);
DELAY();
DELAY();
DELAY();
DELAY();
}


if(S6==0)
{
UART1_Write('N');
CMD_WRT(0XC2);
LCD_WRT(" ALL ON 100% ");

DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
CMD_WRT(0X01);
CMD_WRT(0X80);
LCD_WRT("-- 3 Dimmer--");
}

if(S7==0)
{
UART1_Write('S');
CMD_WRT(0XC2);
LCD_WRT(" ALL OFF 0% ");

DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
DELAY();
CMD_WRT(0X01);
CMD_WRT(0X80);
LCD_WRT("-- 3 Dimmer--");
}

}

}

void busy()
{
D7=1;
rs=0;
rw=1;
while(D7!=0)
{
en=0;
en=1;
}
}

void CMD_WRT(unsigned char val)
{
busy();
LCD_PORT=val;
rs=0;
rw=0;
en=1;
en=0;
}

void LCD_WRT(unsigned char *string)
{
while(*string)
DATA_WRT(*string++);
}
void DATA_WRT(unsigned char ch)
{
busy();
LCD_PORT = ch;
rs=1;
rw=0;
en=1;
en=0;
}
void DELAY()
{
unsigned int X=60000000;
while(X--);
}

void UART1_Write(unsigned char byte)
{
SBUF=byte;
while(!TI);
TI=0;
}

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;

DATA_WRT(temp);
}


}

void CONVERT_DISPLAY1(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);
}


}

Back to top