Cantafford
Member
Hello,
I'm trying to make a DC motor driver in which I read the motor speed with an encoder, turn it into an digital value with the PIC's internal ADC and then display it on an LCD.
I'm trying to interface the LCD with the PIC for starters I just want the LCD to display "DC Motor driver" before any command is given to the motor. Then once I manage to do this I will continue with the code.
This is the schematic:
As you can see I have connected E to logic 1 so I can have access to the LCD, R/W to logic 0 so I can write data on the LCD and RS to logic 0 so bits D4-D7 are interpreted as commands. D4-D7 are connected to the PIC's RC2-RC5.
Here is the code:
As you can see I have created and prototyped the functions needed for the LCD(configured it in 4 bit configuration).
Then with these lines of code I'm trying to get some text on the LCD before any command is given to the motor:
When I try to simulate the program nothing pops up on the LCD, there is no text on it
.
I'm guessing that there is a problem with those 4 pins, D4-D7 I just connected them to the ADC and assigned them as inputs in the code. I suppose I have to somehow specify in the program that those pins are connected to the LCD but I don't know how. When I simulate in proteus they are shown as beiing in high-impedance.
Please help me correct this problem if possible so I can display the text on the LCD. Thank you!
I'm trying to make a DC motor driver in which I read the motor speed with an encoder, turn it into an digital value with the PIC's internal ADC and then display it on an LCD.
I'm trying to interface the LCD with the PIC for starters I just want the LCD to display "DC Motor driver" before any command is given to the motor. Then once I manage to do this I will continue with the code.
This is the schematic:

As you can see I have connected E to logic 1 so I can have access to the LCD, R/W to logic 0 so I can write data on the LCD and RS to logic 0 so bits D4-D7 are interpreted as commands. D4-D7 are connected to the PIC's RC2-RC5.
Here is the code:
Code:
/*
* File: driver.c
* Author: Paul
*
* Created on October 23, 2015, 11:06 AM
*/
#include <stdio.h>
#include <stdlib.h>
#include "project.h"
#include <plib/adc.h>
#include <plib/xlcd.h>
#include <plib/delays.h>
void init_XLCD(void); //Initialize LCD display
void DelayFor18TCY( void ); //18 cycles delay
void DelayPORXLCD (void); // Delay of 15ms
void DelayXLCD (void); // Delay of 5ms
void main()
{
OSCCON = 0x76; // set internal oscillator to 8Mhz
ADCON1 = 0x0f;
TRISA = 0b11111111;
TRISB = 0b11111111; // portB as input(the switches)
TRISC = 0b11111100; // set portC as output(RC0 = in1, RC1 = in2)
LATCbits.LATC0 = 0; // motor is not running
LATCbits.LATC1 = 0;
init_XLCD(); //Call the Initialize LCD display function
putrsXLCD("DC Motor"); //Display text
SetDDRamAddr(0x40); //shift cursor to beginning of second line
putrsXLCD("Driver"); //Display text
while(PORTBbits.RB0 == 1 && PORTBbits.RB0 == 1)
while(1)
{
if(PORTBbits.RB0 == 0 && PORTBbits.RB1 == 1 && PORTBbits.RB2 == 1) // clockwise
{LATCbits.LATC0 = 1; LATCbits.LATC1 = 0;}
if(PORTBbits.RB0 == 1 && PORTBbits.RB1 == 0 && PORTBbits.RB2 == 1) // counter clockwise
{LATCbits.LATC0 = 0; LATCbits.LATC1 = 1;}
if(PORTBbits.RB2 == 0) // motor stops
{LATCbits.LATC0 = 1; LATCbits.LATC1 = 1;}
}
}
void init_XLCD(void) //Initialize LCD display
{
OpenXLCD(FOUR_BIT&LINES_5X7); //configure LCD in 4-bit Data Interface mode
//and 5x7 characters, multiple line display
while(BusyXLCD()); //Check if the LCD controller is not busy
//before writing some commands?
WriteCmdXLCD(0x06); // move cursor right, don?t shift display
WriteCmdXLCD(0x0C); //turn display on without cursor
}
void DelayFor18TCY( void ) //18 cycles delay
{
//Delay10TCYx(20);
Nop( ); Nop( ); Nop( ); Nop( ); // 18 cycle delay
Nop( ); Nop( ); Nop( ); Nop( );
Nop( ); Nop( ); Nop( ); Nop( );
Nop( ); Nop( );
return;
}
void DelayPORXLCD (void) // Delay of 15ms
{
Delay1KTCYx(30);
}
void DelayXLCD (void) // Delay of 5ms
{
Delay1KTCYx(10);
}
As you can see I have created and prototyped the functions needed for the LCD(configured it in 4 bit configuration).
Then with these lines of code I'm trying to get some text on the LCD before any command is given to the motor:
Code:
init_XLCD(); //Call the Initialize LCD display function
putrsXLCD("DC Motor"); //Display text
SetDDRamAddr(0x40); //shift cursor to beginning of second line
putrsXLCD("Driver"); //Display text
while(PORTBbits.RB0 == 1 && PORTBbits.RB0 == 1)
When I try to simulate the program nothing pops up on the LCD, there is no text on it
I'm guessing that there is a problem with those 4 pins, D4-D7 I just connected them to the ADC and assigned them as inputs in the code. I suppose I have to somehow specify in the program that those pins are connected to the LCD but I don't know how. When I simulate in proteus they are shown as beiing in high-impedance.
Please help me correct this problem if possible so I can display the text on the LCD. Thank you!