Stap 5: Systeem programmering
["#include
#define lcdport P0
#define adcport P1
SBIT enterkey = P2 ^ 5;
SBIT downkey = P2 ^ 6;
SBIT upkey = P2 ^ 7;
SBIT rs = P2 ^ 0;
SBIT rdwr = P2 ^ 1;
SBIT lcde = P2 ^ 2;
SBIT relay P2 = ^ 3;
SBIT zoemer P2 = ^ 4;
SBIT intr = P3 ^ 0;
SBIT wr = P3 ^ 1;
SBIT rd = P3 ^ 2;
unsigned char adcdata;
unsigned char referenceval;
unsigned char enterkeyflag;
unsigned char enterkeycount;
unsigned char buzzercount;
unsigned char buzzerentrycount;
unsigned char loopflag = 1;
unsigned char adcdatagreaterflag;
Const unsigned char slogan1 [] = "Bodem irrigatie";
Const unsigned char slogan2 [] = "Contrl systeem";
Const unsigned char slogan3 [] = "referentiewaarde";
Const unsigned char slogan4 [] = "Bodem waarde";
nietig delay();
nietig lcdinit();
nietig clr_lcd();
nietig dispslogan(char*);
nietig senddata(unsigned char);
nietig send_command(unsigned char);
nietig next_line();
nietig delay1();
unsigned char xch(unsigned char);
ongeldig timer0() interrupt 1
{
buzzercount ++;
TF0 = 0;
TH0 = 00;
TL0 = 00;
if(buzzercount==100)
{
buzzercount = 1;
zoemer = 0;
ET0 = 0;
TR0 = 0;
}
}
VOID longdelay()
{
unsigned int i, j;
voor (ik = 0; ik < 100; i ++)
{
voor (j = 0; j < 400; j ++)
{}
}}
VOID adccontrol()
{
WR = 0;
delay();
WR = 1;
delay();
while(intr == 1); / * wachten totdat het signaal INTR maakt * /
/ * hoge-naar-low overgang die aangeeft * /
/ * voltooiing van conversie
/ * Luiden naar de waarde van de spanning van de haven * /
delay();
RD = 0;
delay();
delay();
adcdata = adcport;
RD = 1;
}
VOID sndconvdata (unsigned char convdata)
{
unsigned char convdata1;
convdata1 = convdata/10;
SendData (convdata1/10 + 48);
SendData (convdata1% 10 + 48);
SendData (convdata % 10 + 48);
dispslogan ("%");
}
VOID upkeychk()
{
if(upkey==0)
{
referenceval ++;
send_command(0xc4);
sndconvdata(referenceval);
}}
VOID downkeychk()
{
if(downkey==0)
{
referenceval--;
send_command(0xc4);
sndconvdata(referenceval);
}}
VOID enterkeychk()
{
if(enterkey==0)
{
enterkeycount ++;
if(enterkeycount==1)
{
enterkeyflag = 1;
clr_lcd();
dispslogan(slogan3);
send_command(0xc4);
sndconvdata(referenceval);
}}} “]
["/ *** BEGINNEN DE TEMPERATUUR CONTROLLER PROJECT *** /
void main()
{
relay = 0a;
zoemer = 0;
TMOD = 0X01;
TH0 = 00;
TL0 = 00;
EA = 1;
ET0 = 0;
TR0 = 0;
rdwr = 0;
delay();
lcdinit();
clr_lcd();
dispslogan(slogan1);
next_line();
dispslogan(slogan2);
longdelay();
clr_lcd();"
["/ *** STARTEN VAN DE MAIN-LOOP *** /
while(enterkeycount<2)
{
enterkeychk();
if(enterkeyflag)
upkeychk();
if(enterkeyflag)
downkeychk();
}
RD = 1;
WR = 1;
intr = 1;
clr_lcd();
dispslogan(slogan4);
while(1)
{
delay();
adccontrol();
delay();
send_command(0xc4);
sndconvdata(2*adcdata);
Als (2 * adcdata > referenceval)
{
if(!adcdatagreaterflag)
{
adcdatagreaterflag = 1;
buzzerentrycount ++;
lcde = 1;
relay = 0;
if(buzzerentrycount==1)
{
zoemer = 1;
ET0 = 1;
TR0 = 1;
}}}”]
["/ *** FUNCTIE OM TE SWAPPEN, LSBYTE EN MSBYTE DE GEGEVENS *** /
unsigned char xch (unsigned char data1)
{
unsigned char temp, temp1;
Temp = data1;
Data1 = data1 >> 4;
temp1 = data1;
Data1 = temp;
Data1 = data1 << 4;
Data1 = data1|temp1;
Return(Data1);
} “]
["/ *** INITIALISATIE VAN LCD *** /
VOID lcdinit()
{
clr_lcd(); / * FUNCTIE SET * /
send_command(0x28);
delay();
send_command(0x28);
delay();
send_command(0x28);
delay();
send_command(0x06); MODUS GEGEVENSINVOER
delay()
send_command(0x0e); WEERGEVEN AAN/UIT
vertraging)
clr_lcd();
} “]
["/ * FUNCTIE VOOR HET WEERGEVEN VAN GEGEVENS OP HET LCD-SCHERM *** /
VOID dispslogan (unsigned char * p)
{
unsigned char data1;
while(*p)
{
Data1 = * p;
SendData(Data1);
p ++;
}
} “]
["/ *** FUNCTIE VOOR VERZENDEN LCD OPDRACHTEN *** /
VOID send_command (unsigned char data1)
{
unsigned char newdata;
RS = 0;
delay();
lcde = 1;
delay();
lcdport = data1;
lcde = 0;
delay();
lcde = 1;
NewData=xch(Data1);
lcdport = newdata;
delay();
lcde = 0;
delay();
RS = 1;
} “]
["/ *** FUNCTIE VOOR SCHRIJVEN GEGEVENS OP DE LCD *** /
VOID senddata (unsigned char data1)
{
unsigned char newdata;
RS = 1;
delay();
lcde = 1;
delay();
lcdport = data1;
lcde = 0;
delay();
lcde = 1;
NewData=xch(Data1);
lcdport = newdata;
delay();
lcde = 0;
delay();
RS = 0;
} “]
["/ *** uitstellen voor micro-20 tweede *** /
VOID delay()
{
unsigned char i, j;
voor (ik = 0; ik < 80; i ++)
{
voor (j = 0; j < 120; j ++)
{}
}}”]
["/ *** OPDRACHT OM LCD-CURSOR OP DE TWEEDE REGEL *** /
VOID next_line()
{
send_command(0xc0);
delay();
} “]
["/ *** OPDRACHT VOOR CLEARING LCD EN BRENGEN LCD-CURSOR OP EERSTE LIJN *** /
VOID clr_lcd()
{
send_command(0x01);
delay();
send_command(0x02);
delay();
} “]