0% found this document useful (0 votes)
101 views20 pages

File: D:/Automation/oz8/ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM

Uploaded by

Phan Truong Hai
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views20 pages

File: D:/Automation/oz8/ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM

Uploaded by

Phan Truong Hai
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

File: D:\Automation\oz8\ozonend.

c, Date: 7/28/2011, Time: 4:20:33 PM


/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date
: 7/18/2011
Author : NeVaDa
Company :
Comments:

Chip type
: ATmega8L
Program type
: Application
AVR Core Clock frequency: 8.000000 MHz
Memory model
: Small
External RAM size
: 0
Data Stack size
: 256
*****************************************************/
#include <mega8.h>
//#include <7d8.h>
#include <7dozon.h>
//#include <delay.h>
//#include <oz.h>
#include <code.h>
#include <sleep.h>
////////////////////
int tam,k1,k2,k3,n,i,j,f1,f2,p,s,p,h,d,ms,mp,mh,md,mm,b,t,t1,t2,t3,t4,t5,t6,t7,t8,t9,l,x1;
unsigned m;
int ff,f0,f3,f4,f5,f6,f7,f8,f9,f10,mssm,ss;
int k,a1,a2,a3,a4,f,y1;
unsigned m;
// External Interrupt 0 service routine
// eeprom int luu[]={0,0,0,0,0,0};
// External Interrupt 0 service routine
eeprom int luu[]={0,0,0,0,0,0};
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
if(PIND.2==0)
{
delay_ms(300);
if(PIND.2==0)
{
GICR|=0b00000000;
luu[3]=d;
luu[2]=h;
luu[1]=p;
}
}
}
// Timer1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
// Place your code here
// Place your code here
n++;
// if(n>999)
if(n>999)
{
f=1;
n=0;
s++;
k++;
k1++;
if(s>ms)
{
a4=1;
s=0;
p++;
k2++;
k3++;
if(p>mp)
{

- 1 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


p=0;
h++;
if(h>mh)
{
h=0;
d++;
if(d>md)
{
while(f==1)
{
if(PIND.3==0)
{f=0;
luu[0]=0;
luu[1]=0;
luu[2]=0;
luu[3]=0;
s=luu[0];
p=luu[1];
h=luu[2];
d=luu[3];
//ms=2;mp=3;mh=6;md=365;

}
else
{
PORTC.0=0;
PORTC.1=0;
PORTC.2=0;
PORTC.3=0;
PORTB.0=0;
PORTB.1=0;
PORTB.2=0;
PORTB.3=0;
PORTD.4=0;
PORTD.5=0;
PORTD.6=0;
PORTD.7=0;
delay_ms(1000);
PORTB.0=0;
PORTB.1=0;
PORTB.2=0;
PORTB.3=0;
PORTD.4=1;
PORTD.5=0;
PORTD.6=0;
PORTD.7=0;
delay_ms(1000);
PORTB.0=0;
PORTB.1=0;
PORTB.2=0;
PORTB.3=0;
PORTD.4=0;
PORTD.5=1;
PORTD.6=0;
PORTD.7=0;
delay_ms(1000);
s=61 ;
p=25;
h=36;
d=366;
}
}
}
}
}
}
}
}
#define ADC_VREF_TYPE 0x00
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);

- 2 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
m=0;
l=0;
f1=0;
y1=0;
k=k1=k3=0;
PORTD.0=1;
PORTD.1=1;
f=1;
n=0;
s=0;
p=luu[1];
h=luu[2];
d=luu[3];
// ms=59;mp=59;mh=23;md=364;
ms=59;mp=59;mh=23;md=364;
t=1;
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xCF;
// Port C initialization
// Func6=Out Func5=In Func4=In Func3=Out Func2=Out Func1=Out Func0=Out
// State6=0 State5=T State4=T State3=0 State2=0 State1=0 State0=0
PORTC=0x00;
DDRC=0b01001100;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0xF0;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: CTC top=OCR1A
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x0A;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x03;
OCR1AL=0xE8;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped

- 3 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: Off
GICR|=0x00;
MCUCR=0x00;
GIFR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x10;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AREF pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
if(k3==30)
{
luu[1]=p;
luu[2]=h;
luu[3]=d;
k3=0;
}

if(PINC.1==0)

