rohit21agrawal
Newbie level 2

Programming digital pot using pic18f4520
I am trying to program mcp41100 digital pot using pic18f4520 spi communication.
I am using the following code on MPLAB C18 compiler and am using a picdem 2 plus demo board :
#include <p18cxxx.h> //pic 18 library for all p18 microP
#include <spi.h> // SPI Library
#define SPI_CS LATCbits.LATC2 // Setting RC2 (pin#17) of the PIC as Chip Select)
void main()
{
OSCCON = 0b01110110; //using the internal oscillator of the micro P
LATC = 0x00 ;
LATB = 0x00 ;
TRISC = 0x00; //Setting port c as output
TRISB = 0x00 ; //setting port B as output to test
SPI_CS =1; // chip select =1
OpenSPI(SPI_FOSC_64, MODE_00,SMPEND);
SPI_CS =0;
WriteSPI (0x11); //command byte 00010001
WriteSPI(0xFF); //Dn = 255
LATCbits.LATC1 =1;
LATBbits.LATB1 =1;
SPI_CS =1;
CloseSPI();
while(1);
{
}
}
can anyone tell me if there is a problem in this code ? or an alternative to this?
when i run this on the microP ..nothing happens at all.. the resistance does not change.. the led that i connect at port rc1 and rb1 also do not light up.. please help.
I am trying to program mcp41100 digital pot using pic18f4520 spi communication.
I am using the following code on MPLAB C18 compiler and am using a picdem 2 plus demo board :
#include <p18cxxx.h> //pic 18 library for all p18 microP
#include <spi.h> // SPI Library
#define SPI_CS LATCbits.LATC2 // Setting RC2 (pin#17) of the PIC as Chip Select)
void main()
{
OSCCON = 0b01110110; //using the internal oscillator of the micro P
LATC = 0x00 ;
LATB = 0x00 ;
TRISC = 0x00; //Setting port c as output
TRISB = 0x00 ; //setting port B as output to test
SPI_CS =1; // chip select =1
OpenSPI(SPI_FOSC_64, MODE_00,SMPEND);
SPI_CS =0;
WriteSPI (0x11); //command byte 00010001
WriteSPI(0xFF); //Dn = 255
LATCbits.LATC1 =1;
LATBbits.LATB1 =1;
SPI_CS =1;
CloseSPI();
while(1);
{
}
}
can anyone tell me if there is a problem in this code ? or an alternative to this?
when i run this on the microP ..nothing happens at all.. the resistance does not change.. the led that i connect at port rc1 and rb1 also do not light up.. please help.