Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mcc_generated_files/system.h"
- #define FCY 4000000UL
- // define frequency
- #include "libpic30.h"
- // include for __delay_us();
- /*
- Main application
- */
- int main(void)
- {
- // initialize the device
- SYSTEM_Initialize();
- TRISAbits.TRISA0 = TRISAbits.TRISA1 = TRISCbits.TRISC7 = 0;
- // Set RGB-led to output
- TRISBbits.TRISB12 = 1; // Set RC0 to input
- ANSBbits.ANSB12 = 1; // Set RC0 to Analog
- AD1CON1bits.ADON = 1; // Start ADC1 converter
- AD1CON1bits.MODE12 = 0; // choose 10-bit result
- AD1CON1bits.SSRC = 0b0111; // auto convert
- AD1CON2bits.PVCFG = 0; // positive voltage reference = Vdd
- AD1CON2bits.NVCFG0 = 0; // negative voltage ref = ground
- AD1CON3bits.SAMC = 10; // auto samp time select 10TAD
- AD1CON3bits.ADCS = 10; // conversion clock select 11 x TCY = TAD
- AD1CHSbits.CH0SB = 01000; // choose AN08
- AD1CON1bits.FORM = 10; // data output form absolute fraction left-justified
- LATCbits.LATC7 = 1; // set blue light high
- while (1)
- {
- AD1CON1bits.DONE = 0; // reset done-bit
- AD1CON1bits.ASAM = 1; // start auto samp
- while(!AD1CON1bits.DONE); // wait for done
- AD1CON1bits.ASAM = 0; // stop auto samp
- __delay_us(ADC1BUF0); // wait ADC result in microsec
- LATCbits.LATC7 = 1;
- LATAbits.LATA1 = 0;
- LATAbits.LATA0 = 0;
- delay(1000);
- LATCbits.LATC7 = 0;
- LATAbits.LATA1 = 1;
- LATAbits.LATA0 = 0;
- delay(1000);
- LATCbits.LATC7 = 0;
- LATAbits.LATA1 = 0;
- LATAbits.LATA0 = 1;
- delay(1000);
- }
- return -1;
- }
- void delay(int d)
- {
- int i;
- while(d)
- {
- i = 100;
- while (i)
- {
- i--;
- }
- d--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement