PDA

View Full Version : 16F872 and LCD



Fredrick
- 14th January 2008, 17:01
How do i know the right pins i should connect my LCD display to? or can i select my own pins in my program?

mister_e
- 14th January 2008, 17:03
The manual show the default connections. You can also select your own and add some DEFINEs at the top of your program.


'
' LCD setup
' =========
DEFINE LCD_DREG PORTB ' LCD data port
DEFINE LCD_DBIT 0 ' LCD data starting bit
DEFINE LCD_RSREG PORTB ' LCD register select port
DEFINE LCD_RSBIT 4 ' LCD register select bit
DEFINE LCD_EREG PORTB ' LCD enable port
DEFINE LCD_EBIT 5 ' LCD enable bit
DEFINE LCD_BITS 4 ' LCD data bus size
DEFINE LCD_LINES 2 ' Number lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us

Fredrick
- 14th January 2008, 17:26
But the manual doese´t shows the default connections for 16F872, what are the defaults for my PIC?

Can i want use RB1 to RB6 insted och the default or does i have to use pin´s from outher ports?

btw why does the PIC have diffrent ports like PORTA, PORTB, PORTC..

And yes i´m new to PIC programing and i have just get my LED to blink when i push a button :D

mister_e
- 14th January 2008, 17:42
But the manual doese´t shows the default connections for 16F872, what are the defaults for my PIC?
Don't worry, the default one are the same for all PIC model.


Can i want use RB1 to RB6 insted och the default or does i have to use pin´s from outher ports?
Not sure what you mean :(

skimask
- 14th January 2008, 17:46
But the manual doese´t shows the default connections for 16F872, what are the defaults for my PIC?
Actually the manual does show the default connections.......for all PICs!
If you don't redefine the pins, they'll default to what the manual says, so long as those pins actually exist.


Can i want use RB1 to RB6 insted och the default or does i have to use pin´s from outher ports?
In a roundabout way, you can use any pin you want (using DT's ANYPIN routines) for the LCDIN/LCDOUT commands, but I'm guessing that's probably a bit above your skill at the moment. Give it time and anything is possible.


btw why does the PIC have diffrent ports like PORTA, PORTB, PORTC..
I suppose they could name them anything they want, just call them 1 thru 30, or A-Z or whatever.
But, since the PIC16F872 is primarily an 8bit device, it therefore makes a bit more sense to divide up the pins into 8 bit chunks as much as possible to keep the firmware/instructions/etc a bit simpler.
Quite frankly, you won't see a lot of 6 bit or 13 bit devices out there, or some other off the wall number. Pretty much everything is either 1,4,8, or 16 bits (yes, there are exceptions to the rule, just not a lot).


And yes i´m new to PIC programing and i have just get my LED to blink when i push a button :D

Get on it! Make 2 LEDs blink with 3 buttons... Then make a servo move with the buttons, then make a .... see how it goes?

Get out while you can! It's a never ending cycle man!!! You'll end up spending all of your money on the latest greatest thing out there!!! Blowing all of your sleep time programming PICs... Lose your money, house, sanity...it's like drugs! It's terrible!!! :D

Ok, not really...but you get the point...(as for me, I'll never learn!)

Fredrick
- 17th January 2008, 15:38
Hello.

Now i have connected the LCD as PBP defaults and when i run the PIC with this code the display shown the temerature for 1sec and then it shows "fffffffffffffffffffffff" on both lines for a sec and then shows the temerature again and so on...

Why?


' One-wire temperature for LAB-X1 and DS1820
define OSC 20
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 600

temperature Var Word ' Temperature storage
count_remain Var Byte ' Count remaining
count_per_c Var Byte ' Count per degree C

pause 1000


DQ Var PORTB.2 ' One-wire data pin

ADCON1 = 7 ' Set PORTA and PORTE to digital

mainloop: OWOut DQ, 1, [$CC, $44] ' Start temperature conversion

waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting

If count_remain = 0 Then waitloop

OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]

' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
Lcdout $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"

' Calculate temperature in degrees F to 2 decimal places (not valid for negative temperature)
temperature = (temperature */ 461) + 3200
Lcdout $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " F"

Pause 1000 ' Display about once a second

Goto mainloop ' Do it forever

Acetronics2
- 17th January 2008, 16:28
Hi,

Try this for Waitloop ...


'************************************************* ****************************
' Check for still busy converting ( ~ 4500 fois ... )
'************************************************* ****************************

waitloop:

INPUT DQ
If NOT DQ Then waitloop



AND ....




DEFINE LCD_DATAUS 600



Should be ...




DEFINE LCD_DATAUS 60






Alain

Fredrick
- 17th January 2008, 16:58
Doesn´t work.

Acetronics2
- 17th January 2008, 17:26
Aha ...




' One-wire temperature for Picboard and DS1820

'Ok le 29/08/2004 - 534 lignes


' Define LCD registers and bits

Define LCD_EBIT 1

DQ Var PORTB.4 ' One-wire data pin
Ok Var PORTB.5 ' Led Verte
Waito Var PORTB.6 ' Led Orange
Error Var PORTB.7 ' Led Rouge


temperature Var Word ' Temperature storage
count_remain Var Byte ' Count remaining
count_per_c Var Byte ' Count per degree C
offset Var Word ' 100 * offset réel !!!

offset = 293

PAUSE 500
LCDOUT $FE,1


'************************************************* ****************************
' Start temperature conversion
'************************************************* ****************************

mainloop: OWOut DQ, 1, [$CC, $44 ]

'************************************************* ****************************
' Check for still busy converting ( ~ 4500 fois ... )
'************************************************* ****************************

waitloop:

INPUT DQ
If NOT DQ Then waitloop

'************************************************* ****************************
' Read the temperature
'************************************************* ****************************

OWOut DQ, 1, [$CC, $BE ]

OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]

'************************************************* ****************************
' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
'************************************************* ****************************

temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)+ offset

