Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC16F1508 and MCP9801 simulation in Proteus

Status
Not open for further replies.

sr2w

Junior Member level 1
Junior Member level 1
Joined
Jul 12, 2017
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
156
1) I am trying to read the ambient temperature register in MCP9801 with the following code. My simulation is getting stuck on one line (highlighted in code below). I have attached the Simulation log.JPG.



2) I have referred to the the relevant discussions previously done, but still

wasn't able to figure the problem in my code.

https://www.microchip.com/forums/m956027.aspx

https://www.microchip.com/forums/m852246.aspx



3) It's been two weeks I have started with MPLAB and PIC controllers. I have written Blinky LED for PIC16F1508, 688 and 1887. Also I have done UART communication using PIC16F1887.



Code:
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include"pic16f1508.h"

#define _XTAL_FREQ 16000000

void initialise()
{
INTCONbits.GIE = 0; // GLOBAL INTERRUPTS DISABLED
INTCONbits.PEIE = 0; // PERIPHERAL INTERRUPTS DISABLED
PIE3 = 0; // INTERRUPTs DISABLED 

SSP1STATbits.SMP = 1; // Slew rate control disabled for Standard Speed mode (100 kHz and 1 MHz)
SSP1STATbits.CKE = 0; // Disable SMBus specific inputs
SSP1ADD = 0x03; // CLOCK OF 31.25 KHZ SET
SSP1MSK = 0; // NO MASK 
TRISBbits.TRISB4 = 1; // 
TRISBbits.TRISB6 = 1;
ANSELB = 0;

PIE1bits.SSP1IE = 0;
SSP1CON1bits.WCOL = 0; // 1 - I2C CAN'T BE STARTED, 0 - GOOD TO GO
SSP1CON1bits.SSPOV = 0;// 1 - BYTE RECEIVED WHEN SSP1BUF STILL HOLDING LAST BYTE
                                       // 0 - GOOD TO GO
SSP1CON1bits.SSPEN = 1; // ENABLE I2C
SSP1CON1bits.CKP = 0;
SSP1CON1bits.SSPM0 = 0;
SSP1CON1bits.SSPM1 = 0;
SSP1CON1bits.SSPM2 = 0;
SSP1CON1bits.SSPM3 = 1; // SSPM - 1000, MASTER MODE SELECTED

SSP1CON2 = 0x00;
SSP1BUF = 0;
TRISC = 1;
}

void first_write()
{
SSP1CON2bits.SEN = 1; // START I2C

while(SSP1CON2bits.SEN | SSP1STATbits.R_nW); // WAIT -(I GET STUCK OVER HERE!!!)

SSP1BUF = 0x90; // 1001 - DEFAULT ADDRESS(MCP9801), 000 - I HAVE SET THE 
                           // LAST THREE BITS OF ADDRESS (MCP9801), 0 - WRITE

while(SSP1CON2bits.ACKSTAT); // SEE IF ACKNOWLEDGEMENT HAS BEEN RECEIVED//
SSP1BUF = 0; // TO SET THE REGISTER POINTER TO 00 FOR TEMPERATURE

SSP1CON2bits.PEN = 1; // STOP I2C
}
void one_read()
{
SSP1CON2bits.SEN = 1;
SSP1BUF = 0x91; // 1001 - DEFAULT ADDRESS, 000 - I HAVE SET THE LAST THREE

                           //  BITS OF ADDRESS (MCP9801), 1 - READ
                         
while(0 == SSP1STATbits.BF); // WAIT WHILE RECEPTION NOT COMPLETE
SSP1CON2bits.ACKDT = 0; // SEND ACKNOWLEDGEMENT
SSP1CON2bits.PEN = 1; // STOP I2C
PORTC = SSP1BUF; // 

}
void main(void)
{
        {
             initialise();
             first_write();
             one_read(); 
        }
}
Circuit.JPGSimulation log.JPG
 

In Proteus the I2C Pull-up resistors for 100 KHz I2C Clock should be 4.7k and DIGITAL type.
 
  • Like
Reactions: sr2w

    sr2w

    Points: 2
    Helpful Answer Positive Rating
Thanks for that! Does the code look okay ?
 

Also I have set 31.25 kHz clock frequency in SSP1BUF register(0x03).
 

If code is correct then after making the pullup resistors 4.7k DIGITAL type then you should get the readings.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top