issamo220
Messages postés1Date d'inscriptionsamedi 28 février 2009StatutMembreDernière intervention28 février 2009
-
28 févr. 2009 à 19:29
Bonjour,tous .
j'ai redige ce programme en laguage C du pic en utilisant le compiler CCS C, son but est de gener des impulsions afin de commander un petit moteur , j'ai pris en consideration le compteur 0 ( 8 bits ) pour les interruptions du pic 16f876 j'ai mis en oeuvre 2 boutons ( chacune a un sens ).
quelqu'un peut me dire si programme est juste sinon ou est la ou les fautes .
#include <16f876.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
//*******************
// variables globales
//*******************
int16 COMPTEUR1;
int COMPTEUR2, SENS;
int1 SIGNAL;
//******************
// DEFINE
//******************
#define TIME 4 // TIMER=3 --> 256-3=253 pas
#define 18MS 360 // 360*50=18000µs
#define AV 40 // 40*50 =2000µs
#define AR 20 // 20*50 =1000µs
#define STOP 30 // 30*50 =1500µs
#define PORT_SIGNAL PIN_B0
#define ENTREE1 PIN_B5
#define ENTREE2 PIN_B2
//******************
//Interruptions
//******************
#int_timer0 // Interruption toutes les (4*250)/20000000 = 50µs
main_int () {
set_timer0(TIME);
if (++COMPTEUR1 == 360) {
COMPTEUR1=0;
COMPTEUR2=0;
SIGNAL=1;
output_high(PORT_SIGNAL);
}
else {
if (SIGNAL==1) {
if (COMPTEUR2++ == SENS) {
SIGNAL=0;
output_low(PORT_SIGNAL);
}
}
}
}
//**********************
// Fonctions
//**********************
void init_timer () {
set_timer0(TIME);
setup_counters(RTCC_INTERNAL,WDT_18MS);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
}
//**********************
// Programme principal
//**********************
main() {
init_timer();
while (TRUE) { // boucle sans fin
if ((Input(ENTREE1)==1) && (Input(ENTREE2)==0))
SENS=AV;
if (((input(ENTREE1)==0) && (input(ENTREE2)==0))|| ((input(ENTREE1)==1) && (input(ENTREE2)==1)))
SENS=STOP;
if ((input(ENTREE1)==0) && (input(ENTREE2)==1))
SENS=AR;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------
et merci d'avance .
--------------------------------------------------------------------------------
What can you do with the new Windows Live? Find out