Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Main.c file generated by New Project wizard
- *
- * Created: vie mar 23 2018
- * Processor: PIC18F45K22
- * Compiler: MPLAB XC8
- */
- #include <xc.h>
- #define _XTAL_FREQ 8000000
- int count = 0;
- int apretat0 = 0;
- int apretat1 = 0;
- void configLEDS(int augmenta) {
- switch (count) {
- case 0:
- PORTAbits.RA0 = 0;
- break;
- case 1:
- if (augmenta)
- PORTAbits.RA0 = 1;
- else
- PORTAbits.RA1 = 0;
- break;
- case 2:
- if (augmenta)
- PORTAbits.RA1 = 1;
- else
- PORTAbits.RA2 = 0;
- break;
- case 3:
- if (augmenta)
- PORTAbits.RA2 = 1;
- else
- PORTAbits.RA3 = 0;
- break;
- case 4:
- if (augmenta)
- PORTAbits.RA3 = 1;
- else
- PORTAbits.RA4 = 0;
- break;
- case 5:
- if (augmenta)
- PORTAbits.RA4 = 1;
- break;
- }
- }
- void main(void) {
- //Config
- //Set as digital port
- ANSELA = 0x00;
- ANSELB = 0x00;
- //Set RA ports as output
- TRISA = 0x00;
- //Set RB0 and RB1 as input
- TRISBbits.RB0 = 1;
- TRISBbits.RB1 = 1;
- while (1) {
- if (PORTBbits.RB1 && !apretat0) {
- //Augmentar
- apretat0 = 1;
- __delay_ms(20);
- if (count < 5) ++count;
- configLEDS(1);
- }
- else if (!PORTBbits.RB1 && apretat0 == 1)
- apretat0 = 0;
- else if (PORTBbits.RB0 && !apretat1) {
- //Disminuir
- apretat1 = 1;
- __delay_ms(20);
- if (count > 0) --count;
- configLEDS(0);
- }
- else if (!PORTBbits.RB0 && apretat1 == 1)
- apretat1 = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement