PDA

View Full Version : 4x3 keypad and an LCD.. need help.



taisen83
- 23rd December 2008, 12:12
hello everyone! I'm new in this forum. Anyone can help me with my project? Im using a PIC16F877 and i want to know what codes are needed in PICBasic Pro to display the number key pressed in the 16x2 LCD Hitachi HD44780 and the total number that was entered will be stored in a variable for later use in the program.. pls help me.. thnx to all who can help.. :)

mackrackit
- 23rd December 2008, 13:02
Welcome to the forum.

First let me ask how far you are in this adventure.

Have you got an LCD to work yet? If so then these will help with the key-pad.
http://www.picbasic.co.uk/forum/showthread.php?t=3250
http://www.picbasic.co.uk/forum/showthread.php?t=10110

Archangel
- 23rd December 2008, 17:22
To repeat Mackrackit's admonition: Welcome to the forum. Now, look at the home page, scroll down to code examples, open it up and you will find at least 2 usable examples there.

Acetronics2
- 23rd December 2008, 19:04
Welcome here,Taisen

Also think to browse the PARALLAX site ... ( ~ same basic )

your app reminds me something seen there ...

Alain

taisen83
- 29th December 2008, 13:37
thank you sir mack, joe and ace.. i'll try to study what you have told me. can i ask 1 more thing? u know how to translate this equation into picbasic pro codes: x = 2 * 1.5.. i tried to do this but the result was x = 2 only.. it means only the equation x = 2 * 1 was seen by the program.. anyone can help.. thnx!

taisen83
- 29th December 2008, 14:14
also when the equation is x = 50 x 2500.. x becomes 59464 instead of 125000.. anyone know why this happen?

mackrackit
- 29th December 2008, 14:18
If you must have floating points there is a routine over at the MeLabs site.

The easy way for what you are doing is to drop the decimal point.
x = 2 * 1.5

would be
x = 2 * 15 / 10

Then if you are wanting to display a 3.0


LCDOUT, $FE;1,DEC x,".",DEC2 x//100


65535 is the largest value for a WORD size variable. So 125000 over flows, comes back around starting at zero and the result is 59464.

taisen83
- 30th December 2008, 03:09
i tried the codes but the lcd displaying 3.03.

mackrackit
- 30th December 2008, 06:02
OOPPS, I was not thinking straight :o

What we are doing.
Take the number with one decimal place and multiply by 10 before the PIC sees it.
1.5 is now 15
1.6 is now 16
...


x = 2 * 16
lcdout $FE,1,DEC x / 10,".",DEC x//10

In the above the "x / 10" will return 3.
x//10 will return the remainder 2.

Look in the Pic Basic manual under Math Operators for more fun/confusing stuff :)

taisen83
- 31st December 2008, 09:20
thanks! that info really helps me.. :)
But i still got another problem. if the equation goes like this x = 26 // 21.. the answer should be 238095238, the decimal part cannot read by the program and the answer is wrong because the limit is 65535 right? how to get the right answer like display 238 only? thanks again..

mackrackit
- 31st December 2008, 11:38
In this case the decimal needs moved three places to the right.
26/21=1.238095...
1000*26/21=1238.095...
x = (1000*26/21)//1000
x=238

You could have


y=26
x = (1000*y/21)//1000

The above will only work if "y" is an integer 22 through 41.
When reading a sensor the range of values are fixed so with a little imagination a constant like in the above case 1000 will work. When another application comes along with a different set of values a different constant and equation will be required.

What is your application besides a keypad?

Nicmus
- 31st December 2008, 13:42
You could have



y=26
x = (1000*y/21)//1000

The above will only work if "y" is an integer 22 through 41.


I'm not sure why any value 0 - 65 will not satisfy your equation. The only requirement to keep it "legal" is to keep 1000*y under 65535. Also if you can afford to loose one digit after the decimal point (0.00x) then the range for y will be 0 – 650.
I guess knowing more about the application will help make the best decision.

Regards,

Nick

