• 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.

Stuck on Migrating 16F to 12F

Status
Not open for further replies.

bigal_scorpio

Active Member
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:

skyhawk

New Member
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.
 

SMUGangsta

New Member
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.
 

bigal_scorpio

Active Member
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
 

bigal_scorpio

Active Member
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:

blueroomelectronics

Well-Known Member
You could always modify the .inf files and add the tris & port defines. :)
I never understood why the naming convention was done either.
 

picasm

Member
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"
 

bigal_scorpio

Active Member
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
 

Nigel Goodwin

Super Moderator
Most Helpful Member
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.
 

skyhawk

New Member
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.electro-tech-online.com/custompdfs/2008/10/mikrobasic_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:

bigal_scorpio

Active Member
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
 

Nigel Goodwin

Super Moderator
Most Helpful Member
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 :D
 

bigal_scorpio

Active Member
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
 
Status
Not open for further replies.

EE World Online Articles

Loading

 
Top