Posts

Pic16f188xx ADC with fvr

 #include <xc.h> // Configuration bits #pragma config FOSC = INTOSC // Internal Oscillator #pragma config WDTE = OFF // Watchdog Timer Disable #pragma config PWRTE = OFF // Power-up Timer Disable #pragma config MCLRE = ON // MCLR Pin Function Select #pragma config CP = OFF // Flash Program Memory Code Protection #pragma config BOREN = ON // Brown-out Reset Enable #pragma config CLKOUTEN = OFF // Clock Out Disable #pragma config IESO = OFF // Internal/External Switchover #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Disable // Define system frequency #define _XTAL_FREQ 32000000 // 32 MHz internal oscillator void setup(void) {     // Initialize oscillator     OSCCON1 = 0x60; // Set OSCCON1 - HFINTOSC with 1x divider     OSCFRQ = 0x06; // Set OSCFRQ - 32MHz HFINTOSC     // Initialize FVR to 2.048V for ADC     FVRCON = 0b11000010; // FVREN enabled, ADC FVR Buffer Gain is 2x (2.048V)     // Set RA0/AN0 as analog input     TRI

I2C MasterSlave

 Esp32 I2C Slave code #include <Wire.h> #define SLAVE_ADDR 0x04 // Define the I2C Slave address // Data to send to the I2C master String dataToSend = "Hello, master!"; // This function is called when the master requests data from the slave. void onRequest() {     Wire.write(dataToSend.c_str()); // Send data as a string (char array) } // This function is called when the master sends data to the slave. // We're not expecting any specific commands, but you can expand this // function to handle any data you receive from the master. void onReceive(int howMany) {     while (Wire.available()) { // loop through all but the last         char c = Wire.read(); // receive byte as a character         Serial.print(c); // print the character     } } void setup() {   Serial.begin(115200); // Start serial communication at 115200 baud   Wire.begin(SLAVE_ADDR); // Join i2c bus with the defined slave address   Wire.onRequest(onRequest); // Register the onRequest ev

Xiic_i.h

 /****************************************************************************** * Copyright (C) 2002 - 2021 Xilinx, Inc.  All rights reserved. * SPDX-License-Identifier: MIT ******************************************************************************/ /****************************************************************************/ /** * * @file xiic_l.h * @addtogroup Overview * @{ * * This header file contains identifiers and driver functions (or * macros) that can be used to access the device in normal and dynamic * controller mode.  High-level driver functions are defined in xiic.h. * * <pre> * MODIFICATION HISTORY: * * Ver   Who  Date     Changes * ----- ---- -------- ----------------------------------------------- * 1.00b jhl  05/07/02 First release * 1.01c ecm  12/05/02 new rev * 1.01d jhl  10/08/03 Added general purpose output feature * 1.02a mta  03/09/06 Implemented Repeated Start in the Low Level Driver. * 1.03a mta  04/04/06 Implemented Dynamic IIC core routines. * 1.0

Xiic_i.c

 /****************************************************************************** * Copyright (C) 2002 - 2021 Xilinx, Inc.  All rights reserved. * SPDX-License-Identifier: MIT ******************************************************************************/ /*****************************************************************************/ /** * * @file xiic_l.c * @addtogroup Overview * @{ * * This file contains low-level driver functions that can be used to access the * device in normal and dynamic controller mode. The user should refer to the * hardware device specification for more details of the device operation. * * <pre> * MODIFICATION HISTORY: * * Ver   Who  Date     Changes * ----- --- -------   ----------------------------------------------- * 1.01b jhl 05/13/02  First release * 1.01b jhl 10/14/02  Corrected bug in the receive function, the setup of the *                     interrupt status mask was not being done in the loop such *                     that a read would someti