MCP4161 - Digital Pot
Posted: Tue May 28, 2019 3:09 am
Hi all, can anybody help with a new componente for mcp4161 digital pot?
I appreciate
Thanks Rod
I appreciate
Thanks Rod
For users to discuss using Matrix products.
https://www.matrixtsl.com/mmforums/
https://www.matrixtsl.com/mmforums/viewtopic.php?f=77&t=21266
Code: Select all
// Port Expander module connections
sbit SPExpanderRST at RF6_bit;
sbit SPExpanderCS at RA2_bit;
sbit SPExpanderRST_Direction at TRISF6_bit;
sbit SPExpanderCS_Direction at TRISA2_bit;
// End Port Expander module connections
sbit LCD_RST at RF6_bit;
sbit LCD_CS at RA2_bit;
sbit LCD_RST_TRIS at TRISF6_bit;
sbit LCD_CS_TRIS at TRISA2_bit;
sbit LCD_SCK_TRIS at TRISC3_bit;
sbit LCD_SDO_TRIS at TRISC5_bit;
//extern void Delay(void);
//extern void SDelay(void);
//*****************************************************************
// Write to MCP923S17 Port A
//*****************************************************************
void WritePortA(char b)
{
Expander_Write_PortA(0, b);
}
//*****************************************************************
// Write to MCP923S17 Port B
//*****************************************************************
void WritePortB(char b)
{
Expander_Write_PortB(0, b);
}
//*****************************************************************
// Write the data to the display
//*****************************************************************
void d_write(char b)
{
WritePortA(0x80);
Delay_ms(10);
WritePortB(b);
Nop();
Nop();
Nop();
Nop();
WritePortA(0xC0);
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
WritePortA(0x00);
//TXREG = b; //carriage return
//while(!LCD_TXSTA_TRMT); //wait for data TX
//LCD_TXSTA_TRMT = 0;
}
//*****************************************************************
// Send a instruction to the display
//*****************************************************************
void i_write(char b)
{
WritePortA(0x00);
Delay_ms(10);
WritePortB(b);
Nop();
Nop();
Nop();
Nop();
WritePortA(0x40);
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
WritePortA(0x00);
}
//*****************************************************************
// Write to line 1 of the display
//*****************************************************************
void LCDLine_1(void)
{
i_write(0x80);
}
//*****************************************************************
// Write to line 1 of the display
//*****************************************************************
void LCDLine_2(void)
{
i_write(0xC0);
}
//*****************************************************************
// To clear the display
//*****************************************************************
void LCDClear(void)
{
i_write(0x01);
}
//******************************************************************
// Function to write to the PORT
//******************************************************************
void InitWrite(char b)
{
WritePortA(0);
WritePortB(b);
Nop();
Nop();
Nop();
WritePortA(0x40);
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
Nop();
WritePortA(0);
}
//******************************************************************
// LCD Initialization function
//******************************************************************
void LCDInit(void)
{
LCD_CS_TRIS = 0;
LCD_CS = 1;
Delay_ms(10);
Delay_ms(10);
Delay_ms(10);
LCD_RST_TRIS = 0;
LCD_RST = 0;
Delay_ms(10);
LCD_RST = 1;
SPI1_Init();
Expander_Init(0);
Expander_Set_DirectionPortA(0,0x00); // Set Expander's PORTA to be output
Expander_Set_DirectionPortB(0,0x00); // Set Expander's PORTB to be output
WritePortA(0);
Delay_ms(10);
InitWrite(0x3C); //0011NFxx
Delay_ms(10);
InitWrite(0x0C); //Display Off
Delay_ms(10);
InitWrite(0x01); //Display Clear
Delay_ms(10);
InitWrite(0x06); //Entry mode
}
void main(void)
{
// Initialize the LCD display.
LCDInit();
// Switch ti LCD line 1 ( sends a command to the LCD to tell it ).
LCDLine_1();
// Write the data one char at a time.
d_write('T');
d_write('H');
d_write('A');
d_write('N');
d_write('K');
d_write('S');
LCDLine_2();
d_write('B');
d_write('I');
d_write('G');
d_write(' ');
d_write('D');
d_write('O');
d_write('G');
while(1);
}