PDA

View Full Version : Using LCD from Mechatronics Demo Board



Michlis
- 24th April 2007, 14:32
Hi,
I have a Microchip's Mechatronics Demo Board and I am trying to use on board LCD with PBP. In the PBP manual it says that: "If a 4-bit bus is used the top 4 LCD data bits must be connected to either the bottom 4 or top 4 bits of one port."
Now the problem is that LCD is already pre-connected to the PIC and as it says in the data sheet fist 4 ports are COM0-COM3. So I took the board and it looks that COM0 is on pin RB4, COM1 is RB5, COM2 RA2, COM3 RD0. Is it possible to run this LCD in PBP with such connections? How should I set DEFINEs?

skimask
- 24th April 2007, 14:37
Hi,
I have a Microchip's Mechatronics Demo Board and I am trying to use on board LCD with PBP. In the PBP manual it says that: "If a 4-bit bus is used the top 4 LCD data bits must be connected to either the bottom 4 or top 4 bits of one port."
Now the problem is that LCD is already pre-connected to the PIC and as it says in the data sheet fist 4 ports are COM0-COM3. So I took the board and it looks that COM0 is on pin RB4, COM1 is RB5, COM2 RA2, COM3 RD0. Is it possible to run this LCD in PBP with such connections? How should I set DEFINEs?

It's possible to run that LCD with a PIC, just not with the LCDOUT commands.
The LCDOUT commands used in PBP with the PICs are for LCDs with built-in Hitachi 44780 style controllers with a parallel interface.
Judging from the connector, what you've got is probably a 'dumb' LCD. You'll most likely have to dig up the spec's for the LCD, write a program to handle the multiplexing, etc.etc.etc.
If you want an LCD, it's a heck of a lot easier to get on eBay or wherever and just buy a 16x2 LCD from somewhere for $10.

Michlis
- 24th April 2007, 17:49
Judging from the connector, what you've got is probably a 'dumb' LCD. You'll most likely have to dig up the spec's for the LCD, write a program to handle the multiplexing, etc.etc.etc.
I have found the datasheet here:
http://www.varitronix.com/Product/LCD/VIM-332-DP(R0).pdf
but I don't understand the table at the end of it. I guess it's the most important part.


If you want an LCD, it's a heck of a lot easier to get on eBay or wherever and just buy a 16x2 LCD from somewhere for $10.
Ok, now I know that, but unfortunately I have to stick to this LCD.

How should I write a PBP code to handle this LCD, what do I need to take care of, in which order?
I'd be grateful for any hints.

skimask
- 24th April 2007, 17:58
I have found the datasheet here:
http://www.varitronix.com/Product/LCD/VIM-332-DP(R0).pdf
but I don't understand the table at the end of it. I guess it's the most important part.

Basically, that table says that if you put power (whatever that power may be according to the datasheet) on pin #5 and a ground on COM1, then the 'RC' will show on the LCD.

PBP will NOT drive this LCD thru it's built in commands. As I said before, this is a 'dumb' LCD.

You're going to need 14 pins from a PIC to provide power to a segment, and 4 MOSFETs/transistors to apply a ground to a COMmon.
Then you're going to have to write software to drive the LCD, multiplexing various signals to get it to display what you want to display. Then you're going to have to get it to do this roughly 20+ times per second so your eyes don't see any flickering.

You HAVE to stick with this LCD... :p This LCD is going to 'cost' at least 18 pins from a PIC and a LOAD of code and headaches... I'd talk to whoever is making you do this...and slap them up a bit... :)
But if you must, do some searching here, there's a few projects around here that deal with multiplexing a display,etc.

Michlis
- 25th April 2007, 09:39
Ok, that sounds quite tricky ;)
PIC16F917 has some LCD module. Maybe it's possible to use it, so that it will be easier and simpler to drive this 'dumb' LCD? What kind of functionality does this LCD module provide?

BobK
- 25th April 2007, 13:34
Hi Michlis,

The LCD on your demo board is similar to driving a 7 segment display. Your program will need to output the data to the first display digit, then to the second, then to the third, etc. There are many types of LCD displays out there. The ones that are used with PBP are quite different from the one on your demo board. The PBP LCDOUT routines will not work with the type of LCD display that you have. I just took aglance at microchip's website and there seems to be alot of reading material in relation to their LCD PICs. The 16F917 is a specialty chip with a built in LCD driver so you need to learn how to address that driver to get information displayed. The built-in driver probably explains why the chip has a large program memory, 14K!

Didn't your demo board come with sample applications? If so, why don't you use the information there to create an assembly routine to operate the display within a PBP program.

I personally use the regular LCD displays in either a serial or parallel manner whereby I can use LCDOUT or Serout2 commands to display data quick and simple!

HTH,

BobK

Michlis
- 9th May 2007, 11:48
After all, the LCD works. Here is the code that I use to display "1234":

PAUSE 1000 'wait for LCD start up

LCDPS = %00110001 'Selecting the frame prescale

