How do i know the right pins i should connect my LCD display to? or can i select my own pins in my program?
Printable View
How do i know the right pins i should connect my LCD display to? or can i select my own pins in my program?
The manual show the default connections. You can also select your own and add some DEFINEs at the top of your program.
Code:'
' 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
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
Don't worry, the default one are the same for all PIC model.Quote:
But the manual doese´t shows the default connections for 16F872, what are the defaults for my PIC?
Not sure what you mean :(Quote:
Can i want use RB1 to RB6 insted och the default or does i have to use pin´s from outher ports?
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.
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.Quote:
Can i want use RB1 to RB6 insted och the default or does i have to use pin´s from outher ports?
I suppose they could name them anything they want, just call them 1 thru 30, or A-Z or whatever.Quote:
btw why does the PIC have diffrent ports like PORTA, PORTB, PORTC..
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).
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?Quote:
And yes i´m new to PIC programing and i have just get my LED to blink when i push a button :D
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!)
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?
Code:' 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
Hi,
Try this for Waitloop ...
AND ....Code:'*****************************************************************************
' Check for still busy converting ( ~ 4500 fois ... )
'*****************************************************************************
waitloop:
INPUT DQ
If NOT DQ Then waitloop
Should be ...Code:
DEFINE LCD_DATAUS 600
Code:
DEFINE LCD_DATAUS 60
Alain
Doesn´t work.
Aha ...
looks we have the same source !!! ... This one works perfectly aboard a 16F84 ...Code:
' 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
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/show...79&postcount=4
Alain
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?
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..
Yes i have.
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?
Give this a shot:
Code:@ 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'.
No i does not work...
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?
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...
Remove the space between the * and / in temperature = ( temperature * / 461 ) + 3200.
Why? 2.45 should work...
And update the PBP is not an garanti for that i will work..
Maybe i will do that, but still i want to get the LCD to work now..... with the current version...
No i use PICBASIC PRO
Will it do any diffrent if i use an PIC16F876 insted?
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?
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
So, Might we think to a bad connection on the breadboard ???
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
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
I will try that..
Btw how do i do if i want to messure both positive and negative temperature?
A 10Kohms resistor i serie with the enable wire and the code works as normal... strange???