Jump to content


Photo

18f4550 serial interface with VB

18F4550 Firmware for UART com

  • Please log in to reply
2 replies to this topic

#1 Tom

Tom

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 11 November 2014 - 04:30 AM

Hello.

 

I have a project I need some help with, I newish to microcontrollers and the C language. I'm ok with VB and electronics. I've got some simple stand-alones to work so far after much tinkering.

 

I wrote a very simple program in VB to communicate with the microcontroller via serial (UART) cp201 (where I'm totally stuck) just to turn on a few leds and then turn them all off. The VB code is working along with the UART converter. It will TX when I click on a button in my VB program. 9600 baud, 8 bit, 1 stop no parody.

 

I have the data sheet for the pic and still do not know the proper code to communicate with the pic18F4550. 

 

I'm attaching my attempt at the pic code which I did get to compile but does not "work" when downloaded into the pic.  I left some older code in that I got from the data sheet (maybe still relevant) but commented out.

I think someone experienced in it could see the issues with the code immediately.

BTW I used MPLABX and xc8 compiler. (still learning how to use)

I am using the internal oscillator at 8 MHz (not sure if this is compatible with the UART communication) according to the data sheet  OSCCON should be set to 51 but my other simple stand alones use 0x76 (hex)

A simple working example will help out tremendously.

 

Any help feedback is appreciated.

TomAttached File  18f4550 UART interface.rtf   3.01KB   4 downloads

 

 


  • 0

#2 Nathan House

Nathan House

    Administrator

  • Administrators
  • 122 posts
  • LocationLynchburg, VA

Posted 12 November 2014 - 02:29 PM

Sorry for the late reply!

 

I actually haven't used XC8 yet (I've been meaning to transition to it) and so I'm not sure if your program is correct. Since I can't really help at the moment, what I would suggest doing is reposting your question on the Microchip forum.

 

Sometime in the next few months I'm planning on moving over to MPLAB X and the XC8 compiler, and hopefully will have time to update all of the tutorials on this site (there's one for serial communication if you didn't see it, but it doesn't use XC8).

 

Sorry I couldn't be of more help, but I'm afraid I'm a little "outdated" at the moment when it comes to PIC's!


  • 0

#3 Tom

Tom

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 13 November 2014 - 05:43 PM

Thanks Nathan,

 

I'll try the microchip forum.

 

I was looking into the serial communications and I know there is a clock rate that need to match the serial protocol being used. From what I've seen, (on the internet) most use a external crystal oscillator to bump up the frequency. Not sure if it is required on a simple turn on/of LED from a host program. Could just lower the baud rate?  

 

I think when we see how simple it really is, we will look back on it and wonder why we didn't get it.

 

When you know how to do it, it is easy. When you do not know how, it is difficult. <_< 


  • 0




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users