#include //Always include this code, it’s necessary when using a bootloader extern void _startup (void); #pragma code _RESET_INTERRUPT_VECTOR = 0x000800 void _reset (void) { _asm goto _startup _endasm } #pragma code #pragma code high_vector = 0x000808 void high_ISR (void) { } #pragma code #pragma code _LOW_INTERRUPT_VECTOR = 0x000818 void low_ISR (void) { } #pragma code // end of bootloader code /**************************************** Minimax Startup Code v1.0 - Use LAT_ for Outputs - Use PORT_ for Inputs - Use defines to make more readable code ***************************************/ #define LED1 LATBbits.LATB0 // all instances of LED1 will be replaced by LATBbits.LATB0 // so the name LED1 can now be used in the code to make it more readable void main(void) { // IO-port directions TRISA = 0b11111110; // Port A Input, A0 Output TRISB = 0b11111110; // Port B Input, B0 Output TRISC = 0b11111111; // Port C Input TRISD = 0b11111111; // Port D Input TRISE = 0b11111111; // Port E Input ADCON1 = 0b00001111; //All ADC disabled // set all outputs to 0; PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; while(1) { // read multiplexed switches LATAbits.LATA0 = 0; // Select active row (active low) if (PORTAbits.RA3 == 0) LED1 = 1; // switch pressed -> led1 ON // read the other colums and do something LATAbits.LATA0 = 1; // deselect active row // select next row and read the colums } }