Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

RS232 to 16F pic

Status
Not open for further replies.
Nope just get a 1814k50 and microchips usb stack **broken link removed**

And roll your own

Since I have a 1814k50, can I convert it to operate as an mcp2200?

Any advice on the procedure to do that?

This looked hopeful:

Dangerous Prototypes

but they say it only echoes.
As be80be said, you can probably turn an 18F14K50 into an MCP2200 by flashing it with the firmware he linked to. I haven't done it, but it shouldn't be too difficult.

Or just buy an MCP2200.

...

After installing the Microchip Application Libraries and help files, and spending some time reading, I'm still pretty lost on how to do it. What you need is there, but it's not totally obvious to me what to do.

Looks like "USB Device -CDC - Serial Emulator" is the directory you want. Maybe I'll find time to test it one of these days. Microchip uses the phrase "Low Pin Count USB Development Kit" to refer to the 18F14K50, as that board has the 18F14K50 on it.

This stuff was written for Microchip's demo boards. You may possibly have to do some code mods to make it do what you want.
 
Last edited:
I decided to do it right away. I have the USB stack and CDC serial emulator demo code installed in the 18F14K50 and the driver installed on the PC. When I connect the USB cable the 18F14K50 connects (makes the happy USB sound :D) and is properly assigned to COM5. But I don't think "CDC Serial Emulator" is the piece of code I want for what I'm trying to do. Must read more...
18f14k50_usb002sm.JPG
 
Last edited:
... But I don't think "CDC Serial Emulator" is the piece of code I want for what I'm trying to do. Must read more...

OK, CDC Serial Emulator receives over the USB cable and spits whatever it receives back out the USART pins (how a USB-UART converter does). Not what I had in mind for a first time demo.

CDC Basic Demo is better as a first demo test. It receives any ASCII character typed in the PC terminal and echos back that character + 1. For example, type A - the PIC echoes back B.

I have installed this demo and it works perfect. Now I have to dig into Microchip's ultra-heavily commented and confusing code and modify it to suit me. Should be pretty simple to convert it to a plain old USB-to-UART bridge. I can for sure do a TON of decluttering, since I only want to compile it for one chip instead of ten different chips. If you're not up to speed with C then you would definitely want to just buy an MCP2200 or CP2102 or whatever. This isn't the kind of source code you want to start out with. :D
 
Last edited:
Futz!

Well futz, Actually I am looking for a USB to serial emulator.

So you're saying I can program the 18F14k50 with a hex file that you can graciously share :) and I'll be able to run PC USB to PIC UART HW comms via the 18f14K50?

It has become an MCP2200?

If that's so.. you have solved a large challenge I had w/o me having to order more HW.

Seems i'll be facing this though:
https://www.electro-tech-online.com/threads/18f14k50-at-5-volts.99239/

I have an LPC pickit2 board mentioned in that thread...can u share a schematic of how to power the 18f14k50 while programming?
 
So you're saying I can program the 18F14k50 with a hex file that you can graciously share :) and I'll be able to run PC USB to PIC UART HW comms via the 18f14K50?

It has become an MCP2200?

If that's so.. you have solved a large challenge I had w/o me having to order more HW.
Don't you want to tackle that nice C code yourself? :D

I'm not sure from reading the help file, but "USB Device - CDC - Serial Emulator" may work both ways and may already be all you need to make an 18F14K50 into a pseudo-MCP2200. The help file isn't totally clear about it. I need to connect another PIC to this one and do some testing (doing that right away now). If it works then you'd just use Microchip's pre-compiled hex file supplied with the Microchip Application Libraries.

Seems i'll be facing this though:
https://www.electro-tech-online.com/threads/18f14k50-at-5-volts.99239/

I have an LPC pickit2 board mentioned in that thread...can u share a schematic of how to power the 18f14k50 while programming?
What is an "LPC pickit2 board"?

When I use my PICkit 2 (or PICkit 3) to program the 18F14K50 I simply set the PICkit 2 to supply 3.3V to the target. You make that change in MPLAB/Programmer/Settings.

If I'm running the 18F14K50 off a 5V supply I have to switch that supply off and reconnect (in MPLAB's Programmer menu) the PICkit 2 so it supplies the target with 3.3V for programming. Then switch the 5V back on to run.

