Stap 6: Het programma
De bestanden hier zijn een tekstversie van de C-programma samen met het volledige Cypress Designer-bestand in zip-formaat.Zijn niet vreselijk lang...
//----------------------------------------------------------------------------
C programma voor PSOC temperatuur controller
//----------------------------------------------------------------------------
#include < m8c.h > / / deel van specifieke constanten en macro's
#include "PSoCAPI.h" / / PSoC API definities voor alle Modules van de gebruiker
#include "stdlib.h"
int MAXC = 0;
int TEMPC = 500;
char degC [] = "500";
char [degF] = "932";
int TEMPF = 932;
void main()
{
int w, z;
int KeyRead, KeyBuffer;
int x, buffer;
zweven temperatuur = 0;
zweven temperature2 = 0;
int count = 0;
int stop = 1;
int CycleBuffer;
int basis = 1;
int InputADC;
int InputADC2;
char lcd_Reading [8];
char lcd_Setting [8];
PGA_1_SetGain(PGA_1_G1_00);
PGA_1_Start(PGA_1_LOWPOWER);
DAC9_1_Start(DAC9_1_FULLPOWER);
LCD_1_Start(); Initialiseren van de LCD
M8C_EnableGInt; Inschakelen van de wereldwijde Interrupts
AboveTop:
DAC9_1_WriteBlind(0); set output naar 0V
ADCINC12_1_Start(ADCINC12_1_LOWPOWER); De stroomtoevoer naar de SC-blok
ADCINC12_1_GetSamples(0); ADC continu draaien hebben
LCD_1_Control(LCD_1_DISP_CLEAR_HOME);
LCD_1_Position(0,0);
LCD_1_PrCString ("MAX Limit");
LCD_1_Position(0,10);
Als (basis == 0)
{
MAXC = TEMPF;
LCD_1_PrString(degF);
LCD_1_Position(0,14);
LCD_1_PrCString("F");
} else
{
MAXC = TEMPC;
LCD_1_PrString(degC);
LCD_1_Position(0,14);
LCD_1_PrCString("C");
}
for(;;) {
Boven:
KeyRead = PRT1DR; Lees voor ToetsIndrukken (KeyPress)
while(ADCINC12_1_fIsDataAvailable() == 0); Lus tot waarde klaar
ADCINC12_1_ClearFlag(); ADC-markering wissen
x=ADCINC12_1_iGetData(); ADC resultaat krijgen
Als (InputADC > = temperatuur) / / autostop en eerste voorwaarde instellen
{
DAC9_1_WriteBlind(0); productie van de 0V
}
Als (stoppen == 0) / / loop voor automatisch opnieuw starten in de start-voorwaarde
{
Als (CycleBuffer < temperatuur)
{
DAC9_1_WriteBlind(510); output van 5V
}
}
Als (x == buffer) / / controle voor geldige ADC lezen
{
InputADC =(x*0.5208)-12; / / correctie voor sonde weerstand.
Als (basis == 0)
{
InputADC = (9.0/5.0*InputADC) + 32;
}
Als (InputADC < = 99) / / set up display te hogen 10 en 100 's naar links
{
lcd_Reading [0] = ' ';
w = 1;
Als (InputADC < = 9)
{
lcd_Reading [1] =' ';
w = 2;
}
} else w = 0;
InputADC2 = abs(InputADC); absolute waarde
int omzetten in een base 10 lege beëindigd ASCII-tekenreeks
Itoa (& lcd_Reading [w], (unsigned int) InputADC2, 10);
Als (temperatuur < = 99) / / input te lezen correct instellen
{
lcd_Setting [0] = ' ';
z = 1;
Als (temperatuur < = 9)
{
lcd_Setting [1] =' ';
z = 2;
}
} anders z = 0;
temperature2 = abs(temperature);
int converteert naar een base 10 lege beëindigd ASCII-tekenreeks
Itoa (& lcd_Setting [z], temperature2 (unsigned int), 10);
CycleBuffer = InputADC + 2; Herstart ondergrens instellen
LCD_1_Position(1,0);
LCD_1_PrString(lcd_Reading); continu Temperatuurdisplay
LCD_1_Position(1,5);
LCD_1_PrCString ("SET ->");
LCD_1_Position(1,10);
LCD_1_PrString(lcd_Setting);
Stel belangrijke herhaal functie voor omhoog van toetsen alleen
Als (KeyRead! = 0x00) //0x03 als programmeur aangesloten
{
Graaf ++;
Als (graaf > 15)
Als (KeyRead == 0x80|| KeyRead == 0x40)
goto hier;
} anders tellen = 0;
Als (KeyBuffer == KeyRead) / / dubbele sleutel negeren
goto Top;
HIER:
Programmeur zal het toevoegen van 0X03 aan alle gevallen wanneer aangesloten
schakelaar (KeyRead) {}
kast (0x80): / / verhogen van de temperatuur
if(Count>15)
{temperatuur = temperatuur + 10;
Graaf = 0;
Als (temperatuur > = MAXC)
{goto HIGHlimit;
}
goto Top;
}
KeyBuffer = KeyRead;
Als (temperatuur > = MAXC)
{goto HIGHlimit;
}
goto TempUp;
breken;
kast (0x40): / / decrement temperatuur
if(Count>15)
{temperatuur = temperatuur-10;
Graaf = 0;
Als (temperatuur < = 0)
{goto LOWlimit;
}
goto Top;
}
KeyBuffer = KeyRead;
Als (temperatuur < = 0)
{goto LOWlimit;
}
goto TempDown;
breken;
kast (0x20): / / clear
KeyBuffer = KeyRead;
goto duidelijk;
breken;
geval (0X10): //start
KeyBuffer = KeyRead;
Goto Start;
breken;
kast (0x08): //stop
KeyBuffer = KeyRead;
goto Stop;
breken;
kast (0x04): //base verandering
KeyBuffer = KeyRead;
Als (basis == 1)
{//Change tot F
basis = 0;
goto Base;
}
Als (basis == 0)
{//Change tot C
basis = 1;
}
goto Base;
breken;
standaard:
KeyBuffer = KeyRead;
breken;
}
}
buffer = x; ADC validatie buffer
goto Top;
TempUp:
temperatuur ++; Increment instelling
goto Top;
TempDown:
temperatuur--; decrement instelling
goto Top;
Duidelijk:
temperatuur = 0;
Graaf = 0;
LCD_1_Position(1,10);
LCD_1_PrString(lcd_Setting);
goto AboveTop;
Foutbericht ' Stop:
LCD_1_Control(LCD_1_DISP_CLEAR_HOME);
LCD_1_Position(0,0);
LCD_1_PrCString ("gestopt bij");
LCD_1_PrString(lcd_Reading);
DAC9_1_WriteBlind(0);
stoppen = 1;
Als (basis == 0)
{
MAXC = TEMPF;
LCD_1_Position(0,15);
LCD_1_PrCString("F");
} else
{
MAXC = TEMPC;
LCD_1_Position(0,15);
LCD_1_PrCString("C");
}
goto Top;
Start:
LCD_1_Control(LCD_1_DISP_CLEAR_HOME);
LCD_1_Position(0,0);
LCD_1_PrCString ("verwarming aan");
LCD_1_PrString(lcd_Setting);
Als (InputADC < = temperatuur)
{
DAC9_1_WriteBlind(510);
} else
{
DAC9_1_WriteBlind(0);
}
stoppen = 0;
Als (basis == 0)
{
MAXC = TEMPF;
LCD_1_Position(0,15);
LCD_1_PrCString("F");
} else
{
MAXC = TEMPC;
LCD_1_Position(0,15);
LCD_1_PrCString("C");
}
goto Top;
LOWlimit:
temperatuur = 0;
goto Top;
HIGHlimit:
temperatuur = MAXC;
goto Top;
Base:
Als (basis == 1) //Degrees F tot graden C
{
Als (temperatuur! = 0)
{
temperature2 = temperatuur;
Temperature=(5.0/9.0*(temperature2-32)); converteren van F naar C
}
goto BaseBottom;
} else
Als (temperatuur! = 0)
{
temperature2 = temperatuur;
temperatuur = (9.0/5.0*temperature2) + 32; converteren van C naar F
}
BaseBottom:
Als (stoppen == 0)
{
goto Top;
} else goto AboveTop;
}
}