Skip to content
Permalink
35c29abe63
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
366 lines (362 sloc) 29 KB
/*==================================================================================*/
#include "DL1416.h" // Include DL1416 library file */
#ifdef xc8 // If XC8 Compiler is used */
#include "mcc_generated_files/mcc.h" // Include generated libraries if used */
#endif // */
/*==================================================================================*/
void DL1416_Init() // Initialisation function */
{ // */
#ifdef DATA_PORTA // If DL1416 data lines are on PORTA */
#ifdef c18 // If C18 is used - supports PIC18F4520 */
ADCON1 = 0x0F; // Analogue pins On PORTA set to digital*/
CMCON = 0b111; // Disable PORTA Comparators */
#endif // */
#ifdef xc8 // If XC8 is used - no support for F4520*/
ANSELbits.ANS0 = 0; // Disable analogue functions on RA0 */
ANSELbits.ANS1 = 0; // Disable analogue functions on RA1 */
ANSELbits.ANS2 = 0; // Disable analogue functions on RA2 */
ANSELbits.ANS3 = 0; // Disable analogue functions on RA3 */
ANSELbits.ANS4 = 0; // Disable analogue functions on RA5 */
SLRCONbits.SLRA = 0; // Set PORTA slew rate to standard */
#endif // */
#define DATA_PORT LATA // DATA_PORT macro is LATA */
#define TRIS_DATA_PORT TRISA // TRIS_DATA_PORT macro is TRISA */
#define DL1416_D0 LATAbits.LATA0 // Used to control cursor operations */
#endif // */
#ifdef CTRL_PORTA // If DL1416 control lines are on PORTA */
#ifdef c18 // If C18 is used - supports PIC18F4520 */
ADCON1 = 0x0F; // Analogue pins On PORTA set to digital*/
CMCON = 0b111; // Disable PORTA Comparators */
#endif // */
#ifdef xc8 // If XC8 is used - no support for F4520*/
ANSELbits.ANS0 = 0; // Disable analogue functions on RA0 */
ANSELbits.ANS1 = 0; // Disable analogue functions on RA1 */
ANSELbits.ANS2 = 0; // Disable analogue functions on RA2 */
ANSELbits.ANS3 = 0; // Disable analogue functions on RA3 */
ANSELbits.ANS4 = 0; // Disable analogue functions on RA5 */
SLRCONbits.SLRA = 0; // Set PORTA slew rate to standard */
#endif // */
#define CTRL_PORT LATA // CTRL_PORT macro is LATA */
#define TRIS_CTRL_PORT TRISA // TRIS_CTRL_PORT macro is TRISA */
#define DL1416_A0 LATAbits.LATA0 // Pin A0 is at LATA bit 0 */
#define DL1416_A1 LATAbits.LATA1 // Pin A1 is at LATA bit 1 */
#define DL1416_CU LATAbits.LATA2 // Pin CU is at LATA bit 2 */
#define DL1416_WR LATAbits.LATA3 // Pin WR is at LATA bit 3 */
#ifdef DL1416_SINGLE // If single DL1416 is used/defined */
#define DL1416_CE0 LATAbits.LATA4 // Pin CE is at LATA bit 4 (default) */
#endif // */
#endif // */
/*==================================================================================*/
#ifdef DATA_PORTB // If DL1416 data lines are on PORTB */
#ifdef c18 // If C18 is used - supports PIC18F4520 */
ADCON1 = 0x07; // Analogue pins On PORTB set to digital*/
#endif // */
#ifdef xc8 // If XC8 is used - no support for F4520*/
ANSELH = 0; // Set all PORTB pins to digital */
#endif // */
INTCON2bits.RBPU = 1; // Internal port B Pull-Ups off */
#define DATA_PORT LATB // DATA_PORT macro is LATB */
#define TRIS_DATA_PORT TRISB // TRIS_DATA_PORT macro is TRISB */
#define DL1416_D0 LATBbits.LATB0 // Used to control cursor operations */
#endif // */
#ifdef CTRL_PORTB // If DL1416 control lines are on PORTB */
#ifdef c18 // If C18 is used - supports PIC18F4520 */
ADCON1 = 0x07; // Analogue pins On PORTB set to digital*/
#endif // */
#ifdef xc8 // If XC8 is used - no support for F4520*/
ANSELH = 0; // Set all PORTB pins to digital */
#endif // */
INTCON2bits.RBPU = 1; // Internal port B Pull-Ups off */
#define CTRL_PORT LATB // CTRL_PORT macro is LATB */
#define TRIS_CTRL_PORT TRISB // TRIS_CTRL_PORT macro is TRISB */
#define DL1416_A0 LATBbits.LATB0 // Pin A0 is at LATB bit 0 */
#define DL1416_A1 LATBbits.LATB1 // Pin A1 is at LATB bit 1 */
#define DL1416_CU LATBbits.LATB2 // Pin CU is at LATB bit 2 */
#define DL1416_WR LATBbits.LATB3 // Pin WR is at LATB bit 3 */
#ifdef DL1416_SINGLE // If single DL1416 is used/defined */
#define DL1416_CE0 LATBbits.LATB4 // Pin CE is at LATB bit 4 (default) */
#endif // */
#endif // */
/*==================================================================================*/
#ifdef DATA_PORTC // If DL1416 data lines are on PORTC */
#define DATA_PORT LATC // DATA_PORT macro is LATC */
#define TRIS_DATA_PORT TRISC // TRIS_DATA_PORT macro is TRISC */
#define DL1416_D0 LATCbits.LATC0 // Used to control cursor operations */
#endif // */
#ifdef CTRL_PORTC // If DL1416 control lines are on PORTC */
#define CTRL_PORT LATC // CTRL_PORT macro is LATC */
#define TRIS_CTRL_PORT TRISC // TRIS_CTRL_PORT macro is TRISC */
#define DL1416_A0 LATCbits.LATC0 // Pin A0 is at LATC bit 0 */
#define DL1416_A1 LATCbits.LATC1 // Pin A1 is at LATC bit 1 */
#define DL1416_CU LATCbits.LATC2 // Pin CU is at LATC bit 2 */
#define DL1416_WR LATCbits.LATC3 // Pin WR is at LATC bit 3 */
#ifdef DL1416_SINGLE // If single DL1416 is used/defined */
#define DL1416_CE0 LATCbits.LATC4 // Pin CE is at LATC bit 4 (default) */
#endif // */
#endif // */
/*==================================================================================*/
#ifdef DATA_PORTD // If DL1416 data lines are on PORTD */
#define DATA_PORT LATD // DATA_PORT macro is LATD */
#define TRIS_DATA_PORT TRISD // TRIS_DATA_PORT macro is TRISD */
#define DL1416_D0 LATDbits.LATD0 // Used to control cursor operations */
#endif // */
#ifdef CTRL_PORTD // If DL1416 control lines are on PORTD */
#define CTRL_PORT LATD // CTRL_PORT macro is LATD */
#define TRIS_CTRL_PORT TRISD // TRIS_CTRL_PORT macro is TRISD */
#define DL1416_A0 LATDbits.LATD0 // Pin A0 is at LATD bit 0 */
#define DL1416_A1 LATDbits.LATD1 // Pin A1 is at LATD bit 1 */
#define DL1416_CU LATDbits.LATD2 // Pin CU is at LATD bit 2 */
#define DL1416_WR LATDbits.LATD3 // Pin WR is at LATD bit 3 */
#ifdef DL1416_SINGLE // If single DL1416 is used/defined */
#define DL1416_CE0 LATDbits.LATD4 // Pin CE is at LATD bit 4 (default) */
#endif // */
#endif // */
/*==================================================================================*/
TRIS_DATA_PORT = 0x00; // Configure Data port as output */
TRIS_CTRL_PORT = 0x00; // Configure Control port as output */
DATA_PORT = 0x20; // If display latches data, latch blank */
#ifdef DL1416_SINGLE // */
DL1416_Blank_Display(); // Blank DL1416 */
#endif // */
#ifdef DL1416_MUX // If multiple DL1416 displays are used */
#ifdef DL1416_DUAL // */
DL1416_Blank_Display(0); // Blank first DL1416 */
DL1416_Blank_Display(1); // Blank second DL1416 */
#endif // */
#ifdef DL1416_TRIPPLE // */
DL1416_Blank_Display(0); // Blank first DL1416 */
DL1416_Blank_Display(1); // Blank second DL1416 */
DL1416_Blank_Display(2); // Blank third DL1416 */
#endif // */
#ifdef DL1416_QUAD // */
DL1416_Blank_Display(0); // Blank first DL1416 */
DL1416_Blank_Display(1); // Blank second DL1416 */
DL1416_Blank_Display(2); // Blank third DL1416 */
DL1416_Blank_Display(3); // Blank fourth DL1416 */
#endif // */
#endif // */
} // */
//==================================================================================*/
void DL1416_Digit_Sel(char digit) // Function to address individual digits*/
{ // of currently enable DL1416 */
if(digit == DL1416_DIG1) // If received digit is the same DIG1 */
{ // */
DL1416_A0 = 0; // Set A0 to low */
DL1416_A1 = 0; // Set A1 to low */
} // */
if(digit == DL1416_DIG2) // If received digit is the same DIG2 */
{ // */
DL1416_A0 = 1; // Set A0 to high */
DL1416_A1 = 0; // Set A1 to low */
} // */
if(digit == DL1416_DIG3) // If received digit is the same DIG3 */
{ // */
DL1416_A0 = 0; // Set A0 to low */
DL1416_A1 = 1; // Set A1 to high */
} // */
if(digit == DL1416_DIG4) // If received digit is the same DIG4 */
{ // */
DL1416_A0 = 1; // Set A0 to high */
DL1416_A1 = 1; // Set A1 to high */
} // */
} // */
//==================================================================================*/
#ifdef DL1416_SINGLE // If only a single DL1416 is used */
void DL1416_Print_C(char data,char dig_sel) // Prints char on specific digit */
{ // */
DL1416_CE0 = 0; // Enable CE pin for first DL1416 */
DL1416_CU = 1; // Disable Cursor Control */
DL1416_Digit_Sel(dig_sel); // Configure the address pins */
DL1416_WR = 0; // Activate the Write pin */
// */
DATA_PORT = data; // Latch the data out from DATA_PORT */
// */
Nop(); // Execute a NOP, DL1416 timing */
DL1416_WR = 1; // Disable the Write pin */
DL1416_CU = 0; // Enable the cursor control */
DL1416_CE0 = 1; // Disable display 1 enable pin */
} // */
//==================================================================================*/
void DL1416_Blank_Display() // Function to blank a DL1416 */
{ // */
unsigned int i = 0; // Array index variable */
for(i = 0; i < 4; i++) // Loop through & load the space char */
{ // essentially clearing each digit */
DL1416_Print_C(DL1416_space, i); // Load space to each digit */
} // */
} // */
#endif // */
//==================================================================================*/
void DL1416_Cursor_Ctrl(char dig_sel,char cmd)//Function to control cursor */
{ // */
DL1416_CE0 = 0; // Enable CE pin for first DL1416 */
DL1416_CU = 0; // Disable Cursor Control */
DL1416_WR = 0; // Activate the Write pin */
// */
DL1416_Digit_Sel(dig_sel); // Address specified digit of DL1416 */
// */
if(cmd == CMD_CUR_STORE) // If command to store was received */
{ // */
DL1416_D0 = 1; // Latch D0 of DL1416 to 1 to store */
} // */
if(cmd == CMD_CUR_CLEAR) // If command to clear was received */
{ // */
DL1416_D0 = 0; // Latch D0 of DL1416 to 0 to clear */
} // */
DL1416_WR = 1; // Disable the Write pin */
Nop(); // Execute a NOP, DL1416 timing */
DL1416_CU = 1; // Enable the cursor control */
DL1416_CE0 = 1; // Disable display 1 enable pin */
} // */
//==================================================================================*/
#ifdef DL1416_MUX // If multiple DL1416 displays are used */
void DL1416_MUX_Print_C(char data, char dig_sel, char disp_sel) // */
{ // Sequence of inputting data to DL1416 */
if(disp_sel == 0) // If first DL1416 is selected */
{ // */
DL1416_CE0 = 0; // Enable CE pin for first DL1416 */
} // */
if(disp_sel == 1) // If second DL1416 is selected */
{ // */
DL1416_CE1 = 0; // Enable CE pin for second DL1416 */
} // */
#ifdef DL1416_TRIPPLE || DL1416_QUAD // */
if(disp_sel == 2) // */
{ // */
DL1416_CE2 = 0; // Enable CE pin for third DL1416 */
} // */
#endif // */
#ifdef DL1416_QUAD // */
if(disp_sel == 3) // */
{ // */
DL1416_CE3 = 0; // Enable CE pin for fourth DL1416 */
} // */
#endif // */
DL1416_CU = 1; // Disable Cursor Control */
DL1416_Digit_Sel(dig_sel); // Configure the address pins */
DL1416_WR = 0; // Activate the Write pin */
// */
DATA_PORT = data; // Latch the data out from DATA_PORT */
// */
Nop(); // Execute a NOP, DL1416 timing */
DL1416_WR = 1; // Disable the Write pin */
DL1416_CU = 0; // Enable the cursor control */
if(disp_sel == 0) // If first DL1416 is selected */
{ // */
DL1416_CE0 = 1; // Disable display 1 enable pin */
} // */
if(disp_sel == 1) // If second DL1416 is selected */
{ // */
DL1416_CE1 = 1; // Disable CE pin for second DL1416 */
} // */
#ifdef DL1416_TRIPPLE || DL1416_QUAD // */
if(disp_sel == 2) // */
{ // */
DL1416_CE2 = 1; // Disable CE pin for third DL1416 */
} // */
#endif // */
#ifdef DL1416_QUAD // */
if(disp_sel == 3) // */
{ // */
DL1416_CE3 = 1; // Disable CE pin for fourth DL1416 */
} // */
#endif // */
} // */
//==================================================================================*/
void DL1416_Blank_MUX_Display(char disp_sel)// Function to blank a DL1416 */
{ // */
unsigned int i = 0; // Array index variable */
for(i = 0; i < 4; i++) // Loop through & load the space char */
{ // essentially clearing each digit */
DL1416_Print_C(DL1416_space,i, disp_sel);// Load space to each digit */
} // */
} // */
//==================================================================================*/
void DL1416_WriteTo_MUX_Display(char *data, char cmd) // Writes data to display */
{ // */
unsigned int itr = 0; // Variable used to go though data array*/
while(itr < 7) // While itr is less than 7 */
{ // */
if(itr <= 3) // Check if itr is less or equal to 3 */
{ // */
DL1416_Print_C(data_in[itr], itr, 0); // Load data to 1st 3 digits */
} // */
if(itr >= 3) // Check if itr is more or equal to 4 */
{ // */
DL1416_Print_C(data_in[itr+1],itr-3,1);// Load data to 2nd 4 digits */
} // */
itr++; // Increment indexing variable */
if(cmd == DL1416_MUX_ON) // If DL1416 is MUXed include delay */
{ // */
#ifdef c18 // */
Delay1KTCYx(0); // Delay for a bit */
#endif // */
#ifdef xc8 // */
__delay_ms(500); // Delay for a bit */
#endif // */
} // */
} // */
} // */
//==================================================================================*/
void DL1416_MUX_Cursor_Ctrl(char dig_sel, char disp_sel, char cmd) // */
{ // */
if(disp_sel == 0)
{ // */
DL1416_CE0 = 0;
} // */
if(disp_sel == 1)
{ // */
DL1416_CE1 = 0;
} // */
#ifdef DL1416_TRIPPLE || DL1416_QUAD
if(disp_sel == 1)
{ // */
DL1416_CE2 = 0;
} // */
#endif // */
#ifdef DL1416_QUAD
if(disp_sel == 1)
{ // */
DL1416_CE3 = 0;
} // */
#endif // */
DL1416_CU = 0;
DL1416_WR = 0;
// */
DL1416_Digit_Sel(dig_sel);
// */
if(cmd == CMD_CUR_STORE) // If command to store was received */
{ // */
DL1416_D0 = 1; // Latch D0 of DL1416 to 1 to store */
} // */
if(cmd == CMD_CUR_CLEAR) // If command to clear was received */
{ // */
DL1416_D0 = 0; // Latch D0 of DL1416 to 0 to clear */
} // */
DL1416_WR = 1;
Nop();
DL1416_CU = 1;
// */
if(disp_sel == 0)
{ // */
DL1416_CE0 = 1;
} // */
if(disp_sel == 1)
{ // */
DL1416_CE1 = 1;
} // */
#ifdef DL1416_TRIPPLE || DL1416_QUAD
if(disp_sel == 1)
{ // */
DL1416_CE2 = 1;
} // */
#endif // */
#ifdef DL1416_QUAD
if(disp_sel == 1)
{ // */
DL1416_CE3 = 1;
} // */
#endif // */
} // */
//==================================================================================*/
#endif