PDA

View Full Version : Issue with 12F609



Harlequin
- 24th March 2013, 14:58
I have been using the 12F510 for a project for a while but chose to upgrade to the 12F609 because of the greater number of internal pullups and interrupts. Since size and part count are critical in my project I was running the 12F510 on the internal oscillator. This was going fine, but when I tried to get the 12F609 working I had no luck.
All I'm trying to do at this stage is get a simple port toggling programme running, once I've got that working my actual code can easily be ported from the 12F510 to the new PIC.
The toggle code is below.

#CONFIG
ifdef PM_USED
device pic12F609, intoscio, wdt_on, mclr_off, ioscfs_8mhz, protect_off
else
__config _INTOSCIO & _WDT_ON & _MCLRE_OFF & _IOSCFS_8MHZ & _CP_OFF
endif
#ENDCONFIG

DEFINE OSC 8

ANSEL = 00000000

TRISIO = 0

MAIN_LOOP:
high GPIO
pause 1000
low GPIO
pause 1000
goto main_loop

Obviously it just toggles the outputs each second. The code compiles fine and I uploaded it onto a PIC, then connected an LED up to GP2 (through a resistor) to monitor the state of the output.
When I powered the PIC up the code doesn't seem to run correctly. The LED will either be on or off constantly without changing.
I'm guessing that I've missed something in the configuration, but I don't know what. As far as I can tell the #config block is correctly set up for internal oscillator, 8MHz, digital I/O on all pins and MCLR off. Inputs are all set to digital (although that shouldn't matter when using the pins as outputs, if I'm reading the datasheet correctly) and all the pins are set as outputs.
I'm stumped as to why it doesn't work, but there must be something I've missed. If anyone could offer any suggestions I would be very appreciative.

Harlequin
- 25th March 2013, 04:55
I went back over the configs and fixed it up a bit- still no good.


#CONFIG
ifdef PM_USED
device pic12F609, intoscio, wdt_on, mclr_off, ioscfs_4mhz, protect_off
else
__config _INTOSCIO & _WDT_ON & _MCLRE_OFF & _IOSCFS_4MHZ & _CP_OFF
endif
#ENDCONFIG

DEFINE OSC 4

ANSEL = 00000000

TRISIO = 0
low GPIO

MAIN_LOOP:
high GPIO
pause 1000
low GPIO
pause 1000
goto main_loop

Acetronics2
- 25th March 2013, 07:30
HIGH GPIO

obviously ... you have forgotten something ... :rolleyes:

Alain

Dave
- 25th March 2013, 11:04
It looks from your code you are not setting the bit you want to toggle. the statement should be HIGH GPIO.2 or LOW GPIO.2. By saying just GPIO you are trying to set the entire port. Also if you are trying to use port pin 2 you are not setting it for output mode. That should be TRISIO.2 = 0 to set the port pin 2 to output. I hope this helps....

Dave
- 25th March 2013, 11:09
You need to set the port pin tris register for output that you are trying to use as an output. Your message says that you are trying to connect an led to port pin 2 but you are setting port pin 0 as an output. Also you are trying to set the entire port high instead of the individual pin. It should be HIGH GPIO.2

AvionicsMaster1
- 25th March 2013, 19:39
I'm ASSUMING the 12F683 and 12F609 are the same for GPIO and TRISIO commands. I'm also ASSUMING you can't tell a whole GPIO to turn on or off like you did with "high GPIO".

That being said your program should look like:

cmcon0 = 7 'turns comparators off
ansel = 0 'all ports digital
adcon0 = 0 ' adc off
trisio = %001000 ' all out except GPIO.3

define osc 8
osccon = %01110111 ' you need to check this but I'm pretty sure it's right to set up a stable 8 MHz internal oscillator

MAIN_LOOP:
high GPIO.2 'if LED is on GPIO.2
pause 1000
low GPIO.2
pause 1000
goto main_loop

If you look in the PBP2.6 manual it spells some more stuff out. They either forgot it in PBP3.0 or decided to keep you guessing.

Best Wishes

Acetronics2
- 26th March 2013, 16:07
Obviously ...

HIGH or LOW GPIO is an error ...

Alain

AvionicsMaster1
- 28th March 2013, 23:54
I've been looking for this thread for some time and haven't been able to find it again. I thought I'd only dreamt of the topic. Glad to see the admin Gods let it return.

One issue I found with my code is that it should be DEFINE OSC 8. I recently had the epiphany, after reading the manual of course, that defines are case sensitive. trisio, gpio, cmcon0, adcon0 and ansel are not case sensitive. Keep that in mind as it will save you many brain cells.