Log in

View Full Version : migration from 16F876a to 18F25k22



MOUNTAIN747
- 21st January 2012, 19:36
I have a project that I have built for the farm to extract the moisture content of grain in the silos. The project is working well. I would like to add a RS485 comm ( Master, 5 Slaves ) to the project to communicate with all silos. The current boards use PIC16F876a. I am having difficulty with DT_INT and HSERIN routines using the 16F876a. After reading all 17 pages of DT_INT’s I think it would be much easier to upgrade my processor to 18F to get the quality of comm that I need. I am considering a 18F25k22 because it should do the job and because I would like to use this processors features in future projects. I have not yet worked with this processor and I am wondering what changes I will have to make to my current code in order to use it. Comments please? Would this be a good choice for upgrade or is there another processor that would be better for upgrade from 16F876a?

Thanks!

Wayne

Demon
- 21st January 2012, 23:13
Off the top of my head, CONFIGs are more complicated with 18F family.

You might also want to consider moving to MPASM if you haven't already.

Robert

EDIT: Off-hand 18F PICs are superior to the 16F family, but it's hard to tell you if that PIC is the best for you, especially if we don't know exactly what features you want now, and what you will need in the future. Microchip does have comparison and migration information, you might want to start here:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2661

Also, if you intend on migrating to PBP 3.0 as well, things have changed a bit too:
http://www.picbasic.co.uk/forum/showthread.php?t=543&page=2&p=110963#post110963

MOUNTAIN747
- 22nd January 2012, 18:00
Demon, Thanks for responding. I have considered the change in Config’s on the 18F’s, the pin outs seem to be the same so the 18F25k22 should replace the 16F876a with only minor changes. The extra memory will also come in handy as the code seems to always grow, I think there’s some kind of natural law that says that has to happen.
I haven’t jumped to PBP3 yet (which supports 18F25k22). PBP2.6 has the support files for 25k20 and I think it would take just a few tweaks to create new files for the 25k22. PBP3 Does Look Good and I think DT_INT can be run without MPASM. Has anyone put together a list of difficulties in migrating from 2.6 to 3 while working with file created in 2.6?

Demon
- 22nd January 2012, 19:23
More clutter with more available space also applies to basements, and in double for garages.

I'm still on 2.60C, but you'll have a good list of migration errors from me when I'm forced to make the jump. :D

Consider switching to MPASM as a small step, it's just a download and then pointing to that library from within Microcode Studio. I downloaded the entire MPLAB Suite, but only point to MPASM.

And you're going to need MPASM if you ever do USB.

Robert

ScaleRobotics
- 22nd January 2012, 19:30
I believe DT_INTS requires MPASM. PBP3 require MPASM or MPASMx. PBP3 was a pretty easy migration. I think some of the install instructions pretty much cover it, but there are a few things. Here is a migration document: http://pbp3.com/downloads/Migrating%20existing%20programs%20to%20PBP3.pdf

MOUNTAIN747
- 22nd January 2012, 20:20
Thanks guys for your comments and links!
Don’t you hate those new learning curves ? Dang it, once I think I just about got the hang of one piece of software I need to change. I don’t have a problem with MPLAB, in the later part of the last century I spent a couple of years playing with ASM. It’s just that PBP takes much of the work out of it! Migrating just means down time. I’m sure I’ll go PBP3 once I figure out what upgrade I need and if I need to get a new MCS. By the way, I see a Compiler V3 on Reynolds web site. What is V3? Have ether of you tried to add your own files to MCS+ to gain a new processor? OOPs, maybe I shouldn’t ask that question…

One more thing, I think I've seen post by both of you doing work with graphic LCD's. I need to get into these LCD if for no other reason that I need more screan space for messages. I don't need touch screen but I do need something in the range of a 5 to 6 inch display. any suggestions on brands maybe with some ASKII maps on board?
Thanks!

Wayne

Demon
- 22nd January 2012, 20:48
You don't have to use MPLAB, I just downloaded it to have a recent version of MPASM. You don't have to use MPASM directly either, you keep on working in PIC Basic Pro (MPASM is used in place of the default assembler in background).

You don't have to go to PBP 3.0 either if you're happy with what you have. I'm on PBP 2.60C, Microcode Studio Plus v2.2.1.1 using 18F4550 with USB and I'm quite happy!

It's just that some new features need MPASM to function, like USB and DT Interrupts.

Sorry, I haven't added a new processor in MCS. And no, as far as I know it's not forbidden to discuss that subject. I have seen others post about doing it, I don't think they included details though.

5-6 inch LCDs, I haven't looked recently but those buggers weren't coming down in price very fast. Something like $80-100 USD several years ago, ebay is a good place to get an idea what they go for now. Particular model, I worked with one LCD more than the other demos I received. I'll have to do some digging.

Robert

EDIT: What about something like this?

http://i991.photobucket.com/albums/af37/DemonDNF/Electronics/Demo015.jpg

MOUNTAIN747
- 22nd January 2012, 21:19
Wow! that would be perfect for what I'm working on now. What and Where? and how difficult was it to program?

Demon
- 22nd January 2012, 21:37
Ok, this was all I could find, 320x240 pixels.

6235

If I recall, this works as standard parallel LCD on a PIC. All you need is the line numbers.

My gamer PC is in the fritz so I can't get to the code right now. I can't say when I'll be getting a new cpu cooling fan.

Robert

EDIT: Check this one out, google for datasheet:
http://www.ebay.ca/itm/NEW-5-7-320x240-LCD-Module-DGA-32240-WNCW-Touch-Screen-QVGA-Data-International-/250974813202?pt=LH_DefaultDomain_0&hash=item3a6f43bc12

There's also this one:
http://www.ebay.ca/itm/UG-32F01-SEBT5-J-LCD-320x240-Dot-5-Display-Panel-Samsung-E01217-/250944162313?pt=LH_DefaultDomain_0&hash=item3a6d700a09

But both of these have Clock Latch and Shift pins, I think that is a serial interface (datasheet for 2nd one says parallel).

You really want to get parallel with pins similar to the one I used at top, so much easier to deal with.

Demon
- 22nd January 2012, 22:09
OOOPS!

That 1st model was from an earlier demo unit.

I checked the actual prototype used for that picture and I ended using a HM320240FDWB1-14 v1.0 with Epson S1D1330 controller:

6236

Very detailled specs.

Robert

MOUNTAIN747
- 22nd January 2012, 22:32
Great Robert, thanks a bunch! I'll follow through on these and may have a question or two after I have spent some time playing with them.
Wayne

Demon
- 23rd January 2012, 00:20
Look what I found:
http://www.compsys1.com/support/PBP_Files/sed1330/

Robert

HenrikOlsson
- 23rd January 2012, 17:03
Hi,
Regarding the two "EBAY-units" linked to in post #9. It looks to me as if these units have the display driver onboard but NOT the display controller (like the SED1330, RA6963 etc) OR any RAM. This means you're going to have to build the complete frame in memory (internal or external to the PIC) and then continously keep refreshing the display with that data (320*240/8=9600bytes).

If I'm correct on that point it'll be a real challenge to drive either of these with a PIC.

What you're looking for is a unit with display driver AND controller AND RAM. Alternatively something like this module (http://www.ebay.ca/itm/SED1335-SED1330-Control-Board-320240-LCD-Module-Display-/190409089539?pt=LH_DefaultDomain_0&hash=item2c55442203) to compliment the actual LCD-module.

/Henrik.

Demon
- 23rd January 2012, 17:30
Hi,
Regarding the two "EBAY-units"...
If I'm correct on that point it'll be a real challenge...

Yes, those will be hard to operate, that's why I gave more info on the SED model and said it's important to find a parallel model.

If there are clock or latch pins, stay away from those LCDs. That's why they are cheap, hobbyists don't buy them.

Robert

Demon
- 4th February 2012, 21:55
I just found this lying around in My Documents of an old PC:


'--------------------------------------------------------------------'
' Author: Demon '
' Date: April 7th, 2006 ' '
' Language: PIC Basic Pro v2.46 '
' MPU: PIC 16F877 20/P from MicroChip '
' IDE: MicroCode Studio Plus from Mecanique v2.2.1.1 '
' Programmer: MeLabs Serial Programmer v3.12 (firmware v3.4) '
' LCD: LCM3202401 from QingYun-IT '
' '
' All rights reserved. '
' '
' Use of parts of code is permitted as long as credit is given '
' to the author. Code may or may not be Year 3000 proof. Use '
' at your own risk. '
'--------------------------------------------------------------------'

'define LOADER_USED 1
clear
ADCON1 = 7

ASM
@ DEVICE PIC16F877, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, PROTECT_OFF
ENDASM

DEFINE OSC 20

pinData var PORTD
pinWR var PORTB.0
pinRD var PORTB.1
pinCS var PORTB.2
pinA0 var PORTB.4
pinRST var PORTB.5
pinLED VAR PORTB.3
pinSCL VAR PORTC.3
pinSDA VAR PORTC.4

