using pic18f4520 to program digital pot(mcp41100)

Status
Not open for further replies.

rohit21agrawal

Newbie level 2
Newbie level 2
Joined
Mar 17, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
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.
 


ok in your code u r send 0x11 and 0xff what is this? u r not send the wiper position value.
 

0x11 is the command byte while 0xFF is the wiper position code.
 

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.[/QUOTE]

I have done your project too but i used to use mikroC by the way i put the codes maybe it can help you
void main()
{
unsigned char res ;
Spi_Init_Advanced(MASTER_OSC_DIV4,DATA_SAMPLE_End,CLK_IDLE_HIGH , HIGH_2_LOW) ;
res=0;
portc.f0=0;
Trisc.f0=0;
while(1)
{
portc.f0=0;
Spi_Write(17);
Spi_Write(karno[res]);
portc.f0=1;
delay_ms(200);
res++;
}}
in this project i were changing the resistor of digital pot and controlled the color of the tft LCD
 

Status
Not open for further replies.

Similar threads