If the circuit takes too much power for the PICkit 2 to supply 3.3V then I have to have an external 3.3V target supply that I can switch to (this won't be a problem with just the chip). I usually use a SparkFun PRT-09319 (there's one in the photo above). It can supply both 5V and 3.3V, selected with a switch. It can even be hacked to supply 3.3V on one side of the breadboard and 5V on the other.
 
The 18f14k50 is 5 volts if your not using the USB And to be safe I would only use 3.3 with it

This makes a com port
Code:
:020000040000FA
:1000000083EF00F01201000202000008D8040A0089
:1000100001000102000109024300020100803209CF
:100020000400000102020100052400100104240262
:1000300002052406000105240100010705820308CA
:10004000000209040100020A00000007050302087B
:1000500000000705830208000000040309043603BA
:100060004D006900630072006F0063006800690062
:100070007000200054006500630068006E006F008F
:100080006C006F00670079002C00200049006E00B2
:1000900063002E001E034A0041004C004C00490042
:1000A00042002000530065007200690061006C008E
:1000B0002E004A414C4C4942205553422053657210
:1000C00069616C2044656D6F206170700A0067BFC4
:1000D0007DEF00F067BD73EF00F06651EA6E655189
:1000E000E96EEF5012006551F66E6651F76E67517A
:1000F0003F0BF86E0800F55012001200FB6E6651BF
:10010000FA6E6551F96E2FEF01F0976F9251E16E23
:100110009351E26E986B9DEF00F094519825656FB6
:10012000000E5E6E95515E20666F96515E20676F81
:1001300067EC00F0E66E0001982B9851975DD8A40B
:100140008DEF00F01200020104BF12000001A05167
:100150009D5DD8B4B1EF00F0D8B0B1EF00F09D5183
:10016000A06FD880A0519E55906F90519F5DD8B4DC
:10017000BFEF00F0D8B0BFEF00F09F51906F780E46
:100180009E25606F000E5E6E020E5E20616F6051F4
:100190000201066F000161510201076F00019051D9
:1001A0000201056F04ADD9EF00F0880E046FDBEF9C
:1001B00000F0C80E046F000190519E279E51A05D73
:1001C0001200080E9F6F9E6BA06B9D6B0201049D39
:1001D000A3EF00F09C6F9C510201786F080E0001A4
:1001E0009F6F9E6B010EA06F010E9D6F0201049D1B
:1001F000A3EF00F0840E020100131200080E0201AA
:10020000016F200E026F020E036F030E0001A25D4C
:10021000D8A411EF01F08C0E8F6F0201046B13EF65
:1002200001F0C80E8F6F00018F510201006F1200A4
:10023000816FD8908135846FD8908437D890843777
:100240008429836F02EE00F08351E9268251EF6E1C
:1002500002EE00F08451E926800EEF6E1200A46BCE
:10026000D7916F6B706B716B726B100E736F63EF66
:1002700005F00201F9510001916F210E915DD8A4A2
:1002800044EF01F0050EA26F120002011CBF4DEFFA
:1002900001F000017F914FEF01F000017F817FB1FC
:1002A00012006F51705DD8A45BEF01F0D7A112006E
:1002B0007B6B6DEF01F06F51705DD8B469EF01F0A9
:1002C000D8B069EF01F0D8806F5170557B6F6DEF3A
:1002D00001F0D880200E70557B6F080E7B5DD8B47E
:1002E00077EF01F0D8A077EF01F0080E7B6F7D6B00
:1002F0008AEF01F070517D257C6F00EEA5F07C51F6
:10030000E926EF50606F02EE58F07D51E92660510A
:10031000EF6E7D2B7D517B5DD8A47AEF01F0580EF6
:1003200002011E6F020E1F6F00017B5102011D6F43
:100330001CAD9FEF01F0880E1C6FA1EF01F0C80EFD
:100340001C6F000170517B257E6F1F0E7E5DD8B43F
:10035000AEEF01F0D8A0AEEF01F07E6B7E51706F72
:10036000080E7B5DD791D8B4D7811200796F6F29C1
:100370007A6F200E7A5DD8A4BFEF01F07A6B00EEA1
:10038000A5F06F51E9267951EF6E7A516F6F120027
:1003900000EEC5F07251E926EF50E96F732B722918
:1003A000EA6F100EEA5DD8A4D7EF01F0EA6BEA51CC
:1003B000726FE95112007251715DE891D8A4E88121
:1003C0006091E8B16081120045EC01F0080E000177
:1003D000735DD8B4EFEF01F0D8A0F9EF01F002019E
:1003E00018BFF9EF01F0080E0001826F030E18EF3D
:1003F00001F01200686BC20E696F010E6A6F6B6BC1
:100400006C6B080E6E6F6D6B12000201F9510001EA
:10041000996F060E995DD8A4ABEF02F00201FB5173
:1004200000019A6F0201FA5100019B6FA06B010E4F
:100430009A5DD8A42EEF02F0120EA06F780E926F84
:10044000020E936F040E946F000E956F000E40091C
:10045000966FA05185EC00F08EEF02F0020E9A5DCF
:10046000D8A445EF02F0430EA06F780E926F020EF3
:10047000936F160E946F000E956F000E4009966FE5
:10048000A05185EC00F08EEF02F0030E9A5DD8A427
:100490008CEF02F09B51D8A45EEF02F0040EA06F27
:1004A000780E926F020E936F5A0E946F000E956F36
:1004B000000E4009966FA05185EC00F0010E00017E
:1004C0009B5DD8A474EF02F0360EA06F780E926F89
:1004D000020E936F5E0E946F000E956F000E400932
:1004E000966FA05185EC00F0020E00019B5DD8A430
:1004F0008EEF02F01E0EA06F780E926F020E936FB9
:10050000940E946F000E956F000E4009966FA051E7
:1005100085EC00F08EEF02F0220E9A5D0001A051F2
:10052000D8B4A9EF02F0080E9F6F0201FF51D8A4C2
:100530009FEF02F0FE5100019D6FA2EF02F0FF0E4F
:1005400000019D6F030EA26F9E6B0201049DA3EF3D
:1005500000F0FAEF00F0050E995DD8A4BCEF02F0B0
:100560000201FA510001A36F010EA16FE1EC00F04E
:10057000060E0001A26F1200090E995DD8A4F6EFD5
:1005800002F0060EA26FE1EC00F00F0154895485D1
:1005900054835487400E02010C6F080E096F300E11
:1005A0000A6F020E0B6F800E086F0F01558955857B
:1005B00055835587400E0201146F080E116F400ECF
:1005C000126F020E136F800E106F0F015689568541
:1005D00056835687400E02011C6F080E196F500E8D
:1005E0001A6F020E1B6F800E186F12000A0E995DB3
:1005F000D8A400EF03F0030EA26F010EEAEF00F0A3
:100600009951D8A407EF03F0000EEAEF00F01200B2
:10061000D8906330856FD8908533D890853363A4A4
:100620001EEF03F0D890020104310001876FD890CB
:1006300087330F0E8715866F28EF03F0D8900201DD
:1006400000310001876FD89087330F0E8715866FB2
:100650008551D8A41FEF04F00D0E865DD8A49EEF3F
:1006600003F0886B02EE20F08851E926EF50606FAE
:1006700002EEF8F08851E9266051EF6E882B080EE3
:10068000885DD8A432EF03F06498FEEC00F0300EE1
:100690000201F8150001876F8751D8A452EF03F0CB
:1006A00005EF02F0200E875DD8A498EF03F0020159
:1006B000F9510001896F230E895DD8A464EF03F01E
:1006C000060EA26FE1EF00F0200E895DD8A46CEF5A
:1006D00003F0020EA26F1200210E895DD8A48AEFEA
:1006E00003F0FF0E9D6F070EA06F780E926F020E43
:1006F000936F680E946F956B966BA05185EC00F02C
:10070000080E00019F6F030EA26F9E6B0201049DF5
:10071000A3EF00F0220E895DD8A497EF03F0060E38
:10072000A26FE1EC00F00201FA510001A46F120087
:10073000400E875DD8A491EF04F01200090E865D8B
:10074000D8A4C5EF03F0030EA25DD8A4AAEF03F06E
:10075000A3EF00F0060EA25DD8A4BBEF03F0A26BDE
:10076000010EA15DD8A491EF04F0A3510F015C6FBD
:100770000001A16B1200050EA25DD8B41200040E98
:10078000A25DD8B439EF01F01200020E865DD8A444
:10079000DFEF03F0030EA25DD8A4D1EF03F0A3EFC7
:1007A00000F0040EA25DD8A4D8EF03F039EF01F0F9
:1007B000060EA25DD8A491EF04F0A26B1200010E08
:1007C000865DD8A491EF04F0050EA25DD8A4ECEFED
:1007D00003F0A26BFEEF00F0020EA25DD8A413EFAF
:1007E00004F00201F9510001886F200E885DD8A441
:1007F00011EF04F0896B02EE20F08951E926EF50E9
:10080000606F00EE68F08951E9266051EF6E892B28
:10081000070E895DD8A4FBEF03F0060EA26FE1EC92
:1008200000F0FEEF00F0030EA25DD8A41DEF04F06F
:10083000FEEC00F00001A26B1200FEEF00F063A4DA
:1008400046EF04F0D8908535886FD8908837D890D7
:100850008837040E8827020E8825876F02EE00F085
:100860008751E926EF50896F030E8825876F02EEC6
:1008700000F08751E926EF508A6F8829876F030EB1
:10088000855DD8A491EF04F045EF01F0D89085354F
:10089000886FD8908837D8908837020E8825876F60
:1008A00002EE00F08751E926EF50896F030E88258C
:1008B000876F02EE00F08751E926EF508A6F882992
:1008C000876F02EE00F08751E926EF508B6F030E21
:1008D000855DD8A491EF04F08951E16E8A51E26EF2
:1008E0008D6B8CEF04F071298C6F100E8C5DD8A489
:1008F0007BEF04F08C6B8C51725DD8B48BEF04F0FD
:10090000E6508E6F00EEC5F07151E9268E51EF6E04
:100910008C51716F73078D2B8D518B5DD8A473EF44
:1009200004F01200A1A4E0EF04F0A1940001806B98
:1009300062A69EEF04F008EC03F062960001802BA3
:10094000040E805DD8A498EF04F062A0D2EF04F00A
:100950000F015F6B626A0001A36B0F01546B556B53
:10096000566B576B586B596B5A6B160E536F62A6CA
:10097000BDEF04F06296B7EF04F00001A26BA16B2B
:100980006498080E0201056F280E066F020E076FAD
:10099000046B080E016F200E026F020E036F8C0EA7
:1009A000006F629062BA629A62B8629862ACDCEFE1
:1009B00004F0E4EC01F0629C62A2E0EF04F06292C9
:1009C000120092EC04F045EF01F0646A140E616EBF
:1009D0006B0E606EA094FAEC01F0626A646A648641
:1009E0001200766FA451776F7751D8B412006F2937
:1009F000786F200E785DD8A4FFEF04F0786B0001CB
:100A00007851705DD8A409EF05F0E1EC04F0FFEF38
:100A100004F07651B6EF01F00001A451E66FE65103
:100A2000D8A416EF05F0609127EF05F0DBEC01F09C
:100A30000001E79360B1E783E7B322EF05F060912F
:100A400027EF05F0C8EC01F00001E56F6081E5518A
:100A500012000CEC05F00001E36FE35112000001FD
:100A60006051756F7551F1EF04F0DB51E06FDC51AF
:100A7000E16FE26B5AEF05F0DD51E225616F000E88
:100A80005E6EDE515E20626FDF515E20636F6151EA
:100A9000F66E6251F76E6351F86EF89C0900F550DE
:100AA000606FD851656FD951666FDA517EEC00F0F6
:100AB0000001E22BE251E05D606FE1516011D8A4CA
:100AC0003CEF05F01200F29EE5EC04F00001D78344
:100AD000E1EC04F00001A451D66FD651D8B489EFEF
:100AE00005F0D7B38AEF05F0D7835E0ED86F0A0EF4
:100AF000D96F000EDA6F1B0EDB6FDC6BB20EDD6F91
:100B0000000EDE6F000E4009DF6F35EC05F08AEF56
:100B100005F0D79329EC05F00001D56FD79960B1A6
:100B2000D789D7A968EF05F0D551606F2FEC05F094
:040B300068EF05F075
:020000040030CA
:0E0000000032211E0080C90003C003E003404F
:00000001FF
And here the code that made it