TRISD = 0
TRISB.0 = 0
TRISB.1 = 0
TRISB.2 = 0
TRISB.4 = 0
TRISB.5 = 0
TRISB.3 = 0

conSet con $40
conScroll con $44
conCursorForm con $5d
conCursorAddress con $46
conCursorRight con $4c
conOverlay con $5b
conWrite con $42
conDisplayON con $59
conDisplayOFF con $58
conCharPerLine con $28 ' 40 characters / line

varCommand Var BYTE
varCursor var BYTE
varByte var BYTE
varLoop1 var BYTE
varLoop2 var BYTE
varAddress var WORD

pinRD = 1
pinWR = 1
pinCS = 0
pinRST = 0
pause 1
pinRST = 1
pause 100

goto main

' --------------------------- Subroutines --------------------------

'INCLUDE "SED1335 subroutines.pbp"
SendData:
pinA0 = 0
pinData = varByte
pinWR = 0
' @ nop
pinWR = 1
return

SendCommand:
pinA0 = 1
pinData = varCommand
pinWR = 0
' @ nop
pinWR = 1
return

ClearGraphic:
varCommand = conCursorAddress
gosub SendCommand
varByte = $00
gosub SendData
varByte = $10
gosub SendData

varCommand = conCursorRight
gosub SendCommand

varCommand = conWrite
gosub SendCommand
varByte = %00000000 ' 1 byte = 8 bits = 8 pixels wide
for varLoop1 = 1 to 240 ' 240 pixels high
for varLoop2 = 1 to 40 ' 40 bytes = 320 bits = 320 pixels wide
gosub SendData
next varLoop2
next varLoop1
return

ClearText:
varCommand = conCursorAddress
gosub SendCommand
varByte = $00
gosub SendData
varByte = $00
gosub SendData

varCommand = conCursorRight
gosub SendCommand

varCommand = conWrite
gosub SendCommand
varByte = " "
for varLoop1 = 1 to 30
for varLoop2 = 1 to 40
gosub SendData
next varLoop2
next varLoop1
return

InitDisplay:
varCommand = conSet
gosub SendCommand
for varLoop1 = 0 to 7
lookup varLoop1,[$32,$87,$07,$27,$2B,$EF,$28,$00],varByte
gosub SendData
next varLoop1

varCommand = conScroll
gosub SendCommand
for varLoop1 = 0 to 5
lookup varLoop1,[$00,$00,$EF,$00,$10,$EF],varByte
gosub SendData
next varLoop1

varCommand = conOverlay
gosub SendCommand
varByte = %00000001
gosub SendData

varCommand =conDisplayOFF
gosub SendCommand
varByte = %00000000
gosub SendData

gosub ClearText
gosub ClearGraphic

varCommand = conDisplayON
gosub SendCommand
varByte = %00010100
gosub SendData

varCommand = conCursorAddress
gosub SendCommand
varByte = $0
gosub SendData
varByte = $0
gosub SendData

varCommand =conCursorForm
gosub SendCommand
varByte = $04
gosub SendData
varByte = $86
gosub SendData
return

SetAddress:
varCommand = conCursorAddress
gosub SendCommand
varByte = varAddress.BYTE0
gosub SendData
varByte = varAddress.BYTE1
gosub SendData

varCommand = varCursor
gosub SendCommand

varCommand = conWrite
gosub SendCommand
return

' --------------------------- Main program --------------------------

Main:
gosub InitDisplay

pinLED = 1

varAddress = 0
varCursor = conCursorRight
gosub SetAddress

for varLoop1 = 0 to 39
lookup varLoop1,[".. QINGYUN IT LCM-3202401 GRAPHIC LCD .."],varByte
gosub SendData
NEXT varLoop1

varAddress = 29 * conCharPerLine
varCursor = conCursorRight
gosub SetAddress

for varLoop1 = 0 to 39
lookup varLoop1,["Demon was here! "],varByte
gosub SendData
NEXT varLoop1
end


It's old and not cleaned up, but at least it's a start.

Robert


EDIT: LOL Look what I found while looking at my attachments:
http://www.picbasic.co.uk/forum/showthread.php?t=3811

MOUNTAIN747
- 4th February 2012, 22:33
Robert, thanks for the code. It does look like a good starting point, clean, simple. I have a GLCD on the way from EgoChina which uses a S1D13700 controller. ($75) My first purchase of a GLCD, which means it looks like it has everything needed on the board. (I hope) I’m just figuring out the details of how to set it up. I’ll start with a code format following your example.
Thanks again,
Wayne

