Code on other microcontroller not working

Discussion in 'Programmer's Corner' started by Drk_alien, Feb 28, 2013.

  1. Drk_alien

    Thread Starter New Member

    Feb 28, 2013
    14
    0
    Hello guys,i am new so, can anyone tell me where i have wrong?.I have a keyboard (PS2) connected to an 16f877a and nokia 3310 display.This circuit is working, when i type a letter is displayed on the display.The problem is when i change the microcontroller to 18f4550, it doesn't happend anything.
    To make the code more simple i made some changes.

    This is the code:
    I'm using pickit 2 clone, and microC pro for pic from MicroElectronika to write the code and compile.

    This code works on pic16f877a with 10 mhz oscilator
    I have no ideea what i should change to make this work on pif18f4550 (10 mhz) or pic18f2520(16 mhz).

    ps: the project is recompiled with this new settings the new microcontroller and new oscilator.
    I will be happy if anyone have an ideea...many Thanks
     
    Last edited: Feb 28, 2013
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Did you remember to change your configuration bits to match those of the new PIC?
     
  3. Drk_alien

    Thread Starter New Member

    Feb 28, 2013
    14
    0
    Now the code is a little bit smaller ...
    My bit configuration for pic16f877a is 2F4A (i have no ideea what that means)
    For 18f2520 is 0700 1f1f 8300 0085 C00F E00F 400F ( no ideea either )

    I use picKit 2 software v2.61

    Not all bits can be changed , only few. What should be the new configuration?...
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Compare your configuration bits and their meanings for the 16F877A from page 146 here, to the configuration bits for the 18F2520 on page 251 here, you'll notice there are many more configuration words in the 18F2520...
     
  5. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    The new MPLABX is much better, you can change the configuration bits in the IDE, there is a textual explanation for each line.

    Then you have a button to generate code to copy&paste it into a specially designed file: configuration_bits.c

    If your code still does not work then it is not watertight for use on different controllers, you have to take it apart, and put it back together step by step, adding means of testing if each step is doing what it should.
     
  6. Drk_alien

    Thread Starter New Member

    Feb 28, 2013
    14
    0
    I didn't understood much thing from those pages.
    And i didn't manage to change configuration bits from picKit2 software. When i'm loading the hex the bits are changing back.

    Doh.....it's frustrating.
     
  7. Drk_alien

    Thread Starter New Member

    Feb 28, 2013
    14
    0
    I want to use a more powerful microcontroller becouse i need to create a text file on 16mb SD card and i need mmc libraries....and so on.
    I'm stuck with my project ...haha.
     
  8. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Those pages describe the way the microcontroller will operate. They control everything from the clock source to the watchdog timer to code-protection. I would suggest becoming familiar with those terms and reading through the Configuration Bits section in the datasheet. From there, you should be able to understand what each bit in the configuration word(s) does.
     
  9. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    I don't know what your writecom() function does.

    Something that may be breaking your program is that in the PIC16 series, outputs are changed by writing to the Ports directly. On the PIC18 series, you need to write the new outputs into the Latches (LATA, LATB, etc), rather than Port.
     
  10. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I remember always writing to the PORT register when starting with the 18F. Found this from the datasheet:
    So that shouldn't present a problem...
     
  11. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Yes this might be one of the issues, I remember I had to change code here too.

    There is no such rule: Always write to PORT, or always write to LATCH.

    You have to understand how LATCH and PORT actually work (with different tristate), especially when they are read back and modified by some operations.

    Normally, reading is done from the PORT, and writing is done to the LATCH. That is what works best in my experience.
     
  12. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Can you simulate your code to see if it is trying to output to the LCD from the "compiler's point of view"?
     
  13. Drk_alien

    Thread Starter New Member

    Feb 28, 2013
    14
    0
    Yep...this was the solution ...using of Latches

    regarding to my code...
    i had to use this configuration ( LATB7_bit; instead of RB7_bit;)
    Thanks a lot...any little idea does great things.

    ps: i'm not that good at electronics , i am php programmer but that's one of my passions.
    If i will have more time i will study more this domain, but until then...i'm on track.
     
  14. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    I'd suggest trying to read the datasheet and understanding a bit of it, I know they are long and about as fun ot read as a.. datasheet. However, Microchip Data Sheets cover every aspect of the controller, so they tend to be long, but also answer every question.

    If you look at the pinned "Resources for PIC Programmers" which I believe is in the Embedded Systems subforum here, you'll find a link that is an "app note" for migrating designs from mid-range PICs to the PIC18 series, in addition to the latches and config word, some other things changed as well.

    The more you work with it, the more sense the datasheet will make, and vice-versa. The datasheet is a lifesaver, especially when you plan to use a hardware peripheral, such as the MMC, or USB onboard.
     
  15. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    I always work with them as my only resource.
     
  16. Drk_alien

    Thread Starter New Member

    Feb 28, 2013
    14
    0
    I will do so.Thank you very much.;) Great forum, fast answers.
    I think i will stay around for a long time.

    For sure i will need more help in future.:p
     
Loading...