Skip to main content
English and punctation
Source Link
winny
  • 16.8k
  • 6
  • 50
  • 71

I have a question Question regarding the adc mcp3201ADC MCP3201 interfacing with pic16f72PIC16F72 microcontroller

I provide the 1.25mhz2 MHz clock to sckSCK pin to the adcADC from picPIC clock pin.but, but how iI can receive the data from mcp3201 adc.whichMCP3201 ADC, which provides a 12 bit binary data on spiSPI pin SDI of pic.i have a question that is,bufferPIC? Buffer of picPIC is 8bit8 bit so how iI can receive the extra 4 bits from adc.ADC?

iI will share uyou my cC code plz. Please check and suggest me where iI can modify the code.

I have a question regarding the adc mcp3201 interfacing with pic16f72 microcontroller

I provide the 1.25mhz clock to sck pin to the adc from pic clock pin.but how i can receive the data from mcp3201 adc.which provides a 12 bit binary data on spi pin SDI of pic.i have a question that is,buffer of pic is 8bit so how i can receive the extra 4 bits from adc.

i will share u my c code plz check and suggest me where i can modify the code

Question regarding the ADC MCP3201 interfacing with PIC16F72 microcontroller

I provide the 1.2 MHz clock to SCK pin to the ADC from PIC clock pin, but how I can receive the data from MCP3201 ADC, which provides a 12 bit binary data on SPI pin SDI of PIC? Buffer of PIC is 8 bit so how I can receive the extra 4 bits from ADC?

I will share you my C code. Please check and suggest me where I can modify the code.

appended answer 614629 as supplemental
Source Link
SamGibson
  • 18.3k
  • 5
  • 41
  • 63

i will share u my c code plz check and suggest me where i can modify the code

#include <xc.h>
#include <PIC16F72.h>
#include "config.h"
#define _XTAL_FREQ 20000000
#define SS RA5
/***************INITIALIZING LCD MODULE**************************/
#define Data_PORT PORTB
#define Enable_pin RC6
#define RS RC7
#define CTRL_PORT_DIR TRISC
#define DATA_PORT_DIR TRISB
int LSB=0,MSB=0,FINAL_DATA=0;
/*****************************************************************/
void lcd_init(void);
void LCD_command(unsigned char command);
void LCD_data(unsigned char data);
void WriteStringToLCD(const char *s);

/**********************initiAslizing SPI*****************************/
void SPI_Initialize_Master();
unsigned SPI_Ready2Read();
char SPI_Read();
/****************************************************************/
int VALUE;

void main(void)
{
   
   SPI_Initialize_Master();
   __delay_ms(150);
   
   LCD_command(0x01);
   lcd_init();
   const char msg[] = "ADC_VALUE=";
   char a= 0x30;
   LCD_command(0x80);
   WriteStringToLCD(msg);
   while(1)
   {  
        VALUE = ADC_READ();
        LCD_command(0x8A);
        LCD_data(VALUE);
        __delay_ms(500);
   }
       
}
  


void lcd_init(void)
       {
        CTRL_PORT_DIR = 0x00;                           /* Direction of control port as Output                      */
        DATA_PORT_DIR = 0x00;                           /* Direction of data port as Output                         */
        LCD_command(0x38);                              /* LCD command - 5x7 matrix                                 */
        LCD_command(0x80);                              /* LCD command - Force cursor to the bigining of first line */
        LCD_command(0x3C);   // activate 2nd line
        LCD_command(0x0C);                              /* LCD command - Display ON, cursor OFF                     */
        LCD_command(0x01);                              /* LCD command - Clear display                              */
        }
void LCD_command(unsigned char command)
{
    RS=0;
    Data_PORT=command;
    Enable_pin=1;
    __delay_ms(5);
    Enable_pin=0;
}


void LCD_data(unsigned char data)
{
    RS=1;
    Data_PORT=data;
    Enable_pin=1;
    __delay_ms(5);
    Enable_pin=0;
}

void WriteStringToLCD(const char *s)
{
    while(*s)
    {
        LCD_data(*s++);   // print first character on LCD
    }
}


void SPI_Initialize_Master()
{
     TRISC5 = 0; // SDO pin set as output pin for data out
     TRISC4 = 1; // SDI pin set as data in pin s
     TRISC3 = 0; // SCK pin Set as output 
     TRISA5 = 0; // SS pin set as output pin for slave select
     TRISB = 0x00;
     SSPSTAT = 0b00100000; // data transmittend on falling edge of clock cycle
     SSPCON = 0b00100001; //pg 75/234  idle state for clock is low level & fosc/16 
     SS = 1;
    
}