Code:
-- -----------------------------------------------------------------------------
-- Title: demo of usb_serial library
-- Author: Albert Faber, Copyright (c) 2009, all rights reserved.
-- Adapted-by: -
-- Compiler: >=2.4j
-- 
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php)
-- 
-- Description: This application demonstratesest USB Serial library, this application 
-- will emulate a RS-232 terminal device. Once the USB device has been detected by the 
-- host operating system, it will create a virtual COM port. When opening this COM
-- on the host computer, using a standard terminal application, it should show a
-- welcome message, after the welcome message all input characters are echoed back
-- to the terminal application
-- --
-- 
-- Sources: http://www.usb.org for USB specifications
-- 
-- Notes: compiled with following flags
-- -loader18 -no-fuse  ; when the microchip 18f bootloader is present
-- add -no-variable-reuse when debugging flags are set due to a compiler issue
-- -
-- Some instructions for use:
-- -
-- 1. Make sure you logon as administrator, or with administrator privileges,
--    on Windows XP.
-- 2. If needed convert to the correct PIC device (change include file), 
--    adapt fuses fuses and speed
-- 3. Create a basic board with USB PIC device
-- 4. Compile the this file and program the hex file into the PIC.
-- 5. After a (short) while you'll get the "new hardware found" message for
--    "JALLIB Serial". Point Windows manually to the driver in the
--    driver directory xp_drivers The drivers can be found at:
--    http://groups.google.com/group/jallib/ (usb_cdc_drivers_winxp32.zip)
--    Ignore the warning that this driver doesn't have a certificate. 
--    Wait for the installation to complete.
-- 6. Open the Windows Device Manager and check out the "ports" section. A new
--    communications port will be there, with a COM number.
-- 7. Open a terminal program (for example HyperTerminal) and select the COM
--    port you found in the previous step. Pick any baudrate, Windows will
--    accommodate automatically, and use 8-N-1-no for the other settings.
-- 8. Press enter and read the message. Now everything you type will be echoed
--    back.
-- 9. Have fun, adapt to your needs
--
-- ------------------------------------------------------
--
--
-- This file has been generated from:
--    * board: board_18f14k50_af.jal
--    * test : test_usb_serial.jal
--

