Hi,
I've just started a project using a PIC12F675.
Just to get started I'm trying to drive all of the port pins high, but
I'm having no success. I'm aware that the ports have multiple
functions and need to be set up. I don't seem to have nay control over any
of the pins. I'm using HI Tec PICC lite embedded into MPLAB 8.1.
My code is:
/* PIC 12F flash.c */
#include "pic12f6x.h"
void main()
{
STATUS = 0b00000000; // Bank 0
CMCON = 0x07;
STATUS = 0b00100000; // Bank 1
WPU = 0b00110111;
ANSEL = 0;
TRISIO = 0x00;
STATUS = 0x00;
GPIO = 0x3F;//(1<<4);
while(1);
}
Could some one please indicate what I have missed.
Kind regards
Andrew
problems with PIC12F675 GPIO
Started by ●October 6, 2009
Reply by ●October 8, 20092009-10-08
Erm, it's a long time since I played with HiTech C but as far as I
recall bank selection is transparent to the programmer. In other words
you don't need to fiddle with bank registers because the compiler
takes care of that for you. Your example seems to follow the assembly
language example in the manual which didles with the STATUS register.
I may be totally wrong but I would suggest removing the STATUS
statements and trying again. Take a look at the assembler listing
output that the compiler produces, I _think_ you'll see the automatic
bank selection in action.
Also, it may not hurt to clear GPIO before you setup the port
directions. For various reasons I used to assign a separate variable
as a holder for the GPIO value, then change the variable as required
and copy the variable to the GPIO register each time it needed update.
Sorry, I don't have time right now to dig through my old examples.
Good luck.
On 10/7/09, ajellisuk wrote:
> Hi,
>
> I've just started a project using a PIC12F675.
>
> Just to get started I'm trying to drive all of the port pins high, but I'm
> having no success. I'm aware that the ports have multiple functions and need
> to be set up. I don't seem to have nay control over any of the pins. I'm
> using HI Tec PICC lite embedded into MPLAB 8.1.
>
> My code is:
>
> /* PIC 12F flash.c */
>
> #include "pic12f6x.h"
>
> void main()
> {
>
> STATUS = 0b00000000; // Bank 0
> CMCON = 0x07;
>
> STATUS = 0b00100000; // Bank 1
> WPU = 0b00110111;
> ANSEL = 0;
> TRISIO = 0x00;
> STATUS = 0x00;
> GPIO = 0x3F;//(1<<4);
>
> while(1);
> }
>
> Could some one please indicate what I have missed.
>
> Kind regards
>
> Andrew
>
recall bank selection is transparent to the programmer. In other words
you don't need to fiddle with bank registers because the compiler
takes care of that for you. Your example seems to follow the assembly
language example in the manual which didles with the STATUS register.
I may be totally wrong but I would suggest removing the STATUS
statements and trying again. Take a look at the assembler listing
output that the compiler produces, I _think_ you'll see the automatic
bank selection in action.
Also, it may not hurt to clear GPIO before you setup the port
directions. For various reasons I used to assign a separate variable
as a holder for the GPIO value, then change the variable as required
and copy the variable to the GPIO register each time it needed update.
Sorry, I don't have time right now to dig through my old examples.
Good luck.
On 10/7/09, ajellisuk wrote:
> Hi,
>
> I've just started a project using a PIC12F675.
>
> Just to get started I'm trying to drive all of the port pins high, but I'm
> having no success. I'm aware that the ports have multiple functions and need
> to be set up. I don't seem to have nay control over any of the pins. I'm
> using HI Tec PICC lite embedded into MPLAB 8.1.
>
> My code is:
>
> /* PIC 12F flash.c */
>
> #include "pic12f6x.h"
>
> void main()
> {
>
> STATUS = 0b00000000; // Bank 0
> CMCON = 0x07;
>
> STATUS = 0b00100000; // Bank 1
> WPU = 0b00110111;
> ANSEL = 0;
> TRISIO = 0x00;
> STATUS = 0x00;
> GPIO = 0x3F;//(1<<4);
>
> while(1);
> }
>
> Could some one please indicate what I have missed.
>
> Kind regards
>
> Andrew
>
Reply by ●October 10, 20092009-10-10
Hi Phil,
Thanks for your reply.
I have stumbled across the solution by accident. I needed to add the line:
__CONFIG(INTIO & WDTEN & MCLRDIS & BORDIS & UNPROTECT & PWRTEN);
to my code. Now that I have full control of the port pins I can press on.
Kind regards
Andrew
--- In p..., Phil Seakins wrote:
>
> Erm, it's a long time since I played with HiTech C but as far as I
> recall bank selection is transparent to the programmer. In other words
> you don't need to fiddle with bank registers because the compiler
> takes care of that for you. Your example seems to follow the assembly
> language example in the manual which didles with the STATUS register.
>
> I may be totally wrong but I would suggest removing the STATUS
> statements and trying again. Take a look at the assembler listing
> output that the compiler produces, I _think_ you'll see the automatic
> bank selection in action.
>
> Also, it may not hurt to clear GPIO before you setup the port
> directions. For various reasons I used to assign a separate variable
> as a holder for the GPIO value, then change the variable as required
> and copy the variable to the GPIO register each time it needed update.
>
> Sorry, I don't have time right now to dig through my old examples.
>
> Good luck.
>
> On 10/7/09, ajellisuk wrote:
> >
> >
> >
> >
> >
> >
> > Hi,
> >
> > I've just started a project using a PIC12F675.
> >
> > Just to get started I'm trying to drive all of the port pins high, but I'm
> > having no success. I'm aware that the ports have multiple functions and need
> > to be set up. I don't seem to have nay control over any of the pins. I'm
> > using HI Tec PICC lite embedded into MPLAB 8.1.
> >
> > My code is:
> >
> > /* PIC 12F flash.c */
> >
> > #include "pic12f6x.h"
> >
> > void main()
> > {
> >
> > STATUS = 0b00000000; // Bank 0
> > CMCON = 0x07;
> >
> > STATUS = 0b00100000; // Bank 1
> > WPU = 0b00110111;
> > ANSEL = 0;
> > TRISIO = 0x00;
> > STATUS = 0x00;
> > GPIO = 0x3F;//(1<<4);
> >
> > while(1);
> > }
> >
> > Could some one please indicate what I have missed.
> >
> > Kind regards
> >
> > Andrew
> >
> >
>
Thanks for your reply.
I have stumbled across the solution by accident. I needed to add the line:
__CONFIG(INTIO & WDTEN & MCLRDIS & BORDIS & UNPROTECT & PWRTEN);
to my code. Now that I have full control of the port pins I can press on.
Kind regards
Andrew
--- In p..., Phil Seakins wrote:
>
> Erm, it's a long time since I played with HiTech C but as far as I
> recall bank selection is transparent to the programmer. In other words
> you don't need to fiddle with bank registers because the compiler
> takes care of that for you. Your example seems to follow the assembly
> language example in the manual which didles with the STATUS register.
>
> I may be totally wrong but I would suggest removing the STATUS
> statements and trying again. Take a look at the assembler listing
> output that the compiler produces, I _think_ you'll see the automatic
> bank selection in action.
>
> Also, it may not hurt to clear GPIO before you setup the port
> directions. For various reasons I used to assign a separate variable
> as a holder for the GPIO value, then change the variable as required
> and copy the variable to the GPIO register each time it needed update.
>
> Sorry, I don't have time right now to dig through my old examples.
>
> Good luck.
>
> On 10/7/09, ajellisuk wrote:
> >
> >
> >
> >
> >
> >
> > Hi,
> >
> > I've just started a project using a PIC12F675.
> >
> > Just to get started I'm trying to drive all of the port pins high, but I'm
> > having no success. I'm aware that the ports have multiple functions and need
> > to be set up. I don't seem to have nay control over any of the pins. I'm
> > using HI Tec PICC lite embedded into MPLAB 8.1.
> >
> > My code is:
> >
> > /* PIC 12F flash.c */
> >
> > #include "pic12f6x.h"
> >
> > void main()
> > {
> >
> > STATUS = 0b00000000; // Bank 0
> > CMCON = 0x07;
> >
> > STATUS = 0b00100000; // Bank 1
> > WPU = 0b00110111;
> > ANSEL = 0;
> > TRISIO = 0x00;
> > STATUS = 0x00;
> > GPIO = 0x3F;//(1<<4);
> >
> > while(1);
> > }
> >
> > Could some one please indicate what I have missed.
> >
> > Kind regards
> >
> > Andrew
> >
> >
>