+ Reply to Thread
Results 1 to 13 of 13

Thread: Stuck on Migrating 16F to 12F

  1. #1
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    447

    Default Stuck on Migrating 16F to 12F

    Hi to all,

    Can anyone help me with a problem I have in changing the PIC16F877A that this uses code to a 12F683.

    I have looked at the datasheets and the 683 seems to have all it needs but I am absolutely stuck with the different terminology used for the 12Fs to all the other 16F, 18F PICs.

    There must be something I'm missing here but why didn't they simply assign the 683 with PORTA instead of the GPIO terminology to keep all the syntax the same?

    I just thought I was learning a little when I needed to use a 683 and it all falls to pieces. The only decent examples for programs in the MEBasic are all for the larger PICs, with very little about the 12Fs and even then only the most basic of programs with not much hope of me learning from them.

    If anyone could show me how to migrate this program or indeed give me an example of another MEBasic program for both 12F and 16F that I could compare then I would be very grateful and it would help my learning along nicely.






    Code:
    ' *
    ' * Project name
    '     PWM_Test_01 (PWM1 library Demonstration)
    ' * Copyright
    '     (c) mikroElektronika, 2008
    ' * Revision History
    '     20080225
    '       - initial release.
    ' * Description
    '     This is a simple demonstration of PWM1 library, which is being used for
    '     control of the PIC's CCP module. The module is initialized and started,
    '     after which the PWM1 Duty Ratio can be adjusted by means of two buttons
    '     connected to pins RA0 and RA1. The changes can be monitored on the CCP
    '     output pin (RC2).
    ' * Test configuration
    '     MCU:            PIC16F877A
    '     Dev.Board:      EasyPIC5
    '     Oscillator:     HS, 08.0000 MHz
    '     Ext. Modules:    -
    '     SW:             mikroBasic v7.1
    ' * NOTES
    '     - Pull-down PORTA and connect button jumper (jumper17) to Vcc. (board specific)
    '*
    
    program PWM_Test_01
    
    dim current_duty, old_duty as byte
    
    sub procedure InitMain()
      PORTA  = 255
      TRISA  = 255                       ' configure PORTA pins as input
      PORTB  = 0                         ' set PORTB to 0
      TRISB  = 0                         ' designate PORTB pins as output
      ADCON1 = 7                         ' all ADC pins to digital I/O
    
      PORTC = 0                          ' set PORTC to 0
      TRISC = 0                          ' designate PORTC pins as output
      PWM1_Init(5000)                    ' Initialize PWM1 module at 5KHz
    end sub
    
    main:
      initMain()
      current_duty     = 16              ' initial value for current_duty
      old_duty    = 0                    ' old_duty will keep the 'old current_duty' value
      PWM1_Start()                       ' start PWM1
      while TRUE
                                         ' endless loop
        if (Button(PORTA, 0,1,1)) then   ' button on RA0 pressed
          Inc(current_duty)              '    increment current_duty
        end if
        if (Button(PORTA, 1,1,1)) then   ' button on RA1 pressed
          Dec(current_duty)              '    decrement current_duty
        end if
        if (old_duty <> current_duty) then  ' if change in duty cycle requested
          PWM1_Change_Duty(current_duty)    '    set new duty ratio,
          old_duty = current_duty           '    memorize it
          PORTB = old_duty                  '    and display on PORTB
        end if
        Delay_ms(20)                       ' slow wn change pace a little
      wend
    end.
    

    Thanks for looking.........Al
    Last edited by bigal_scorpio; 22nd October 2008 at 04:25 PM.
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!


  2. #2
    skyhawk Excellent skyhawk Excellent skyhawk Excellent skyhawk Excellent
    Join Date
    Feb 2007
    Location
    Morgantown, WV
    Posts
    197

    Default

    There must be something I'm missing here but why didn't they simply assign the 683 with PORTA instead of the GPIO terminology to keep all the syntax the same?
    There is only one port on 8-pin PICs. It's called GPIO. It's also a 6-pin port. Your code references PORTA, PORTB, and PORTC.

  3. #3
    SMUGangsta Good SMUGangsta Good
    Join Date
    Oct 2008
    Location
    Wales, Centre of the Universe
    Posts
    219

    Default

    Have the datsheets for both next to you, as mE has all the ports defined as in the microchip data sheets, and convert from their.

    for example it will be GPIO.4 rather than PORTA.4 and i think its TRISIO instead of TRISA etc. this caught me out a few weeks back, but by reading the header files in the mE folder for my 12F chip, it showed all the designations, so i just worked through the list checking my 16F628 code and changing it where neccesary.
    There will come a day when PICs will rule the world!

  4. #4
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    447

    Default

    Quote Originally Posted by skyhawk View Post
    There is only one port on 8-pin PICs. It's called GPIO. It's also a 6-pin port. Your code references PORTA, PORTB, and PORTC.
    Hi Skyhawk,

    Yeah I know its only got one port, my car has 4 wheels. A unicycle only has 1 but they still call it a wheel! So why not maintain some kind of pattern?

    Also I realise the code uses 3 ports but if you read it then you would realise that there are only 4 actual pins being used, and one of them is just to enable measurement of the PWM, so the 683 should still have 2 spare!

    My point is why confuse things with different aliases, if it walks like a duck.......

    Al
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!

  5. #5
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    447

    Default

    Quote Originally Posted by SMUGangsta View Post
    Have the datsheets for both next to you, as mE has all the ports defined as in the microchip data sheets, and convert from their.

    for example it will be GPIO.4 rather than PORTA.4 and i think its TRISIO instead of TRISA etc. this caught me out a few weeks back
    Hi SMUGangsta,

    Yes, thats my point exactly! Who designs these things? They must be very smart but then again they say the smartest people in the world have little common sense.

    Thanks mate.......Al
    Last edited by bigal_scorpio; 22nd October 2008 at 06:44 PM.
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!

  6. #6
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,711
    Blog Entries
    5

    Default

    You could always modify the .inf files and add the tris & port defines.
    I never understood why the naming convention was done either.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  7. #7
    picasm Good picasm Good
    Join Date
    Sep 2006
    Location
    UK
    Posts
    358

    Default

    I think the different port naming on the 12f chips probably dates back to when they first introduced the 12c series.
    At that time, existing chips such as the 16c84 did not make very efficient use of all pins. eg. they usually had separate pins for ports, oscillator and mclr.
    To make full use of only 8 pins aavailable in the 12c chips they had to make some do multi-functions - perhaps that is why they called them "General Purpose"

  8. #8
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    447

    Default

    Quote Originally Posted by blueroomelectronics View Post
    You could always modify the .inf files and add the tris & port defines.
    I never understood why the naming convention was done either.
    Hi Bill,

    That does sound interesting, but I have never messed with the inf files, can you give me an example?

    Thanks....Al
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!

  9. #9
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,795

    Default

    Quote Originally Posted by bigal_scorpio View Post
    Hi Bill,

    That does sound interesting, but I have never messed with the inf files, can you give me an example?

    Thanks....Al
    It's the INC files, niot the INF files.

    It's just a simple text substitution, here's a section from the 16F84.inc file

    Code:
    PORTA                        EQU     H'0005'
    PORTB                        EQU     H'0006'
    
    It you wanted to use GPIO instead of PORTA (and as well as), just add an extra line:

    PORTA EQU H'0005'
    GPIO EQU H'0005'
    PORTB EQU H'0006'
    It's really as simple as that - any occurance of PORTA or GPIO in the source code would be replaced by 'H'0005' during assembly.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  10. #10
    skyhawk Excellent skyhawk Excellent skyhawk Excellent skyhawk Excellent
    Join Date
    Feb 2007
    Location
    Morgantown, WV
    Posts
    197

    Default

    Also I realise the code uses 3 ports but if you read it then you would realise that there are only 4 actual pins being used, and one of them is just to enable measurement of the PWM, so the 683 should still have 2 spare!
    I don't do BASIC so I could be mistaken, but the way that I read it is:

    PORTA - two input pins, increment and decrement buttons
    PORTB - output for a number 0-16, requires at least 5 pins
    PORTC - PWM output

    At the very least your TRIS is going to be split between input and output, not like the example where a port is entirely input or output.

    I looked at the documentation

    http://www.mikroe.com/pdf/mikrobasic...sic_manual.pdf

    It seems to suggest that the the PWM library only works for chips with a PWM module on PORTC. Maybe there is an exception for 8-pin PICs or maybe you are going to have to write your own routine loading data into SFRs. That shouldn't be hard, just read the datasheet for the 12F683.

    edit: Looking more closely it looks as though all 8 bits of PORTB are used to display the duty cycle.
    Last edited by skyhawk; 22nd October 2008 at 10:58 PM.

  11. #11
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    447

    Default

    Hi Nigel,

    Hows things going down your way mate?

    Thanks for that info, I see how it works now, its a bit like declaring aliases.

    BTW I used the ESR meter yesterday to find a fault in a power transformer that the DMM said was ok! More uses for it all the time.

    Al
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!

  12. #12
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,795

    Default

    Quote Originally Posted by bigal_scorpio View Post
    Hi Nigel,

    Hows things going down your way mate?

    Thanks for that info, I see how it works now, its a bit like declaring aliases.
    Yes, it looks a bit confusing, but once you realise it's just a simple text substitution it makes more sense.


    BTW I used the ESR meter yesterday to find a fault in a power transformer that the DMM said was ok! More uses for it all the time.
    Glad you found a use for it, I never got rouind to finishing it off
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  13. #13
    bigal_scorpio Good bigal_scorpio Good
    Join Date
    Oct 2007
    Location
    Rotherham South Yorkshire England
    Posts
    447

    Talking Problem solved!

    Hi guys,

    Thanks for all the info.

    I have now decided on a PIC16F872, as it was pointed out to me that the PWM library in MeBasic only supports the C port and I am not confident enough to write my own PWM routine.

    Circuit will be a bit larger but at least I can do it now!

    Thanks again...........Al
    The Doctor just told me I have short term memory problems and he told me I have short term memory problems!

+ Reply to Thread

Similar Threads

  1. migrating from 8051 to AVR!
    By ikalogic in forum AVR
    Replies: 5
    Latest: 3rd May 2008, 11:16 AM
  2. migrating code 16F84 ==> 16F628A
    By whiz115 in forum Micro Controllers
    Replies: 8
    Latest: 14th March 2008, 10:56 PM
  3. Migrating 16c57 to 16F57
    By j_norrie in forum Micro Controllers
    Replies: 6
    Latest: 31st July 2006, 03:03 PM
  4. stuck
    By stuck on electronics in forum Electronic Projects Design/Ideas/Reviews
    Replies: 2
    Latest: 12th June 2005, 05:13 AM
  5. stuck
    By Phish7608 in forum Electronic Projects Design/Ideas/Reviews
    Replies: 1
    Latest: 8th March 2004, 04:25 PM

Tags for this Thread