Tag Archives: tutorial

Interfacing Pic12F1840 (ADC and UART) with Raspberry Pi

Schematic

Board

Code [XC8 compiler]

#include "mcc_generated_files/mcc.h"
#include <stdlib.h>
#include <stdio.h>

void main(void)
{
    char * buf;
    int status;
    SYSTEM_Initialize();

    while (1)
    {
        adc_result_t reading = ADC_GetConversion(channel_AN0);
        
        float volts = (float) reading / 1023 * 3.3f;
        volts = volts * 2;
        buf = ftoa(volts, &status);
        printf("%s", buf);
        __delay_ms(5000);
    }
}