mackrackit
- 31st December 2008, 15:06
I'm not sure why any value 0 - 65 will not satisfy your equation. The only requirement to keep it "legal" is to keep 1000*y under 65535. Also if you can afford to loose one digit after the decimal point (0.00x) then the range for y will be 0 – 650.
I guess knowing more about the application will help make the best decision.

Regards,

Nick
I should have said 2 - 41 .
Beyond these values you run into the leading zero problem with the equation I gave.
Some values above 41 will work, some will return 0.0xx. The 0 tenths is the problem.
Thanks for catching that.

Acetronics2
- 31st December 2008, 15:48
Hi, Taisen

Is this little calculator to count what you'll get this year ???

http://www.piratekingonline.com/forum/search.php?searchid=836105

Seriously ... you should turn to a 16Bits core device ( 18F452 i.e.) and use the 32 bits calculations of PBPL ...

Alain

Nicmus
- 31st December 2008, 15:55
Hi mackrackit,

If the leading zeros are a problem you just use DEC 3 in your LCDOUT command and you should be OK on full 0 – 65 range. The only change will be with the result of y/21 (0 -6).

Regards,

nick

mackrackit
- 31st December 2008, 17:08
Hi mackrackit,

If the leading zeros are a problem you just use DEC 3 in your LCDOUT command and you should be OK on full 0 – 65 range. The only change will be with the result of y/21 (0 -6).

Regards,

nick

Yep. We really need to know what taisen83 is trying to do.
If all of the sudden the numbers change to something like
x = (1000*1/3000)//1000
Then it all falls apart, I tink :)

PBL is the ticket.

taisen83
- 2nd January 2009, 07:04
currently im doing a rice dispenser device that accepts a weight or price value.. my problem was at the price input value.. as the device runs it will ask for a price/kilo of the rice.. assuming i input a value of 25.50, but the actual value stored is 2550. this 2550 is the reference for determining the weight to be dispensed. after 2550 stored, the program ask for another input to be compared in the 2550. i used the codes that mackrackit posted.

'variable PRICE is the reference input
'TOTALAMOUNT is the variable to be compared

PRICED = PRICE/10
AMT = TOTALAMOUNT/10
DECIKILO = (100*AMT/PRICED)//100
WHOLEKILO = (100*AMT/PRICED)/100

LCDOUT $FE,$C0,#WHOLEKILO,".",#DECIKILO," Kg"

using this the program I can determine the weight but it only accepts 4 digit number.. making it to a 5 digit input will go beyond a 65535 limit.

mackrackit
- 2nd January 2009, 07:22
If you have PBP 2.50 and use a 18F
chip, you can compile with PBPL
that will give you 32 bit math.
This will give you the ability to use
numbers with a range of
-2147483648 to
+2147483647
That should solve the problem.

taisen83
- 5th January 2009, 03:35
the codes that i created in 16f877 can be used when i changed to 18f, what 18f pic is almost the same as 16f877? and it must be pbp 2.50? coz im currently using 2.47 only.. thnx

mackrackit
- 5th January 2009, 05:26
If you want to use the LONG variable that gives you 32 bit math you will have to upgrade to 2.50.

When moving your code from a 16F to an 18F there will be some modifications needed. example, the 16F877 does not have comparators, so you may hace to turn them off on the 18F chip depending on the pins used.

As far as pin outs go, and as far as I know, all of the 40 pin PICs use the same pins for power, programming, OSC and MCLR.

The 18Fs will have several extra features, that may or may not be useful, such as USB pins and may even have an internal OSC.

An 18F4320 might be a good one to start with. It has an internal OSC, but does not have USB.

taisen83
- 5th January 2009, 05:56
18f452 can also be a substitute right? coz i've seen in forums about transferring codes from 16f877 to 18f452..

mackrackit
- 5th January 2009, 07:28
Micro Chip says the 18F4520 would be the better choice.
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2533&product1=PIC18F452&product2=PIC18F4520
But if you have some 452s laying around and this is not a production project then the 452 should be fine. With a little imagination :)

taisen83
- 6th January 2009, 09:34
thnx for all the help! really a great help for a beginners like me.. i'll report asap when i got the result using new IC.. thnx again! :):)