MOUNTAIN747
- 25th February 2012, 18:24
Do you know that uneasy felling in the pit of your stomach when you’re about to put voltage on an expensive piece of equipment and you’re NOT 100% sure "this is the right way to do it"? You realize that you may be moments away from filling the workshop with a cloud of green (the color of money) smoke! You also know that if you don’t do this you will never know if it works because, it’s not going to start by itself… OR, you can first consult the guys at MEL PICBASIC Forum and perhaps someone may be able to guide you through the mine fields. If you still go up in smoke you may be able to find one sympathetic soul somewhere on the face of the glob that will share your pain, NOT likely, BUT perhaps someone else will learn some small lesson from the experience of your smoldering carcass…

My new GLCD from china, of course has very little documentation. It is not clear how to handle the LED’s or Vo. Vee is at -23V. The data sheet says:
Vdd-Vss 4.75-5.25V
Vdd-Vo 4.5V to 30V
I am (almost) sure a 10K pot between Vee (-23V) and Vo should make it work. I am not sure about the LED’s. In fact I can’t find out the difference in function between the LEDA and LEDK or why the one page data sheet shows a resistor between a back light block and LEDA while there is no resistor for LEDK. ANY INPUT WILL BE APPRECIATED !

Using an 18F45K22 at 16Mhz internal, JHD639 320240 GLCD w/D1370002A1 controller , my code is almost done. I have followed Robert’s SED1335 example, thanks Robert, as the coding is very close for each controller though the 137000 seems to be a bit more involved.

Wayne

Demon
- 26th February 2012, 07:41
FINALLY! Something I know. :D

LEDA = led anode
LEDK = led cathode

About that Vo stuff, gonna have to go through your datasheet first.


My new GLCD from china, of course has very little documentation.
It can't be worse than the single page of Chinese I once got. LOL

Robert

Demon
- 26th February 2012, 08:06
This is for the D13700F01, but it might help you. I got it here, tons of datasheets under S1D13700*
http://www.datasheetking.com

This is how I got somewhere with several of these poorly documented LCDs. When I had nothing I'd go through controllers with similar names and find one with similar specs.

When in doubt, don't go over 5 volts (and maybe 3 volts with these newer models). At worst, it won't work.

Usually, the variable voltage is for contrast or brightness. That's why I bought a selection of potentiometers; start high and work my way down until "something happens".

Robert

Demon
- 26th February 2012, 08:18
JHD639 320240 GLCD w/D1370002A1 controller

Page 14, 5.1 pinout:

Look at what's engraved on the IC. I'm guessing D1370002A1 is a newer version of the exact same thing, or at least REALLY darn close to it in terms of features and operation.

Robert
:)

Demon
- 26th February 2012, 08:29
Another thing I often do is google for the component with different keywords like: D13700 TUTORIAL/SCHEMATIC/DIAGRAM, etc.

Sometimes you get something from another technology and can't use much of the code, but you can check out the wiring for ideas:
http://www.cafelogic.com/download/s1d13700_arduino_documentation/

And even then, you can sometimes get ideas about the initialization commands when the language is "readable" or the program is well commented.

I'd start with pots on R1 and R2.

Robert

http://www.cafelogic.com/wp-content/uploads/2010/11/Arduino_S1d13700_Schematic.gif

MOUNTAIN747
- 26th February 2012, 19:14
Thanks Robert for your comments. Yep, I've looked at evey piece of document I can find and the microelektronika schematic is the only thing I can find to give me any idea of what to do with Vo, and of course they are not using the same GLCD so its just a roll of the dice and hope for the best.

The attatched datasheet shows the Negative Voltage Generator at the bottom right of the page. notice V0 is an input to the NVG. So, Robert, do you think V0 is a Ground reference for the NVG. If we look at the easypic_v7 data sheet, microelektronika takes Vo to a 10k pot to the NVG, which of course will bring Vo bellow Vss. I think I will start with the 10k pot to ground and if the contrast is not great enough I tie the pot to NVG. I will use your advise on how to handle the LED's. Are you using only a 15 ohm resistor on LEDA?

CN2 GLCD uses 20 pin FFC cable
Pin function description My Action
1. VSS GND GND
2. VDD Logic Power input +5V
3. VO LCD contrast control POT 4kohm
4. AO Command / Data Select U1.RA.7
5. /WR 8080: Data Write U1.RC.0
6. /RD 8080: Data Read U1.RC.1
7. DO Data buss line0 U1.RD.0
8. D1 Data buss line1 U1.RD.1
9. D2 Data buss line2 U1.RD.2
10. D3 Data buss ilne3 U1.RD.3
11. D4 Data buss line4 U1.RD.4
12. D5 Data buss line5 U1.RD.5
13. D6 Data buss line6 U1.RD.6
14. D7 Data buss line7 U1.RD.7
15. /CS LCD Controller function Reset U1.RC.3
17. VEE Negative voltage output (-23V) ???
18. SEL1 SEL1=L, 8080 interface; GND
19. FGND Front Panel Ground GND
20. NC

