Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[asking] LCD+ADC+TRIAC. help me to combine these programs please.

Status
Not open for further replies.

bagusdj

Member level 3
Member level 3
Joined
Nov 25, 2012
Messages
67
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,766
hey guys . im trying to make a simple program for phase angle control using triac. so far it is successfully decreasing the voltage delivered to load.
here is the code
Code:
#include<reg52.h>
 sbit triac=P3^0;
 void cct_init(void);
 void initint0(void);
 void firing(void);

void delay(unsigned int count)
{
unsigned int i;                         
    while(count) {
        i = 115;
                while(i>0) i--;
        count--;
}}

void cct_init(void)
 {
 P3=0x05;					 //triac is on when active low
 }


void initINT0(void)
 {
 IT0=1;
 EX0=1;
 EA=1;
 }

void firing(void)
{
if(value>10 & value>=20)	//1st condition
{triac=1;
delay(5);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(value>20 & value>=30)	//2nd condition
{triac=1;
delay(4);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(value>30 & value>=40)	//3rd condition
{triac=1;
delay(3);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(value>40 & value>=50)	//4th condition
{triac=1;
delay(2);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(value>50)		 //5th condition; full power
{triac=0;
EA=0;
EA=1;}
 else
{triac=1;			   //6th condition; triac not firing at all
EA=0;
EA=1;}
}
void external0_isr(void) interrupt 0
 {
firing(); 
 }
 
 void main(void)
 {
  cct_init();
  initINT0();
 }

for the code above, value is the reading of adc that written to lcd. i can not test this code yet since i dont know what the "value" should be. (for this moment i just name it value).

here is the code of ADC+LCD. can you guys help me,what should i replace "value" with?
Code:
// Program to interface TGS2600 using ADC 0809. The output of TGS2600 is displayed on LCD. Controller interrupt is used to generate the clock for driving ADC 0808.
#include<reg52.h>
sbit ale=P1^0;  //address latch enable
sbit oe=P1^3;  //output enable
sbit sc=P1^1;  //start conversion
sbit eoc=P1^2;  //end of conversion
sbit clk=P1^7;  // clock
sbit ADD_A=P1^4;  // Address pins for selecting input channels.
sbit ADD_B=P1^5;
sbit ADD_C=P1^6;
sfr lcd_data_pin=0xA0;  //P2 port
sbit rs=P3^7;
sbit rw=P3^1;
sbit en=P3^6;
sbit triac=P3^0;
sfr input_port=0x80;  //P0 port
unsigned int bitvalue,decimal_value,key,left_value,value,number,ascii1,ascii2,ascii3,flag,key1;

void timer0() interrupt 1  // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
{
clk=~clk;
}

void delay(unsigned int count)
{
unsigned int i;                         
    while(count) {
        i = 115;
                while(i>0) i--;
        count--;
}}

void lcd_command(unsigned char comm)  //Function to send command to LCD.
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(10);
en=0;
}

void lcd_data(unsigned char disp)  //Function to send data to LCD.
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(10);
en=0;
}


lcd_dataa(unsigned char *disp)  //Function to send string data to LCD.
{
int x;
for(x=0;disp[x]!=0;x++)
{
  lcd_data(disp[x]);
}
}

void lcd_ini()  //Function to inisialize the LCD
{
lcd_command(0x38); 
delay(5);
lcd_command(0x0E); 
delay(5);
lcd_command(0x80);  //Force cursor to blink at line 1 positon 0
delay(5);
}

   void BCD()  // Binary to decimal conversion to send the data to LCD
{
  key1++;
  key=0;
  flag=0;
    number=input_port;
    number= number*39;
    number= number/100;
    value=number%10;
number=number/10;
ascii1=value+48;
if(number!=0)
{
  value=number%10;
  number=number/10;
  ascii2=value+48;
    flag=1;
}
else
{
   ascii2=48;
   flag=1;
}
if(number!=0)
{
 value=number%10;
    number=number/10;
    ascii3=value+48;
    key=2;
}
else
{
  ascii3=48;
  key=2;
}
if(key==2)
lcd_data(ascii3);
if(flag==1)
lcd_data(ascii2);
lcd_data(ascii1);
if(key1==3)
{
key1=0;
ascii3=0;
ascii2=0;
ascii1=0;
delay(10);
} 
}

void adc()  //Function to drive ADC
{
while(1)
{
  ADD_C=0;  // Selecting input channel 2 using address lines
  ADD_B=0;
  ADD_A=1;
  delay(2);
  ale=1;
  delay(2);
  sc=1;
  delay(1);
  ale=0;
  delay(1);
  sc=0;
  while(eoc==1);
  while(eoc==0);
  oe=1;
  BCD();
  lcd_command(0x88);
  delay(2);
  oe=0;
}
}


void main()
{
eoc=1;
ale=0;
oe=0;
sc=0;
key1=0;
TMOD=0x02;  //timer0 setting for generating clock of 500KHz using interrupt enable mode.
TH0=0xFD;
IE=0x82;
TR0=1;
lcd_ini();

lcd_dataa("PPM : ");
lcd_command(0x88);

adc();

}
 

In your first code value is a integer/float variable and in the second code value is a string variable. What do you want to do?

Hi jay. Thanks for replying. Note that "value" in 1st program is not the same value as in 2nd program. What I need is, if the lcd shows 20 (the range is 0-99), then the triac is fired after 5mS. I don't know how to assign the value of sensor written on lcd to if function in 1st program.
 

You cannot assign value of sensor written on LCD that is string to if function. You can only use it if it is a integer/float variable. Depending on the value of variable value (in your situuation it is 20) you should select the timer.
 

You cannot assign value of sensor written on LCD that is string to if function. You can only use it if it is a integer/float variable. Depending on the value of variable value (in your situuation it is 20) you should select the timer.

how to do that? i dont get it
 

Code:
// Program to interface TGS2600 using ADC 0809. The output of TGS2600 is displayed on LCD. Controller interrupt is used to generate the clock for driving ADC 0808.
#include<reg52.h>
sbit ale=P1^0;  //address latch enable
sbit oe=P1^3;  //output enable
sbit sc=P1^1;  //start conversion
sbit eoc=P1^2;  //end of conversion
sbit clk=P1^7;  // clock
sbit ADD_A=P1^4;  // Address pins for selecting input channels.
sbit ADD_B=P1^5;
sbit ADD_C=P1^6;
sfr lcd_data_pin=0xA0;  //P2 port
sbit rs=P3^7;
sbit rw=P3^1;
sbit en=P3^6;
sbit triac=P3^0;
sfr input_port=0x80;  //P0 port
unsigned int bitvalue,decimal_value,key,left_value,value,number,ascii1,ascii2,ascii3,flag,key1;
void cct_init(void);
void initint0(void);
void firing(void);

void timer0() interrupt 1  // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
{
clk=~clk;
}

void delay(unsigned int count)
{
unsigned int i;                         
    while(count) {
        i = 115;
                while(i>0) i--;
        count--;
}}

void cct_init(void)
 {
 P3=0x05;					 //triac is on when active low
 }

void initINT0(void)
 {
 IT0=1;
 EX0=1;
 EA=1;
 }

void external0_isr(void) interrupt 0
 {
firing(); 
 }



void lcd_command(unsigned char comm)  //Function to send command to LCD.
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(10);
en=0;
}

void lcd_data(unsigned char disp)  //Function to send data to LCD.
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(10);
en=0;
}

lcd_dataa(unsigned char *disp)  //Function to send string data to LCD.
{
int x;
for(x=0;disp[x]!=0;x++)
{
  lcd_data(disp[x]);
}
}

void lcd_ini()  //Function to inisialize the LCD
{
lcd_command(0x38); 
delay(5);
lcd_command(0x0E); 
delay(5);
lcd_command(0x80);  //Force cursor to blink at line 1 positon 0
delay(5);
}

   void BCD()  // Binary to decimal conversion to send the data to LCD
{
  key1++;
  key=0;
  flag=0;
    number=input_port;
    number= number*39;
    number= number/100;
    value=number%10;
number=number/10;
ascii1=value+48;
if(number!=0)
{
  value=number%10;
  number=number/10;
  ascii2=value+48;
    flag=1;
}
else
{
   ascii2=48;
   flag=1;
}
if(number!=0)
{
 value=number%10;
    number=number/10;
    ascii3=value+48;
    key=2;
}
else
{
  ascii3=48;
  key=2;
}
if(key==2)
lcd_data(ascii3);
if(flag==1)
lcd_data(ascii2);
lcd_data(ascii1);
if(key1==3)
{
key1=0;
ascii3=0;
ascii2=0;
ascii1=0;
delay(10);
} 
}

[B]void firing(void)								   //conducted if interrupt occurs
{
if(input_port>10 & input_port<=20)	//1st condition
{triac=1;
delay(5);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(input_port>20 & input_port<=30)	//2nd condition
{triac=1;
delay(4);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(input_port>30 & input_port<=40)	//3rd condition
{triac=1;
delay(3);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(input_port>40 & input_port<=50)	//4th condition
{triac=1;
delay(2);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(input_port>50)		 //5th condition; full power
{triac=0;
EA=0;
EA=1;}
 else
{triac=1;			   //6th condition; triac not firing at all
EA=0;
EA=1;}
}[/B]

void adc()  //Function to drive ADC
{
while(1)
{
  ADD_C=0;  // Selecting input channel 2 using address lines
  ADD_B=0;
  ADD_A=1;
  delay(2);
  ale=1;
  delay(2);
  sc=1;
  delay(1);
  ale=0;
  delay(1);
  sc=0;
  while(eoc==1);
  while(eoc==0);
  oe=1;
  BCD();
  lcd_command(0x88);
  delay(2);
  oe=0;
}
}


void main()
{
cct_init();
initINT0();
eoc=1;
ale=0;
oe=0;
sc=0;
key1=0;
TMOD=0x02;  //timer0 setting for generating clock of 500KHz using interrupt enable mode.
TH0=0xFD;
IE=0x82;
TR0=1;
lcd_ini();

lcd_dataa("PPM : ");
lcd_command(0x88);
adc();
}

i tried this code, but it didnt work. if i press reset, smotimes the fan (load) completely off, and sometimes it is completely on. as i decrease the value of sensor reading (i used LDR for ease of simulation) the fan is not lowering its rpm. the part in bold is my concern. :(
 

Variable value contains only the one of the extracted digits of variable number which is your adc value. So you have to use number in if statements and depending upon that start a timer or use 5ms delay.
 

can u post the circuit.................

make me clear what u want to do..................

as you can see, there is folder about LCD+sensor+ADC. it simulates the reading of sensor and displays it on lcd. what i need is, i can set,let's say if sensor reads >10 & <=20, triac will be fired after 5mS delay. if sensor reads >20 & <=30, then the delay before triac fires is 4mS. if >30 & <=40, then 3mS delay. if >40 & <=50, then 2mS delay. if >50 then triac fires right away after zero cross (full power).

here is the code
Code:
// Program to interface TGS2600 using ADC 0809. The output of TGS2600 is displayed on LCD. Controller interrupt is used to generate the clock for driving ADC 0808.
#include<reg52.h>
sbit ale=P1^0;  //address latch enable
sbit oe=P1^3;  //output enable
sbit sc=P1^1;  //start conversion
sbit eoc=P1^2;  //end of conversion
sbit clk=P1^7;  // clock
sbit ADD_A=P1^4;  // Address pins for selecting input channels.
sbit ADD_B=P1^5;
sbit ADD_C=P1^6;
sfr lcd_data_pin=0xA0;  //P2 port
sbit rs=P3^7;
sbit rw=P3^1;
sbit en=P3^6;
sbit triac=P3^0;
sfr input_port=0x80;  //P0 port
unsigned int bitvalue,decimal_value,key,left_value,value,number,ascii1,ascii2,ascii3,flag,key1;
void cct_init(void);
void initint0(void);
void firing(void);

void timer0() interrupt 1  // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
{
clk=~clk;
}

void delay(unsigned int count)
{
unsigned int i;                         
    while(count) {
        i = 115;
                while(i>0) i--;
        count--;
}}

void cct_init(void)
 {
 P3=0x05;					 //triac is on when active low
 }

void initINT0(void)
 {
 IT0=1;
 EX0=1;
 EA=1;
 }

void external0_isr(void) interrupt 0
 {
firing(); 
 }



void lcd_command(unsigned char comm)  //Function to send command to LCD.
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(10);
en=0;
}

void lcd_data(unsigned char disp)  //Function to send data to LCD.
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(10);
en=0;
}

lcd_dataa(unsigned char *disp)  //Function to send string data to LCD.
{
int x;
for(x=0;disp[x]!=0;x++)
{
  lcd_data(disp[x]);
}
}

void lcd_ini()  //Function to inisialize the LCD
{
lcd_command(0x38); 
delay(5);
lcd_command(0x0E); 
delay(5);
lcd_command(0x80);  //Force cursor to blink at line 1 positon 0
delay(5);
}

   void BCD()  // Binary to decimal conversion to send the data to LCD
{
  key1++;
  key=0;
  flag=0;
    number=input_port;
    number= number*39;
    number= number/100;
    value=number%10;
number=number/10;
ascii1=value+48;
if(number!=0)
{
  value=number%10;
  number=number/10;
  ascii2=value+48;
    flag=1;
}
else
{
   ascii2=48;
   flag=1;
}
if(number!=0)
{
 value=number%10;
    number=number/10;
    ascii3=value+48;
    key=2;
}
else
{
  ascii3=48;
  key=2;
}
if(key==2)
lcd_data(ascii3);
if(flag==1)
lcd_data(ascii2);
lcd_data(ascii1);
if(key1==3)
{
key1=0;
ascii3=0;
ascii2=0;
ascii1=0;
delay(10);
} 
}

void firing(void)								   //conducted if interrupt occurs
{
if(input_port>10 & input_port<=20)	//1st condition
{triac=1;
delay(5);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(input_port>20 & input_port<=30)	//2nd condition
{triac=1;
delay(4);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(input_port>30 & input_port<=40)	//3rd condition
{triac=1;
delay(3);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(input_port>40 & input_port<=50)	//4th condition
{triac=1;
delay(2);
triac=0;
delay(1);
triac=1;
EA=0;
EA=1;}
 else if(input_port>50)		 //5th condition; full power
{triac=0;
EA=0;
EA=1;}
 else
{triac=1;			   //6th condition; triac not firing at all
EA=0;
EA=1;}
}

void adc()  //Function to drive ADC
{
while(1)
{
  ADD_C=0;  // Selecting input channel 2 using address lines
  ADD_B=0;
  ADD_A=1;
  delay(2);
  ale=1;
  delay(2);
  sc=1;
  delay(1);
  ale=0;
  delay(1);
  sc=0;
  while(eoc==1);
  while(eoc==0);
  oe=1;
  BCD();
  lcd_command(0x88);
  delay(2);
  oe=0;
}
}


void main()
{
cct_init();
initINT0();
eoc=1;
ale=0;
oe=0;
sc=0;
key1=0;
TMOD=0x02;  //timer0 setting for generating clock of 500KHz using interrupt enable mode.
TH0=0xFD;
IE=0x82;
TR0=1;
lcd_ini();

lcd_dataa("PPM : ");
lcd_command(0x88);
adc();
}
 

Attachments

  • Circuit.rar
    47.7 KB · Views: 67

Assign number to input_port.
already tried that in first place. not works also :(

post the circuit in a image file format ..........
adc.png
here you go sir
 

u are not all calling the below function...........

Code:
void firing(void)          //conducted if interrupt occurs
 

the function
Code:
void firing(void)

is not been called in any of the functions

i think i did it this way

Code:
void external0_isr(void) interrupt 0
 {
firing(); 
 }

if i assign 'number' instead of 'input_port', the hardware does nothing. if i use 'input_port', everytime i reset the mcu sometimes it does nothing,and sometimes the load runs with max voltage 220.
 
Last edited:

i think this may work...................
Code:
void adc()  //Function to drive ADC
{
while(1)
{
  ADD_C=0;  // Selecting input channel 2 using address lines
  ADD_B=0;
  ADD_A=1;
  delay(2);
  ale=1;
  delay(2);
  sc=1;
  delay(1);
  ale=0;
  delay(1);
  sc=0;
  while(eoc==1);
  while(eoc==0);
  oe=1;
  BCD();
  lcd_command(0x88);
  delay(2);
  oe=0;
  firing(); 
}
}

try this
 
i think this may work...................

try this

hi there. it works but not very good. when lcd displays <20, the Vrms is about <30V. the fan(load) spin very slow. once it pass 20, the fan goes all the way 210++V. not as intended in firing(). if i use number instead of input_port, load wont spin.

i need my device to detect sensor reading everytime interupt is conducted. at certain value, the triac fired after delayed for certain period, depends on the sensor reading range desired.

ex: if interrupt is conducted and the sensor reading is 34, so triac will be fired after being delayed 3mS. interrupt always occured every 10ms because the interrupt source is zero cross detector. by the next interrupt, it will check the sensor reading again.
 

Attachments

  • 1.gif
    1.gif
    126.8 KB · Views: 96
  • 2.gif
    2.gif
    132.8 KB · Views: 86

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top