Deexith Hasan
Advanced Member level 4
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <htc.h> void main() { TRISB0=1; TRISD0=0; RD0=0; while(1) { if(RB0) RD0=1; else RD0=0; } }
Last edited by a moderator:
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <htc.h> void main() { TRISB0=1; TRISD0=0; RD0=0; while(1) { if(RB0) RD0=1; else RD0=0; } }
Code C - [expand] 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 #include <htc.h> #define _XTAL_FREQ 4000000 #define INPUT 1 #define OUTPUT 0 #define ON 1 #define OFF 0 #define LED LATbits.LATD0 #define LED_Direction TRISDbits.TRISD0 #define SW PORTBbits.RB0 #define SW_Direction TRISBbits.TRISB0 void Debounce() { Delay_ms(100); } void main() { ADCON1 = 0x0F; CMCON = 0x07; CVRCON = 0x00; TRISA = 0xFF; TRISB = 0x01; TRISC = 0x00; TRISD = 0x00; TRISE = 0x08; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; PORTE = 0x08; LATA = 0x00; LATB = 0x00; LATC = 0x00; LATD = 0x00; LATE = 0x00; SW_Direction = INPUT; LED_Direction = OUTPUT; while(1) { if(SW) { Debounce(); while(SW); LED = ~LED; } } }