Programme avec un PIC 16F876
hoshima
-
marcel48 -
marcel48 -
Bonjour,
je dois programmé un pic 16f876 pour mon projet de fin d'année de BTS.
Je connais pas grand chose à la programmation. Je dois programmer un pic 16F876 avec Mplab et j'ai choisis CC5x comme compilataur.
Le programme que je dois faire
c'est à partir d'une valeur de tension la comparer grace au pic et si elle est dans la plage de fonctionnement elle doit faire allumer une led. Si elle la valeur ne se situe pas dans la plage de fonctionnemenet elle doit allumé une autre led.
Je ne sais pas du tout par où commencer.
Pouvez-vous m'aidez.
Merci
je dois programmé un pic 16f876 pour mon projet de fin d'année de BTS.
Je connais pas grand chose à la programmation. Je dois programmer un pic 16F876 avec Mplab et j'ai choisis CC5x comme compilataur.
Le programme que je dois faire
c'est à partir d'une valeur de tension la comparer grace au pic et si elle est dans la plage de fonctionnement elle doit faire allumer une led. Si elle la valeur ne se situe pas dans la plage de fonctionnemenet elle doit allumé une autre led.
Je ne sais pas du tout par où commencer.
Pouvez-vous m'aidez.
Merci
A voir également:
- Programme avec un PIC 16F876
- Pic hunter - Télécharger - Téléchargement & Transfert
- Programme demarrage windows - Guide
- Mettre en veille un programme - Guide
- Pic collage gratuit - Télécharger - Photo & Graphisme
- Desinstaller un programme - Guide
3 réponses
Bonjour
Voici une partie de mon programme
pouvez vous me dire s'il est à peu près correcte et si la configuration du can est bonne? (je ne sais pas comment on fait pour récupérer la valeur qu'il convertit?)
#define <p16f873>
#include <delays.h>
#include <stdio.h>
#include <stdlib.h>
// shortcut definition
#define Temp_ok portb.7 //temperature is good
#define Temp_nok portb.6 //temperature is not good
#define Pressure_ok portb.5 //pressure is good
#define Pressure_nok portb.4 //pressure is not good
#define short_circuit_GND portb.3 //short circuit GND
#define short_circuit_supply portb.2 //short circuit supply
#define ill portb.1 //sensor is ill
#define open_circuit portb.0 //open circuit
#define battery_output portc.7 //battery
#define sensor_pressure_input porta.0 //pressure signal sensor
#define sensor_temp_input porta.1 //temperature signal sensor
#define battery_input porta.5 //signal battery
//constant and variable declaration
unsigned double sensor_output,sensor_pressure_input,sensor_temp_input;
unsigned double s1,s2,s3,s4,s5;
void main ()
{
// initialization (we initialize all variable)
failure=0;
short_circuit_supply=0;
short_circuit_GND=0;
Pressure_nok=0;
Pressure_ok=0;
Temp_nok=0;
Temp_ok=0;
open_circuit=0;
battery_output=0;
}
while (1)
{
// Analog Digital Conversion configuration
{
ADFM=1; //Left justified
Result.low8=ADRESSH //to retrieve only 16-Bits word instead 2 8-bits word
Result.hignt=ADRESSL // to retrieve only 16-Bits word instead 2 8-bits word
PDCF0=0; // enable to config pin like analog or digital input with this config AN0=AN1=AN4=analog input
PDCF1=0; // enable to config pin like analog or digital input
PDCF2=0; // enable to config pin like analog or digital input
PDCF3=1; // enable to config pin like analog or digital input
ADCS1=0 // bit which enable to choose frenquency for ADC
ADCSO=1 // bit which enable to choose frequency for ADC
CHS2=0 //bit which enable to select analog input to convert
CHS1=0 //bit which enable to select analog input to convert
CHS0=0 //bit which enable to select analog input to convert
GO/DONE=1 //bit which launch conversion
ADON=1 // Actuate ADC
GO/DONE=0 //bit which switch off conversion
ADON=0 // Switch off ADC
}
// level definition
0<s1<0,2 // s1= short circuit GND
0,2<s2<1,8 // s2=ill
1,8<s3<2,2 // s3= good sensor
2,2<s4<3,15 // s4=ill
3,15<s5<3,55 // s5=open circuit
3,55<s6<4,8 // s6=ill
s7<4,8 // s7=short circuit supply
//level pressure comparaison
if (sensor_temp_input=s1) //if the voltage level is between 0V and 0,2V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=1; //short circuit GND
portb.2=0; //short circuit supply
portb.1=0; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s2) //if the voltage level is between 0,2V and 1,8V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=1; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s3) // if the voltage level is between 1,8V and 2,2V
{
portb.7=1; //temperature is good
portb.6=0; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=0; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s4) // if the voltage level is between 2,2 V and 3,15V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=1; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s5) // if the voltage level is between 3,15V and 3,55V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=0; //sensor is ill
portb.0=1; //open circuit
}
else if (sensor_temp_input=s6) // if the voltage level is between 3,55V and 4,8V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=1; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s7) // if the voltage level is "superieur à " 4,8V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=1; //short circuit supply
portb.1=0; //sensor is ill
portb.0=0; //open circuit
}
}
Voici une partie de mon programme
pouvez vous me dire s'il est à peu près correcte et si la configuration du can est bonne? (je ne sais pas comment on fait pour récupérer la valeur qu'il convertit?)
#define <p16f873>
#include <delays.h>
#include <stdio.h>
#include <stdlib.h>
// shortcut definition
#define Temp_ok portb.7 //temperature is good
#define Temp_nok portb.6 //temperature is not good
#define Pressure_ok portb.5 //pressure is good
#define Pressure_nok portb.4 //pressure is not good
#define short_circuit_GND portb.3 //short circuit GND
#define short_circuit_supply portb.2 //short circuit supply
#define ill portb.1 //sensor is ill
#define open_circuit portb.0 //open circuit
#define battery_output portc.7 //battery
#define sensor_pressure_input porta.0 //pressure signal sensor
#define sensor_temp_input porta.1 //temperature signal sensor
#define battery_input porta.5 //signal battery
//constant and variable declaration
unsigned double sensor_output,sensor_pressure_input,sensor_temp_input;
unsigned double s1,s2,s3,s4,s5;
void main ()
{
// initialization (we initialize all variable)
failure=0;
short_circuit_supply=0;
short_circuit_GND=0;
Pressure_nok=0;
Pressure_ok=0;
Temp_nok=0;
Temp_ok=0;
open_circuit=0;
battery_output=0;
}
while (1)
{
// Analog Digital Conversion configuration
{
ADFM=1; //Left justified
Result.low8=ADRESSH //to retrieve only 16-Bits word instead 2 8-bits word
Result.hignt=ADRESSL // to retrieve only 16-Bits word instead 2 8-bits word
PDCF0=0; // enable to config pin like analog or digital input with this config AN0=AN1=AN4=analog input
PDCF1=0; // enable to config pin like analog or digital input
PDCF2=0; // enable to config pin like analog or digital input
PDCF3=1; // enable to config pin like analog or digital input
ADCS1=0 // bit which enable to choose frenquency for ADC
ADCSO=1 // bit which enable to choose frequency for ADC
CHS2=0 //bit which enable to select analog input to convert
CHS1=0 //bit which enable to select analog input to convert
CHS0=0 //bit which enable to select analog input to convert
GO/DONE=1 //bit which launch conversion
ADON=1 // Actuate ADC
GO/DONE=0 //bit which switch off conversion
ADON=0 // Switch off ADC
}
// level definition
0<s1<0,2 // s1= short circuit GND
0,2<s2<1,8 // s2=ill
1,8<s3<2,2 // s3= good sensor
2,2<s4<3,15 // s4=ill
3,15<s5<3,55 // s5=open circuit
3,55<s6<4,8 // s6=ill
s7<4,8 // s7=short circuit supply
//level pressure comparaison
if (sensor_temp_input=s1) //if the voltage level is between 0V and 0,2V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=1; //short circuit GND
portb.2=0; //short circuit supply
portb.1=0; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s2) //if the voltage level is between 0,2V and 1,8V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=1; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s3) // if the voltage level is between 1,8V and 2,2V
{
portb.7=1; //temperature is good
portb.6=0; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=0; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s4) // if the voltage level is between 2,2 V and 3,15V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=1; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s5) // if the voltage level is between 3,15V and 3,55V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=0; //sensor is ill
portb.0=1; //open circuit
}
else if (sensor_temp_input=s6) // if the voltage level is between 3,55V and 4,8V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=0; //short circuit supply
portb.1=1; //sensor is ill
portb.0=0; //open circuit
}
else if (sensor_temp_input=s7) // if the voltage level is "superieur à " 4,8V
{
portb.7=0; //temperature is good
portb.6=1; //temperature is not good
portb.3=0; //short circuit GND
portb.2=1; //short circuit supply
portb.1=0; //sensor is ill
portb.0=0; //open circuit
}
}
https://www.microchip.com/wwwproducts/en/en010239
la tu as la datasheet complète de ton pic.
il faut que tu commence par paramétrer le convertiseur analogique/numérique (tu trouveras tout sur le liens plus haut). une fois configuré, un while(1){......} et tu remplace les ..... par le code pour lancer la convertion et tu compares avec tes valeurs de plage
if(resultat_conv > plage_min && resultat_plage < plage_max)
//allume une led
else
// allume l'autre led.
la tu as la datasheet complète de ton pic.
il faut que tu commence par paramétrer le convertiseur analogique/numérique (tu trouveras tout sur le liens plus haut). une fois configuré, un while(1){......} et tu remplace les ..... par le code pour lancer la convertion et tu compares avec tes valeurs de plage
if(resultat_conv > plage_min && resultat_plage < plage_max)
//allume une led
else
// allume l'autre led.
Oh non il n'est pas nécessaire d'utiliser un quartz pour allumer une led. Tu utiliseras un timer (8 bits ou 16 bits selon le PIC utilisé (voir la doc)) cadencé par l'oscillateur de ton PIC; tu as le choix de l'oscillateur, selon la précision voulue tu pourras prendre l'oscillateur interne ou un oscillateur externe (circuit RC ou quartz (voir la doc)).
Bonne continuation.
Bonne continuation.