int ADC_READ(void)
{
       SS = 0;
       SSPBUF = 0x01; // Initiate SPI bus cycle
       SSPSTATbits.BF = 0; // CLEAR THE BUFFER BIT
       while(!SSPSTATbits.BF);
       __delay_ms(10);
       MSB = SSPBUF;
       __delay_ms(10);
       
       SSPBUF = 0x81; // Initiate SPI bus cycle
       SSPSTATbits.BF = 0; // CLEAR THE BUFFER BIT
       while(!SSPSTATbits.BF);
       LSB = SSPBUF;
       __delay_ms(10);
       SS = 1;   
       
       LSB=(LSB>>1);
       MSB=(MSB<<7);
       FINAL_DATA = MSB+LSB;
       return(FINAL_DATA);
}

i will share u my c code plz check and suggest me where i can modify the code

#include <xc.h>
#include <PIC16F72.h>
#include "config.h"
#define _XTAL_FREQ 20000000
#define SS RA5
/***************INITIALIZING LCD MODULE**************************/
#define Data_PORT PORTB
#define Enable_pin RC6
#define RS RC7
#define CTRL_PORT_DIR TRISC
#define DATA_PORT_DIR TRISB
int LSB=0,MSB=0,FINAL_DATA=0;
/*****************************************************************/
void lcd_init(void);
void LCD_command(unsigned char command);
void LCD_data(unsigned char data);
void WriteStringToLCD(const char *s);

/**********************initiAslizing SPI*****************************/
void SPI_Initialize_Master();
unsigned SPI_Ready2Read();
char SPI_Read();
/****************************************************************/
int VALUE;

void main(void)
{
   
   SPI_Initialize_Master();
   __delay_ms(150);
   
   LCD_command(0x01);
   lcd_init();
   const char msg[] = "ADC_VALUE=";
   char a= 0x30;
   LCD_command(0x80);
   WriteStringToLCD(msg);
   while(1)
   {  
        VALUE = ADC_READ();
        LCD_command(0x8A);
        LCD_data(VALUE);
        __delay_ms(500);
   }
       
}
  


void lcd_init(void)
       {
        CTRL_PORT_DIR = 0x00;                           /* Direction of control port as Output                      */
        DATA_PORT_DIR = 0x00;                           /* Direction of data port as Output                         */
        LCD_command(0x38);                              /* LCD command - 5x7 matrix                                 */
        LCD_command(0x80);                              /* LCD command - Force cursor to the bigining of first line */
        LCD_command(0x3C);   // activate 2nd line
        LCD_command(0x0C);                              /* LCD command - Display ON, cursor OFF                     */
        LCD_command(0x01);                              /* LCD command - Clear display                              */
        }
void LCD_command(unsigned char command)
{
    RS=0;
    Data_PORT=command;
    Enable_pin=1;
    __delay_ms(5);
    Enable_pin=0;
}


void LCD_data(unsigned char data)
{
    RS=1;
    Data_PORT=data;
    Enable_pin=1;
    __delay_ms(5);
    Enable_pin=0;
}

void WriteStringToLCD(const char *s)
{
    while(*s)
    {
        LCD_data(*s++);   // print first character on LCD
    }
}


void SPI_Initialize_Master()
{
     TRISC5 = 0; // SDO pin set as output pin for data out
     TRISC4 = 1; // SDI pin set as data in pin s
     TRISC3 = 0; // SCK pin Set as output 
     TRISA5 = 0; // SS pin set as output pin for slave select
     TRISB = 0x00;
     SSPSTAT = 0b00100000; // data transmittend on falling edge of clock cycle
     SSPCON = 0b00100001; //pg 75/234  idle state for clock is low level & fosc/16 
     SS = 1;
    
}

int ADC_READ(void)
{
       SS = 0;
       SSPBUF = 0x01; // Initiate SPI bus cycle
       SSPSTATbits.BF = 0; // CLEAR THE BUFFER BIT
       while(!SSPSTATbits.BF);
       __delay_ms(10);
       MSB = SSPBUF;
       __delay_ms(10);
       
       SSPBUF = 0x81; // Initiate SPI bus cycle
       SSPSTATbits.BF = 0; // CLEAR THE BUFFER BIT
       while(!SSPSTATbits.BF);
       LSB = SSPBUF;
       __delay_ms(10);
       SS = 1;   
       
       LSB=(LSB>>1);
       MSB=(MSB<<7);
       FINAL_DATA = MSB+LSB;
       return(FINAL_DATA);
}
Source Link

I have a question regarding the adc mcp3201 interfacing with pic16f72 microcontroller

I provide the 1.25mhz clock to sck pin to the adc from pic clock pin.but how i can receive the data from mcp3201 adc.which provides a 12 bit binary data on spi pin SDI of pic.i have a question that is,buffer of pic is 8bit so how i can receive the extra 4 bits from adc.