Professional Documents
Culture Documents
ROBOCEPT
Compteur
Zero=> déclenche une interruption
PIC16F877: 3 timer:
1- Le mode timer
T0CS= 0 (bit 5 du registre OPTION_REG)
2- Le mode compteur
T0CS= 1 (bit 5 du registre OPTION_REG)
1- Le mode timer
T0CS=0 (bit 5 du registre OPTION_REG)
4. Start conversion:
• Set GO/DONE bit (ADCON0 2bit)
5. Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared
(with interrupts enabled)
OR
• Waiting for the A/D interrupt (ADIF BIT6 OF PIR1)
6. Read A/D result register pair
(ADRESH:ADRESL), clear bit ADIF if required.
EXEMPLE SUR MICROC
void init(void)
void main ()
{
init();
while(1){
ADCON0.F2= 1; //remise à 1 de ADCON0F.2 pour car passe à 0 après conversion sinon on
relance pas la conversion
while(ADCON0.F2==1){ //Attente pour l'acquisition du résultat
nop();
}
PORTB=ADRESL;
PORTD=ADRESH;
}
}
EXEMPLE 1 :
void init(void){
//initialisation:
TRISA.F0=1; // initialisation comme entrée
TRISB=0; //initialisation comme sortie
TRISD=0; //initialisation comme sortie
ADCON0=0b10000101; //clock=FOSC/2 // channel RA0 entrée // start
ADCON1=0b10000000; // LSB configuration
out=0;
a=0;
b=0;
PORTB=0;
PORTD=0;
//fin initialisation
}
EXEMPLE 2 :
unsigned int cnt;
unsigned int a;
void prog();
void main() {
void prog()
{
while (a < 10) {
if (cnt==20) {
TMR0=0; // reset du TMR0
cnt = 0; // Reset cnt
if (a==0) PORTB= 0x3F;
else if (a==1) PORTB= 0x06; else if (a==2) PORTB= 0x5B;
else if (a==3) PORTB= 0x4F; else if (a==4) PORTB= 0x66;
else if (a==5) PORTB= 0x6D; else if (a==6) PORTB= 0x7D;
else if (a==7) PORTB= 0x07; else if (a==8) PORTB= 0x7F;
else if (a==9) PORTB= 0x6F;
a ++; // Increment value of a
}
}
if (a ==10) a=0;
}
SIMULATION ISIS
Merci Pour Votre Attention