// PIC18 in C - Versione 0.3 - Febbraio 2016 // Copyright (c) 2014, Vincenzo Villa // Creative Commons | Attribuzione-Condividi allo stesso modo 3.0 Unported. // Creative Commons | Attribution-Share Alike 3.0 Unported // https://www.vincenzov.net/tutorial/PIC18/hello-2.htm // Reference // PIC18F2431 data sheet - PORTx, TRISx and LATx Registers - Page 119 -> // PIC18F2xK20 data sheet - PORTx, TRISx, LATx and ANSLEH Registers - Page 124 -> // NOTE: digital source with esternal pull-up or push-pull #include "configurationsbits.h" void main(void) { TRISB = 0xFF; // Set all PORTB pin as input - See data sheet! ANSELH = 0; // ONLY PIC18F2xK20 - Digital input buffers PORTB are enabled - See data sheet! TRISC = 0x00; // Set all PORTC pin as Output - See data sheet! while (1) { if (PORTBbits.RB0 == 0)// If pin V(RB0) = Low voltage LATCbits.LATC0 = 1; // Turn on RC0 pin - See data sheet! else LATCbits.LATC0 = 0; // Turn off RC0 pin - See data sheet! } }