Lcdout $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " ",$DF,"C"

'************************************************* ****************************
' Calculate temperature in degrees F to 2 decimal places (not valid for negative temperature)
'************************************************* ****************************

temperature = (temperature */ 461) + 3200
Lcdout $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " ",$DF,"F"

'************************************************* ****************************
' Display about once a second
'************************************************* ****************************

Pause 1000

Goto mainloop ' Do it forever



looks we have the same source !!! ... This one works perfectly aboard a 16F84 ...

soo ... let's check the 872 config ... AND,AND,AND :


Wich PbP version do you use ... and has your PBPpic14.lib being modified ???

There was an interesting thread those days about 1Wire and > 8 Mhz Osc ...

see here : http://www.picbasic.co.uk/forum/showpost.php?p=47679&postcount=4

Alain

Fredrick
- 17th January 2008, 17:34
I use PBP v2.45 and have not modified anything.

The PIC runs on OSC 20


Edit: Just tryed to put in a 4 Mhz crystal but i does´t work

skimask
- 17th January 2008, 17:52
I use PBP v2.45 and have not modified anything.
The PIC runs on OSC 20
Edit: Just tryed to put in a 4 Mhz crystal but i does´t work

Apparently, the bug mentioned at the end of post #9 is only applicable to PBP2.50(a).

But still, something wierd going on...

Change your LCD_DATAUS from 600 to 255.
LCD_DATAUS is a byte value (up until PBP2.50 as far as I know), so 600 is actually 88 (600 - 256 - 256 ) as far as PBP knows.

Past that...
Check the pullup on MCLR?
Watchdog timer off?

Fredrick
- 17th January 2008, 18:08
I dont know what i have done but now the display shows "333333333333333" on both lines and some times the temerature shows on diffrent positions in the display whit "3" all over the display.

The display is an HD44780 OLED, can the display be broken?

The PBP Hello World sampel works..

