Exercise

Icône de l'outil pédagogique Now it’s your turn...

You can try to write a program that forces to 1 the pin C2 when one pushes BP0 button, and to 0 otherwise.

Correction :

#include <p18f4550.h>

void main(void)

{

// initialization

TRISB |= 0x08; // B3 input

TRISC &= 0xFB; // C2 output

while (1) { // infinite loop

if ((PORTB & 0x08) == 0) { // if we push the BP0 button

PORTC |= 0x04; // C2 forced to 1

} else { // otherwise

PORTC &= 0xFB; // C2 forced to 0

}

}

}

Download the answer Zip file