Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
2.2 kB
1
Indexable
Never
// PIC24FJ128GA010 Configuration Bit Settings
// For more on Configuration Bits
// consult your device data sheet
// CONFIG2
#pragma config POSCMOD = XT // XT Oscillator mode selected
#pragma config OSCIOFNC = ON // OSC2/CLKO/RC15 as port I/O (RC15)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor disabled
#pragma config FNOSC = PRI // Primary Oscillator (XT, HS, EC)
#pragma config IESO = ON // Int Ext Switch Over Mode enabled
// CONFIG1
#pragma config WDTPS = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128 // WDT Prescaler (1:128)
#pragma config WINDIS = ON // Watchdog Timer Window Mode disabled
#pragma config FWDTEN = OFF // Watchdog Timer disabled
#pragma config ICS = PGx2 // Emulator/debugger uses EMUC2/EMUD2
#pragma config GWRP = OFF // Writes to program memory allowed
#pragma config GCP = OFF // Code protection is disabled
#pragma config JTAGEN = OFF // JTAG port is disabled
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include <libpic30.h>
#include <stdlib.h>
#include "buttons.h"
#include <stdbool.h>

int main(void) {
unsigned char portValue;
// Port A access
    AD1PCFG = 0xFFFF;
    TRISA = 0x0000;
    
    int wybor = 0;
    

        
        if (BUTTON_IsPressed ( BUTTON_S3 ) == true) {
            wybor++;
        } else if ((BUTTON_IsPressed ( BUTTON_S4 ) == true)) {
            wybor--;
        }
        
    
    
    switch(wybor) {
            case 0:
                
                    for(int i = 0; i<=256; i++){
                        portValue = i;
                        LATA = portValue;
                        __delay32(1500000); 
                    }
                
                break;
                
            case 1:
                
                    for(int i = 256; i>=0; i--){
                        portValue = i;
                        LATA = portValue;
                        __delay32(1500000); 
                    }
                
                break;
        }
    
return -1;
}
Leave a Comment