{
delay_ms(5);
if(PINC.1==0)
{
read_adc(0)
{
tam=ADCW;
ngay(365-tam);
luu[3]=tam;
//luu[2]=0;
//h=0;
//luu[1]=0;
//p=0;
d=tam;
}
}

- 4 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


}
else
{
////////////////
if(PINC.5==0)
{
b=0; //0
phantram(50); //p50
///////////////
////////////////////
}
else
{
b=1;
phantram(100); //p=100
} ///////////////////////
gio(h);
phut(p);
giay(s);
ngay(365-d);

read_adc(4)

if((0<=ADCW)&&(ADCW<110))
{
f9=0;
t=t1=5;//1
fliplop(0,'a');//thay h=0
PORTD.0=1;
PORTD.1=1;
//////////////////////////
if(b==1)
//100%
{
if((0<k)&&(k<(t+1)))
{

//0

5 giay flip flop lien tuc

PORTC.2=1 ;
PORTC.3=1 ;
fliplop(0,'a');//thay h=0
}
if(((t+1)<k)&&(k<(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
fliplop(0,'a');//thay h=0
}
if(((2*t+1)<k)&&(k<(3*t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
fliplop(0,'a');//thay h=0
}
if((((3*t+1))<k)&&(k<(4*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
fliplop(0,'a');//thay h=0
}
if(k>((4*t+1)))
{k=0 ;
fliplop(0,'a');//thay h=0
}
}
else
//50%
{
if((0<k)&&(k<(t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
fliplop(0,'a');//thay h=0
}
if(((t+1)<k)&&(k<(2*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;

- 5 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


fliplop(0,'a');//thay h=0
}
if(k>(2*t+1))
{
k=0 ;
fliplop(0,'a');//thay h=0
}
}
////////////////////////////
}
if((110<=ADCW)&&(ADCW<220))
{
f2=0;
t=t3=300;
//3
PORTD.0=1;
PORTD.1=1;
x1=5;
if(b==1) //100%
{

//1

5 phut ff chay lien tuc

if((0<k)&&(k<=(t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((301-k),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=0 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((601-k),'f');
}
if(k>(2*t+1))
{
y1=0;
k=0 ;
}

}
else
{

//

50%

if((0<k)&&(k<=(t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((301-k),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((601-k),'f');
}
if(k>(2*t+1))
{
y1=0;
k=0 ;
}
}
}
if((220<=ADCW)&&(ADCW<330))
{

//2 5 phut ff chay 30 phut

f3=0;
x1=30;
if(f2==0)
{

// chi chay lan dau

- 6 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


y1=0;
t=t3=300;
//3
k1=k=k2=0;
ff=0;
f2=1;
}
else
{
if(ff==1)
{
PORTC.2=0 ;
PORTC.3=0 ;
}
else
{
if(b==1) //100%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if((((2*t+1))<k)&&(k<=(3*t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if((((3*t+1))<k)&&(k<=(4*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<x1+15))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=x1+15)
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
else

///50%

- 7 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
}
}
}
if((330<=ADCW)&&(ADCW<440))
{
f2=0;
f4=0;
x1=45;

//3 5phut ff chay 45p

if(f3==0)
// chi chay lan dau
{
y1=0;
t=t3=300;
//3
k1=k=k2=0;
ff=0;

- 8 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


f3=1;
}
else
{
if(ff==1)
{
PORTC.2=0 ;
PORTC.3=0 ;
}
else
{
if(b==1) //100%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
else
///50%
{
if(k2<=x1)

- 9 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
}
}
}
if((440<=ADCW)&&(ADCW<=550))
{
f3=0;
f5=0;
x1=60;

//4

5phut ff 60 phut chay

if(f4==0)
// chi chay lan dau
{
y1=0;
t=t3=300;
//3
k1=k=k2=0;
ff=0;
f4=1;
}
else

- 10 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


{
if(ff==1)
{
PORTC.2=0 ;
PORTC.3=0 ;
}
else
{
if(b==1) //100%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
else
///50%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;

- 11 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
}
}
}
if((550<=ADCW)&&(ADCW<=660))
{
f4=0;
f6=0;
x1=90;

//5 5 phut ff chay 90 phut

if(f5==0)
// chi chay lan dau
{
y1=0;
t=t3=300;
//3
k1=k=k2=0;
ff=0;
f5=1;
}
else
{
if(ff==1)
{

- 12 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


PORTC.2=0 ;
PORTC.3=0 ;
}
else
{
if(b==1) //100%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
else
///50%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;

- 13 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
}
}
}
if((770<=ADCW)&&(ADCW<=880))
{
f5=0;
f7=0;
x1=120;

//6

5phut ff chay 120 phut

if(f6==0)
// chi chay lan dau
{
y1=0;
t=t3=300;
//3
k1=k=k2=0;
ff=0;
f6=1;
}
else
{
if(ff==1)
{
PORTC.2=0 ;
PORTC.3=0 ;
}

- 14 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


else
{
if(b==1) //100%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>=(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
else
///50%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))

- 15 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
}
}
}
if((990<=ADCW)&&(ADCW<=1100))
{
f6=0;
f8=0;
x1=150;

//7

5phut ff chay 150 phut

if(f7==0)
// chi chay lan dau
{
y1=0;
t=t3=300;
//3
k1=k=k2=0;
ff=0;
f7=1;
}
else
{
if(ff==1)
{
PORTC.2=0 ;
PORTC.3=0 ;
}
else
{

- 16 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


if(b==1) //100%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
else
///50%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;

- 17 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
}
}
}
if((1100<=ADCW)&&(ADCW<=1025))
{

//8

chay lien tuc trong vong 180 phut

f0=0;
f7=0;
x1=180;
if(f8==0)
// chi chay lan dau
{
y1=0;
t=t3=300;
//3
k1=k=k2=0;
ff=0;
f8=1;
}
else
{
if(ff==1)
{
PORTC.2=0 ;
PORTC.3=0 ;
}
else
{
if(b==1) //100%
{
if(k2<=x1)

- 18 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=1 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if((((3*t+1))<k)&&(k<=(4*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>=(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
else
///50%
{
if(k2<=x1)
{
if((0<k)&&(k<=(t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((t+1)<k)&&(k<=(2*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');

- 19 -

File: D:\Automation\oz8\ozonend.c, Date: 7/28/2011, Time: 4:20:33 PM


}
if(((2*t+1)<k)&&(k<=(3*t+1)))
{
PORTC.2=0 ;
PORTC.3=1 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(((3*t+1)<k)&&(k<=(4*t+1)))
{
PORTC.2=1 ;
PORTC.3=0 ;
PORTD.0=1;
PORTD.1=1;
fliplop((x1-k2),'f');
}
if(k>(4*t+1))
{
k=0 ;
}
}
else
{
if((k2>x1)&&(k2<(x1+15)))
{
fliplop((x1+15-k2),'f');
PORTC.2=0 ;
PORTC.3=0 ;
}
if(k2>=(x1+15))
{
PORTD.0=0;
PORTD.1=0;
k2=k1=0;
y1=0;
ff=1;
}
}
}
}
}
}
}
} ;
}

- 20 -

You might also like