LCDSE0.0 = 1 'Segment pins
LCDSE0.1 = 1
LCDSE0.2 = 1
LCDSE0.3 = 1
LCDSE0.6 = 1
LCDSE1.3 = 1
LCDSE2.0 = 1
LCDSE2.5 = 1
LCDSE2.6 = 1
LCDSE2.7 = 1

LCDCON = %01000011 'Multiplex,bias,timing, sleep

LCDDATA0 = %01001000 'initial LCD values "1234"
LCDDATA1 = %00001000
LCDDATA2 = %10100000
LCDDATA3 = %00000000
LCDDATA4 = %00001000
LCDDATA5 = %11100000
LCDDATA6 = %00001100
LCDDATA7 = %00000000
LCDDATA8 = %10100000
LCDDATA9 = %01001000
LCDDATA10 = %00000000
LCDDATA11 = %00000000

PIR2.4 = 0 'clearing LCD interrupt flag

LCDCON = %01010011 'enabling bias voltage pins
LCDCON = %11010011 'enabling the LCD module

however, I have problems when trying to run PWM module while using LCD. I will post about it soon.

Michlis
- 9th May 2007, 12:29
As mentioned above, I have problems when trying to use LCD (code above) and HPWM at the same time.

This is my HPWM program:

'Connections:
'SW2->RD1 increase switch
'SW3->RA4 decrease switch
'P1->Vdd motor turned on constantly
'RC5/CCP1->N2 CCP1 is pwm output pin
'DC motor is connected to DRIVE 1 and DRIVE 2



'HPWM initialization
duty VAR WORD ' Duty cycle value )

TRISC.5 = 0 ' Set PORTC.5 (CCP1) to output
CCP1CON = %00001100 ' Set CCP1 to PWM

T2CON = %00000101 ' Turn on Timer2, Prescale=4

PR2 = 249 ' Set PR2 to get 1KHz out

duty = 500 ' Set duty cycle to 50%


up var PORTD.1 'user-friendly names for ports
down var PORTA.4

'Main program loop
loop:

CCP1CON.4 = duty.0 ' Store duty to registers as
CCP1CON.5 = duty.1 ' a 10-bit word
CCPR1L = DUTY >> 2

'check if button "up" is pressed and duty is not maximum
IF (up=0) AND (duty<1000) THEN
duty=duty+50
PAUSE 200
ENDIF

'similar as before but for reducing the speed
IF (down=0) AND (duty>0) THEN
duty=duty-50
PAUSE 200
ENDIF

GoTo loop ' Do it forever
End

When I combine these two programs (first LCD then HPWM) it starts to work that is I get "1234" on the LCD and then motor starts to turn but only for 2-3sec. Later is just stops. It looks like PWM signal just dies...?!
I have no idea why these two modules (LCD and HPWM) cannot work togather? I have checked the pins and timing sources but don't see any possible conflicts?

skimask
- 9th May 2007, 19:39
IF (down=0) AND (duty>0) THEN
duty=duty-50 : PAUSE 200
ENDIF


If duty is 10 and you subtract 50 from it, you'll end up with a negative number, which PBP doesn't handle. I think you want the lines to be:
IF (down = 0) AND (duty => 50) THEN blah blah blah...

mister_e
- 9th May 2007, 23:02
Nah, PBP handle it. if 0-50 in a byte variable will return 205 or 206.

skimask
- 10th May 2007, 03:56
Nah, PBP handle it. if 0-50 in a byte variable will return 205 or 206.

But 'duty' is a word and, if it does end up being a 'negative number', it'll be above the 1000 limit set in the IF/THEN above and nothing will happen to 'duty' and the program will appear to go stupid.

mister_e
- 10th May 2007, 04:04
<table><td>http://www.mister-e.org/Pics/DOH</td><td>hum hum... pfff i knew... it was a test to know if you follow... HUM HUM</td><td>http://www.venetosport.it/fibs/immagini/strikeout.gif</td></table>

skimask
- 10th May 2007, 04:20
hum... pfff i knew... it was a test to know if you follow... HUM HUM
Do I get anything as a prize?

mister_e
- 10th May 2007, 04:42
My respect for few days... or some of those...
http://www.mister-e.org/Pics/Beer_6pack.gif
:D

Michlis
- 10th May 2007, 09:08
Ups, you're right. I will correct it today, but I don't think that this is the main problem, because I don't use the buttons to change the speed and the motor just stops.
However, that gave me smth to think about. Maybe somehow now the pin connected to the "decrease" button is by default low, so in each loop program reduces the speed by one step, even though I didn't press anything?
Maybe I should somehow configure the pins connected to buttons to detect button press correctly?

Michlis
- 11th May 2007, 18:41
If duty is 10 and you subtract 50 from it, you'll end up with a negative number

You are of course right, but I start the program with duty=500 and use only +/-50 steps, so this IF statement is correct in my case.

After some time I found the bug. At first I set all LCDSEn registers and it was a mistake since the LCD uses only few pins, so my button input pins were in segment functionality instead of I/O. Now I only set the segment pins that are actually used by LCD.