skimask
- 17th January 2008, 18:09
I dont know what i have done but now the display shows "333333333333333" on both lines and some times the temerature shows on diffrent positions in the display whit "3" all over the display.
The display is an HD44780 OLED, can the display be broken?
The PBP Hello World sampel works..

I'm sure the 'Hello World' sample works just fine, but when you start messing around with some of the special LCD commands and stuff, the LCD timing starts to matter.
Did you change the LCD_DATAUS yet?

Fredrick
- 17th January 2008, 18:14
Yes i have.

Bruce
- 17th January 2008, 18:29
Place this in the first section of your code;

@ device pic16F872, hs_osc, wdt_off, pwrt_on, lvp_off, protect_off

Change DEFINE LCD_DATAUS 600 to DEFINE LCD_DATAUS 50.

Does it work now?

skimask
- 17th January 2008, 18:44
Give this a shot:



@ DEVICE PIC16F872, HS_OSC, WDT_OFF, PWRT_ON, LVP_OFF, PROTECT_OFF
DEFINE OSC 20
DEFINE LCD_COMMANDUS 3000
DEFINE LCD_DATAUS 250
temperature var word : count_remain var byte : count_per_c var byte
dq var portb.2 : ADCON1 = 7 : pause 1000 : lcdout $fe , 1
mainloop: OWOut DQ , 1 , [ $CC , $44 ]
waitloop: OWIn DQ, 4, [count_remain] : If count_remain = 0 Then waitloop
owout dq, 1, [$cc,$be]
owin dq , 0 , [ temperature.lowbyte , temperature.highbyte , skip 4 , count_remain , count_per_c ]
temperature = ( ( ( temperature >> 1 ) * 100 ) - 25 ) + ( ( ( count_per_c - count_remain ) * 100 ) / count_per_c )
Lcdout $fe , $80 , DEC3 ( temperature / 100 ) , "." , DEC2 temperature, " C"
temperature = ( temperature * / 461 ) + 3200
Lcdout $fe , $c0 , DEC3 ( temperature / 100 ) , "." , DEC2 temperature , " F"
Pause 1000 : goto mainloop



Also, in your original code, you show:
define OSC 20

Put all DEFINE's in upper case. It's a bit weird like that.
Your original code was probably still compiled as if it were for a 4 Mhz oscillator, even though you had 'define OSC 20'.

Fredrick
- 17th January 2008, 18:48
No i does not work...

Fredrick
- 17th January 2008, 18:57
temperature = ( temperature * / 461 ) + 3200

ERROR Line 23: Bad expression. (TEST.pbp)


I use Microcode Studio and microcode put define in uppercase by auto, or do i still have to write it in uppercase?

skimask
- 17th January 2008, 18:58
temperature = ( temperature * / 461 ) + 3200

ERROR Line 23: Bad expression. (TEST.pbp)


I use Microcode Studio and microcode put define in uppercase by auto, or do i still have to write it in uppercase?

I just write it in uppercase myself.
No questions about it then.
As far as the bad expression, the fix is in the manual.

Fredrick
- 17th January 2008, 19:03
Bad expression is fixed now, but the problem whit the LCD still remains...

This is driving me crasy..... gaaahhh i have to take a pause and a cup of coffee now...

skimask
- 17th January 2008, 19:08
I use PBP v2.45 and have not modified anything.

Sounds like it's time to get the 2.50a update...

Bruce
- 17th January 2008, 19:12
Remove the space between the * and / in temperature = ( temperature * / 461 ) + 3200.

Fredrick
- 17th January 2008, 19:12
Why? 2.45 should work...

And update the PBP is not an garanti for that i will work..

skimask
- 17th January 2008, 19:14
Remove the space between the * and / in temperature = ( temperature * / 461 ) + 3200.

Fixed in post #20, apparently anyways.

skimask
- 17th January 2008, 19:14
Why? 2.45 should work...

And update the PBP is not an garanti for that i will work..

The update is only $25, get a new book, all the fixes, support for 32 bit variables, etc.

Fredrick
- 17th January 2008, 19:18
Maybe i will do that, but still i want to get the LCD to work now..... with the current version...

