1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#include std84.h
#include bit84.h
#define descendre porta.0
#define monter porta.1
#define cs porta.2
#define clock porta.3
#define bouton_poussoir portb.4
#define data portb.7
void main()
{
char nouvelle_position, buffer, ancienne_position, z;
trisa = 0 ;
trisb = 0b11111111 ;
// la barriere est fermée à l'état initial
for(;;)
{
// tant qu'on appuit pas sur le bouton poussoir faire rien
while(!bouton_poussoir);
// acquisition du CAN serie
cs =1; //Mode lecture de la tension analogique
microdelay(100); // Temps de conversion AN
cs =0; //Mode extraction des bits
clock = 1; buffer.7 =data; clock = 0;
clock = 1; buffer.6 =data; clock = 0;
clock = 1; buffer.5 =data; clock = 0;
clock = 1; buffer.4 =data; clock = 0;
clock = 1; buffer.3 =data; clock = 0;
clock = 1; buffer.2 =data; clock = 0;
clock = 1; buffer.1 =data; clock = 0;
clock = 1; buffer.0 =data; clock = 0;
ancienne_position = buffer;
// baisser la barriere
descendre = 1 ;
z=1;
while(z)
{
delays(0.5);
// refaire l'acquisition
cs =1; //Mode lecture de la tension analogique
microdelay(20); // Temps de conversion AN
cs =0; //Mode extraction des bits
clock = 1; buffer.7 =data; clock = 0;
clock = 1; buffer.6 =data; clock = 0;
clock = 1; buffer.5 =data; clock = 0;
clock = 1; buffer.4 =data; clock = 0;
clock = 1; buffer.3 =data; clock = 0;
clock = 1; buffer.2 =data; clock = 0;
clock = 1; buffer.1 =data; clock = 0;
clock = 1; buffer.0 =data; clock = 0;
// acquisition du CAN serie
nouvelle_position = buffer;
// si la position nouvelle est égale à la position d'avant,
// alors on arrête ... sinon on continue
if(nouvelle_position == ancienne_position)
z=0;
else
ancienne_position = buffer;
}
// on arrète la barrière
descendre = 0 ;
delays(2) ;
// on remonte la barrière
monter = 1 ;
// acquisition du CAN serie
z=1;
ancienne_position = buffer ;
while(z)
{
delays(1);
// refaire l'acquisition
cs =1; //Mode lecture de la tension analogique
microdelay(20); // Temps de conversion AN
cs =0; //Mode extraction des bits
clock = 1; buffer.7 =data; clock = 0;
clock = 1; buffer.6 =data; clock = 0;
clock = 1; buffer.5 =data; clock = 0;
clock = 1; buffer.4 =data; clock = 0;
clock = 1; buffer.3 =data; clock = 0;
clock = 1; buffer.2 =data; clock = 0;
clock = 1; buffer.1 =data; clock = 0;
clock = 1; buffer.0 =data; clock = 0;
nouvelle_position = buffer;
// si la position nouvelle est égale à la position d'avant,
// alors on arrête ... sinon on continue
if(nouvelle_position==ancienne_position)
z=0;
else
ancienne_position = buffer;
}
// on arrète la barrière
monter = 0 ;
}
} |
Partager