CN3 LED wiring
21. LEDA Power for led Backlight(A) POT_500 ohm to Vcc
22. LEDK Power for led Backlight(K) GND

Thanks Again Robert!
Wayne

Demon
- 27th February 2012, 02:06
I have 100R and 1K pots on my circuit; backlight and contrast (can't say which has which pot by looking at it).


Look at the Electronic Parameters at bottom left:
Voltage Logic 5V typ.
Voltage LCD 20V typ.

The LCD has a range of 4.5 to 30 volts, 5 volts should work, and I'd stay away from the upper max. I'd start with an old PC power supply (5V and 12V) and give that a shot if you don't have a variable power supply, or a bunch of old wall adapters.

So yeah, I'd go with 500R pot on LEDA and 10K pot on V0 to start, and then tweak until I hit a pot that has an acceptable range. You'll see a sweet spot when you get to the right one; from dark to not "too" bright. Brighter LEDs mean shorter life, I aim for the just-enough-for-me range.


I also noticed something else on your datasheet; CONTROLLER: RA8835 OR EQUAL. I'd do some googling on RA8835 and see if more examples come up. You can never have too many schematics, tables or descriptions.

Robert

MOUNTAIN747
- 27th February 2012, 02:10
Thanks Robert, I'll let you know how it turns out!

Demon
- 15th March 2012, 04:12
I used the 16F628 and 16F877 before but it looks like I'll have to move up the food chain and the 18F2xK22 and 18F4xK22 series look like just what I need. At least I'm not forced to upgrade to PBP 3.0 yet:

http://melabs.com/support/patches.htm#pbp


PBP 2.60A:
Adds support for: PIC12F1822, 12LF1822, 16F1823, 16LF1823, 12F617, 16F722A, 16F723A, 16LF722A, 16LF723A, 18F23K22, 18F24K22, 18F25K22, 18F26K22, 18F43K22, 18F44K22, 18F45K22, 18F46K22, 18LF23K22, 18LF24K22, 18LF25K22, 18LF26K22, 18LF43K22, 18LF44K22, 18LF45K22, 18LF46K22

And I can even use the low voltage versions if I want. WOOT!

Robert
:)

MOUNTAIN747
- 16th March 2012, 02:51
I used the 16F628 and 16F877 before but it looks like I'll have to move up the food chain and the 18F2xK22 and 18F4xK22 series look like just what I need. At least I'm not forced to upgrade to PBP 3.0 yet:

http://melabs.com/support/patches.htm#pbp



And I can even use the low voltage versions if I want. WOOT!

Robert
:)


Robert





Robert, I've got my GLCD working with very little modification to your code. I'm using an 18F45K22. I still have a few bugs to work out with the GLCD code but at least I have something on the screen. The migration to 18F was not too difficult with the exception of a problem I had with ports. my first setup was the same as if I was using 16F and the ports did not work. I then set up ports like this:

asm
;PortA setup
MOVLB 0Fh
CLRF PORTA
CLRF ANSELA
MOVLW 30h ;PortA <5:4> input - Navigator
MOVWF TRISA
;PortB setup
MOVLB 0Fh
CLRF PORTB
CLRF ANSELB
MOVLW 03h ;PortB <1:0> input - Navigator
MOVWF TRISB
;PortC setup
MOVLB 0Fh
CLRF PORTC
CLRF ANSELC
CLRF TRISC
;PortD setup
MOVLB 0Fh
CLRF PORTD
CLRF ANSELD
CLRF TRISD
;PortE setup
MOVLB 0Fh
CLRF PORTE
CLRF ANSELE
MOVLW 0Fh ;PortE <2:0> input - Navigator
MOVWF TRISE
ENDASM

and all works well. I haven't had time to look at Darrel's 'All digital' to see how he handled 18F series but it may be easer to use his include rutine.

Wayne

Demon
- 19th March 2012, 21:33
...
17. VEE Negative voltage output (-23V) ???
...


Wayne,

I've been thinking of the negative voltage that your LCD would like to have. You might be getting acceptable results using 5VDC+, but if you're not satisfied with the brightness/contrast, I totally forgot that you can have -12VDC on a PC PSU. That's still safely within the operating specs of the LCD.

http://pcsupport.about.com/od/insidethepc/a/atx-pinout-24-pin-12v-psu.htm

Robert