skimask
- 17th January 2008, 19:24
Maybe i will do that, but still i want to get the LCD to work now..... with the current version...

Are you using the PBP DEMO version?

Fredrick
- 17th January 2008, 19:26
No i use PICBASIC PRO

Will it do any diffrent if i use an PIC16F876 insted?

skimask
- 17th January 2008, 19:28
No i use PICBASIC PRO

'876 vs. '872 - shouldn't make much difference at all.

PicBasicPro or PicBasicPro Demo version?

Fredrick
- 17th January 2008, 19:45
'876 vs. '872 - shouldn't make much difference at all.

PicBasicPro or PicBasicPro Demo version?

PICBASICPRO

skimask
- 17th January 2008, 19:55
PICBASICPRO

When did you get PicBasicPro?
How long have you been using it to write programs for PIC's?

As far as the LCD, maybe the config registers aren't being set up correctly.
You said you were using an OLED LCD?
Are they EXACTLY the same as the non-OLED LCD's as far as programming goes?

Acetronics2
- 17th January 2008, 20:00
I do not know if any issue ...

But found this on Melab's site:

LAB X1
Compatible with the following microcontrollers:

PIC16C64(A), 16C65(B), 16C662, 16C67, 16C74(AB), 16C765, 16C77, 16C774, 16F74, 16F747, 16F77, 16F777, 16F871, 16F874, 16F874A, 16F877, 16F877A, 16F884, 16F887, 16F914, 16F917, 18C442, 18C452, 18F4220, 18F4221, 18F4320, 18F4321, 18F4331, 18F4410, 18F442, 18F4420, 18F4423, 18F4431, 18F4439, 18F4450, 18F4455, 18F4458, 18F448, 18F4480, 18F4510, 18F4515, 18F452, 18F4520, 18F4523, 18F4525, 18F4539, 18F4550, 18F4553, 18F458, 18F4580, 18F4585, 18F4610, 18F4620, 18F4680, 18F4682, 18F4685

16F872 and 876 are not on the list ... simply forgotten or ???

Alain

skimask
- 17th January 2008, 20:03
I do not know if any issue ...
But found this on Melab's site:
LAB X1
Compatible with the following microcontrollers:
16F872 and 876 are not on the list ... simply forgotten or ???
Alain

I don't think he's using the LAB X1, just the code has that in the comments.

Acetronics2
- 17th January 2008, 20:05
So, Might we think to a bad connection on the breadboard ???

skimask
- 17th January 2008, 20:09
So, Might we think to a bad connection on the breadboard ???

