Étape 6: Le programme
Les fichiers ici sont une version texte du programme C avec le fichier de concepteur de Cypress complète au format zip.Ses pas terriblement longue...
//----------------------------------------------------------------------------
Programme en C pour le contrôleur de température PSOC
//----------------------------------------------------------------------------
#include < m8c.h > / / partie des constantes et des macros
#include « PSoCAPI.h » / / définitions PSoC API pour tous les Modules de l’utilisateur
#include « stdlib.h » à
int MAXC = 0 ;
int NC = 500 ;
Char [° c] = "500" ;
Char [] degF = "932" ;
int TEMPF = 932 ;
Sub main()
{
int w, z ;
int KeyRead, KeyBuffer ;
int x, tampon ;
flotteur de température = 0 ;
float temperature2 = 0 ;
int count = 0 ;
arrêt d’int = 1 ;
int CycleBuffer ;
int de base = 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() ; Initialiser le LCD
M8C_EnableGInt ; Activer les interruptions Global
AboveTop :
DAC9_1_WriteBlind(0) ; sortie à 0V
ADCINC12_1_Start(ADCINC12_1_LOWPOWER) ; Mettre sous tension le bloc SC
ADCINC12_1_GetSamples(0) ; Ont ADC fonctionne continuellement
LCD_1_Control(LCD_1_DISP_CLEAR_HOME) ;
LCD_1_Position(0,0) ;
LCD_1_PrCString ("MAX limite") ;
LCD_1_Position(0,10) ;
Si (base == 0)
{
MAXC = TEMPF ;
LCD_1_PrString(degF) ;
LCD_1_Position(0,14) ;
LCD_1_PrCString("F") ;
} else
{
MAXC = NC ;
LCD_1_PrString(DEGC) ;
LCD_1_Position(0,14) ;
LCD_1_PrCString("C") ;
}
for(;;) {
Retour au début:
KeyRead = PRT1DR ; lire pour keypress
while(ADCINC12_1_fIsDataAvailable() == 0) ; Boucle jusqu'à ce que valeur prêt
ADCINC12_1_ClearFlag() ; Claire drapeau ADC
x=ADCINC12_1_iGetData() ; Obtenir le résultat de l’ADC
Si (InputADC > = température) / / Set up autostop et condition initiale
{
DAC9_1_WriteBlind(0) ; sortie 0V
}
Si (arrêter == 0) / / boucle de redémarrage automatique en condition de départ
{
Si (CycleBuffer < température)
{
DAC9_1_WriteBlind(510) ; sortie 5V
}
}
if (x == tampon) / / lecture de cocher pour ADC valide
{
InputADC =(x*0.5208)-12; / / correction pour la résistance de la sonde.
Si (base == 0)
{
InputADC = (9.0/5.0*InputADC) + 32 ;
}
Si (InputADC < = 99) / / set up affichage d’incrément de 10 et 100 à gauche
{
lcd_Reading [0] = ' ' ;
w = 1 ;
Si (InputADC < = 9)
{
lcd_Reading [1] =' ' ;
w = 2 ;
}
} else w = 0 ;
InputADC2 = abs(InputADC) ; valeur absolue
convertir int en une base 10 null résilié chaîne ASCII
EGTI (& lcd_Reading [w], (unsigned int) InputADC2, 10) ;
Si (température < = 99) / / configuré en entrée pour lire correctement
{
lcd_Setting [0] = ' ' ;
z = 1 ;
Si (température < = 9)
{
lcd_Setting [1] =' ' ;
z = 2 ;
}
} else z = 0 ;
temperature2 = abs(temperature) ;
Convertit int en une base 10 null résilié chaîne ASCII
EGTI (& lcd_Setting [z], temperature2 (unsigned int), 10) ;
CycleBuffer = InputADC + 2 ; Définissez le seuil de redémarrage
LCD_1_Position(1,0) ;
LCD_1_PrString(lcd_Reading) ; affichage de la température en continu
LCD_1_Position(1,5) ;
LCD_1_PrCString ("->") ;
LCD_1_Position(1,10) ;
LCD_1_PrString(lcd_Setting) ;
la valeur de clé fonction de répétition pour des touches seulement
Si (KeyRead! = 0 x 00) //0x03 lorsqu’il est attaché de programmeur
{
Count ++ ;
Si (comte > 15)
Si (KeyRead == 0x80|| KeyRead == 0 x 40)
Goto ici ;
} else comte = 0 ;
Si (KeyBuffer == KeyRead) / / ignorer les clés dupliquées
Goto Top ;
ICI :
Programmeur ajoutera 0 x 03 à tous les cas lorsqu’il est attaché
Switch (KeyRead) {}
affaire (0 x 80): / / incrément de température
if(Count>15)
{la température = Température + 10 ;
Count = 0 ;
Si (température > = MAXC)
{goto HIGHlimit ;
}
Goto Top ;
}
KeyBuffer = KeyRead ;
Si (température > = MAXC)
{goto HIGHlimit ;
}
Goto TempUp ;
rupture ;
affaire (0 x 40): / / decrement, température
if(Count>15)
{la température = Température-10 ;
Count = 0 ;
Si (température < = 0)
{goto LOWlimit ;
}
Goto Top ;
}
KeyBuffer = KeyRead ;
Si (température < = 0)
{goto LOWlimit ;
}
Goto TempDown ;
rupture ;
affaire (0 x 20): / / clear
KeyBuffer = KeyRead ;
Goto Clear ;
rupture ;
cas (0 x 10): //start
KeyBuffer = KeyRead ;
Goto début ;
rupture ;
affaire (0 x 08): //stop
KeyBuffer = KeyRead ;
Goto Stop ;
rupture ;
affaire (0 x 04): changement de //base
KeyBuffer = KeyRead ;
Si (base == 1)
{//Change à F
base = 0 ;
Goto Base ;
}
Si (base == 0)
{//Change à C
base = 1 ;
}
Goto Base ;
rupture ;
par défaut :
KeyBuffer = KeyRead ;
rupture ;
}
}
tampon = x ; Tampon de validation ADC
Goto Top ;
TempUp :
température ++ ; réglage de l’incrément
Goto Top ;
TempDown :
température--; Decrement, réglage
Goto Top ;
Claire :
température = 0 ;
Count = 0 ;
LCD_1_Position(1,10) ;
LCD_1_PrString(lcd_Setting) ;
Goto AboveTop ;
Arrêt :
LCD_1_Control(LCD_1_DISP_CLEAR_HOME) ;
LCD_1_Position(0,0) ;
LCD_1_PrCString ("arrêté à") ;
LCD_1_PrString(lcd_Reading) ;
DAC9_1_WriteBlind(0) ;
arrêter = 1 ;
Si (base == 0)
{
MAXC = TEMPF ;
LCD_1_Position(0,15) ;
LCD_1_PrCString("F") ;
} else
{
MAXC = NC ;
LCD_1_Position(0,15) ;
LCD_1_PrCString("C") ;
}
Goto Top ;
Départ :
LCD_1_Control(LCD_1_DISP_CLEAR_HOME) ;
LCD_1_Position(0,0) ;
LCD_1_PrCString ("chauffage à") ;
LCD_1_PrString(lcd_Setting) ;
Si (InputADC < = température)
{
DAC9_1_WriteBlind(510) ;
} else
{
DAC9_1_WriteBlind(0) ;
}
arrêter = 0 ;
Si (base == 0)
{
MAXC = TEMPF ;
LCD_1_Position(0,15) ;
LCD_1_PrCString("F") ;
} else
{
MAXC = NC ;
LCD_1_Position(0,15) ;
LCD_1_PrCString("C") ;
}
Goto Top ;
LOWlimit :
température = 0 ;
Goto Top ;
HIGHlimit :
température = MAXC ;
Goto Top ;
Base :
Si (base == 1) //Degrees F degrés c
{
Si (température! = 0)
{
temperature2 = temperature ;
Temperature=(5.0/9.0*(temperature2-32)) ; convertir de F à C
}
Goto BaseBottom ;
} else
Si (température! = 0)
{
temperature2 = temperature ;
température = (9.0/5.0*temperature2) + 32 ; convertir C à F
}
BaseBottom :
Si (arrêter == 0)
{
Goto Top ;
} else goto AboveTop ;
}
}
main.txt Pouvez