;@jallib section chipdef
-- chip setup
include 18f14k50

-- This file is the setup for my homebrew, 18f14k50 board
-- Currently it is a bare board, with just a PIC and a couple of headers
-- A 12 MHz external crystal and 15pf caps connected to OSC1/2
-- pin 17 (Vusb) with a 220 nF capacitor to the ground
-- The connection between PC and the 18F14k50
-- +5v to power the board (don't forget 100nf decoupling cap
-- data- wire to pin 18 (D-)
-- data+ wire to pin 19 (D+)
-- ground wire to the Vss of the PIC
-- even though the external crystal is 12 MHz, the configuration is such that
-- the CPU clock is derived from the 96 Mhz PLL clock (div2), therefore set
-- target frequency to 48 MHz
pragma target clock       24_000_000

-- fuses
pragma target CPUDIV        P1              -- NO_CPU_SYSTEM_CLOCK_DIVIDE
pragma target USBDIV        P1              -- USB_CLOCK_COMES_DIRECTLY_FROM_THE_OSC1_OSC2_OSCILLATOR_BLOCK_NO_DIVIDE
pragma target OSC           HS
pragma target PLLEN         P4              -- OSCILLATOR_MULTIPLIED_BY_4
pragma target FCMEN         DISABLED
pragma target IESO          DISABLED
pragma target PWRTE         DISABLED        -- power up timer
pragma target BROWNOUT      DISABLED        -- no brownout detection
pragma target VOLTAGE       V30             -- brown out voltage
pragma target WDT           DISABLED        -- no watchdog
pragma target WDTPS         P32K            -- watch dog saler setting
pragma target MCLR          EXTERNAL        -- external reset
pragma target LVP           DISABLED        -- no low-voltage programming
pragma target XINST         ENABLED         -- extended instruction set
pragma target DEBUG         DISABLED        -- background debugging
pragma target CP0           DISABLED        -- code block 0 not protected
pragma target CP1           DISABLED        -- code block 1 not protected
pragma target CPB           DISABLED        -- bootblock code not write protected
pragma target WRT0          DISABLED        -- table writeblock 0 not protected
pragma target WRT1          DISABLED        -- table write block 1 not protected
pragma target WRTB          DISABLED        -- bootblock not write protected
pragma target WRTC          DISABLED        -- config not write protected
pragma target EBTR0         DISABLED        -- table read block 0 not protected
pragma target EBTR1         DISABLED        -- table read block 1 not protected
pragma target EBTRB         DISABLED        -- boot block not protected
pragma target HFOFST        ENABLED         -- THE_SYSTEM_CLOCK_IS_HELD_OFF_UNTIL_THE_HFINTOSC_IS_STABLE


include delay
include usb_serial
include print

-- constants
const  byte str_welcome[] = "JALLIB USB Serial Demo app\n"

-- variables

-- interrupts? No thanks
INTCON_GIE = false


-- setup the USB serial library
usb_serial_init()

var bit has_shown_welcome_msg = true
var byte ch

-- main loop
forever loop
	-- poll the usb ISR function on a regular base, in order to 
	-- serve the USB requests
	usb_serial_flush()
    
    -- check if USB device has been configured by the HOST
	if ( usb_cdc_line_status() !=  0x00 )  then
		if !has_shown_welcome_msg then
			has_shown_welcome_msg = true
			print_string( usb_serial_data, str_welcome )
		end if	
	else
		has_shown_welcome_msg = false
	end if

	-- check for input character
	if usb_serial_read( ch ) then
		-- echo input character
		usb_serial_data = ch
	end if
	
end loop
It's the easiest way I have found to use CDC and here the whole ball of wax
 

Attachments

  • Be80be_jal.zip
    15.6 MB · Views: 230
That code echo's what you type I also have USB to serial that works just like a com port the Zip is the whole compiler
 
I'm not sure from reading the help file, but "USB Device - CDC - Serial Emulator" may work both ways and may already be all you need to make an 18F14K50 into a pseudo-MCP2200. The help file isn't totally clear about it. I need to connect another PIC to this one and do some testing (doing that right away now). If it works then you'd just use Microchip's pre-compiled hex file supplied with the Microchip Application Libraries.
OK, I've tested. Microchip's pre-compiled hex file, "USB Device - CDC - Serial Emulator - C18 - Low Pin Count USB Development Kit.hex" does turn the 18F14K50 into a USB-UART converter. Works perfect.

Or you could use be80be's code.

Either way, don't forget the VUSB capacitor. You need a 470nF cap between pin 17 and ground (I've successfully used a 1.0uF - close enough).

18f14k50_usb005sm.JPG
 
Last edited:
It as good as swordfish it has 18f chips support and lots of cool stuff like fat file sys for hard-drives SD and USB
 
i'll give it a go t'morrow, thx guyz!!!

That VUSB cap....goes on pin 17 of the 14F18k50? Do i use the microchip mcp schematic for the converter?
 
i'll give it a go t'morrow, thx guyz!!!

That VUSB cap....goes on pin 17 of the 14F18k50? Do i use the microchip mcp schematic for the converter?
Ya, grab the MCP2200 Demo Board User Guide and look at the schematic in there. You can greatly simplify their schematic though. All you need is the 12MHz crystal and loading caps, the VUSB cap, a 0.1uF decoupling cap on power pins and maybe a MCLR pullup resistor. Look at the pics I posted - it's really simple.

The MCP2200 and this pseudo-MCP2200 are a bit more finicky than the CP2101/2 or the Prolific chip in the CA-42. Sometimes (always?) you have to start your terminal AFTER plugging in the USB to the 18F14K50. I haven't kept notes on its behaviour during various power cycling of different parts here, but there are situations when it just won't go until you shut it all down and start it all back up in the right order. I think the other chips are much less trouble - in particular, I really like the CP2102.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top