Very possible...but, it works correctly (I think, haven't really determined that) and the LCD only messes up after running for a second or so.

Fredrick
- 17th January 2008, 22:06
There is nothing wrong whit the code....

When i put my finger on the LCDs Enable pin everythings become normal, and it´s not a bad soldering, becouse the LCD have tre diffrent connection pionts and everythings become normal when i put my finger of any och the tre connections Enable pin.

What is wrong?

A picture of the LCD (OLED)
http://www.fractronics.com/oled1_b.jpg

Archangel
- 18th January 2008, 02:22
Hi Fredrick,
I had an issue with some "Import" LCD units and I solved it with a bypass capacitor on the power and ground leads, Pin 1, 2 . My issue was similar to yours.
JS

Fredrick
- 18th January 2008, 04:14
I will try that..

Btw how do i do if i want to messure both positive and negative temperature?

skimask
- 18th January 2008, 14:06
I will try that..

Btw how do i do if i want to messure both positive and negative temperature?

Do a search, bunch of code examples here on how to do that.

Fredrick
- 19th January 2008, 02:04
A 10Kohms resistor i serie with the enable wire and the code works as normal... strange???

Pic_User
- 19th January 2008, 03:56
Hi Fredrick,

Double check that your LCD ground is connected to the PIC Vss (5V common) securely.
Check that your LCD Plus is connected to the PIC Vdd (5V plus).
Also check resistor pullup on PIC MCLR to Vdd. as Skimask suggested.

-Adam-

Fredrick
- 19th January 2008, 04:03
Hi Fredrick,

Double check that your LCD ground is connected to the PIC Vss (5V common) securely.
Check that your LCD Plus is connected to the PIC Vdd (5V plus).
Also check resistor pullup on PIC MCLR to Vdd. as Skimask suggested.

-Adam-

MCLR pull up is ok.

The LCD is connected to the same voltage regulator as the PIC but not directly connected to the VDD or VSS PIC pin.

The LCD is connected to this DEV board.
http://www.olimex.com/dev/pic-p28.html

Pic_User
- 19th January 2008, 04:19
The LCD is connected to the same voltage regulator as the PIC but not directly connected to the VDD or VSS PIC pin.
Same supply as PIC is good.

Does the LCD have a LED back light? The development board voltage regulator (VR) has no heat sink.

Fredrick
- 19th January 2008, 04:26
The LCD does not have a backlight becouse it´s an (HD44780) OLED
For 2 years or so i use the same OLED whit an 16F84 and the same code to and then i worked

No it has not an heat sink, but it is capable of 1.5 A whitout an heat sink and that is more then i need.

http://www.fractronics.com/oled1_b.jpg

Pic_User
- 19th January 2008, 05:31
Hi Fredrick,

The LM317 package would be rated at 1.5A with a very good heat-sink and the correct input voltage, to avoid, dropping too much voltage and heating itself.
(input – output differential V)
http://cache.national.com/ds/LM/LM117.pdf

With no heat sink, 15 V input 5 V output, the 317 could overheat with just over 200 mA at 25 C.

Regulator Heatsink Calculator
http://www.ef-uk.net/data/heatsinking.htm

How much current does the OLED LCD display draw?

Is the voltage regulator getting hot (to your touch)?
Can you “oscilloscope” the +5V supply? Watch for the voltage to dropout.

-Adam-

skimask
- 19th January 2008, 06:26
The LCD does not have a backlight becouse it´s an (HD44780) OLED
For 2 years or so i use the same OLED whit an 16F84 and the same code to and then i worked

No it has not an heat sink, but it is capable of 1.5 A whitout an heat sink and that is more then i need.


Know what else might help?

If you bought a legit copy of PicBasicPro from a vendor instead of download an old version of 2.45 from who knows where!

Fredrick
- 19th January 2008, 12:05
Hi Fredrick,

The LM317 package would be rated at 1.5A with a very good heat-sink and the correct input voltage, to avoid, dropping too much voltage and heating itself.
(input – output differential V)
http://cache.national.com/ds/LM/LM117.pdf

With no heat sink, 15 V input 5 V output, the 317 could overheat with just over 200 mA at 25 C.

Regulator Heatsink Calculator
http://www.ef-uk.net/data/heatsinking.htm

How much current does the OLED LCD display draw?

Is the voltage regulator getting hot (to your touch)?
Can you “oscilloscope” the +5V supply? Watch for the voltage to dropout.

-Adam-

Ok thanx

The VR is not getting hot.

Edit: Heat sink is added just in case...
http://www.elfa.se/elfa-bin/dyndok.pl?lang=se&vat=0&dok=245171.htm

Fredrick
- 26th January 2008, 21:17
Know what else might help?

If you bought a legit copy of PicBasicPro from a vendor instead of download an old version of 2.45 from who knows where!

That diden´t solve my problem, i still have o use the resistor in serie with Enable.

Acetronics2
- 27th January 2008, 09:30
That diden´t solve my problem, i still have o use the resistor in serie with Enable.

Hi, Fredrick

Why not send us you REAL scheme ??? ... and may be a link to your Oled Datasheet ( couldn't find anything about it yet ...)

looking at various OLED displays Datasheet it seems :


DEFINE LCD_COMMANDUS 4500
DEFINE LCD_DATAUS 150

are the values to use ... not so fast, those OLEDs !!!

Alain