PDA

View Full Version : 12F675 Code Help



papa-smurf
- 3rd August 2004, 17:01
i'm new to pic programming and i have been stuck at the first hurdle for a while now. Can someone help me in writing a simple prog to flash a few leds on a pickit1. I have tried using bits and pieces on other threads but i haven't had any joy yet. So it would be greatly appreciated if someone could help me.

Thanks in advance

Dwayne
- 3rd August 2004, 20:35
Papa>>i'm new to pic programming and i have been stuck at the first hurdle for a while now. Can someone help me in writing a simple prog to flash a few leds on a pickit1. I have tried using bits and pieces on other threads but i haven't had any joy yet. So it would be greatly appreciated if someone could help me.<<




I believe the following will work ok for you...It is untested..but
I took it out of one of my programs...


LED var GPIO.1 'this is the pin the blinks a light.
ANSEL=0
CMCON=%00000111
TRISIO=%00001000 'assign output to the pins

Loop:
High LED
Pause 1000
Low LED
Pause 1000
goto Loop

End




Dwayne

papa-smurf
- 8th August 2004, 14:34
sorry Dwayne this didn't work for me, i got the same sort of result as i got from the other threads that i looked at.
result was


High LED gave this output

d0 - off
d1 - off
d2 - on
d3 - off
d4 - on
d5 - off
d6 - off
d7 - on

Low LED gave this output

d0 - off
d1 - off
d2 - on
d3 - off
d4 - on
d5 - off
d6 - dim
d7 - off

any more ideas would be appreciated

Melanie
- 8th August 2004, 15:51
Take Dwayne's code and just add some defines to the top of it... we're making assumptions that you know how to configure your PIC... this selection takes that assumption away... so you don't need an xtal, and you don't need to worry about MCLR either- just apply volts and it WILL run.



'
' PIC Defines
' -----------
@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal)
@ DEVICE pic12F675, WDT_ON
' Watchdog Timer
@ DEVICE pic12F675, PWRT_ON
' Power-On Timer
@ DEVICE pic12F675, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE pic12F675, BOD_ON
' Brown-Out Detect
@ DEVICE pic12F675, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic12F675, PROTECT_OFF
' Program Code Protection
'
' Dwayne's Blinky Bit
' -------------------
'
' Hardware Defines
' -----------------
LED var GPIO.1 ' This is the pin the blinks a light.
'
' PIC Initialisation
' ------------------
ANSEL=0
CMCON=%00000111
TRISIO=%00001000
'
' Main Program Loop
' -----------------
Loop:
High LED
Pause 1000
Low LED
Pause 1000
goto Loop

End


Don't forget to connect your LED via (a Resistor - say 330R) to pin GP1 (that's physical pin 6 of the PIC), BUT make sure you got the LED the right way around...

Either...

1. LED connected to Vdd (+5v)

Connect LED's Anode to Vdd and Kathode to the PIC (Resistor can be anywhere in series).

2. LED connected to Vss (0v)

Connect LED's Anode to the PIC, and the Kathode to Vss (again, the Resistor can be anywhere in series).

Melanie
- 8th August 2004, 16:03
I'm a little concerned as to what your d0 thru to d7 refers to... you say you have a 12F675, well that only has 6 I/O pins plus Vss and Vdd.

I don't have a circuit of a PICKit1, so I'm assuming your LED is on GP1... if it isn't, change the appropriate line in the code...

LED var GPIO.1 ' This is the pin the blinks a light.

...to reflect the line your LED is on.

Bruce
- 9th August 2004, 15:51
The PICkit1 has 8 LEDs all being controlled by GPIO.1, 2, 4 and 5.

If you want to blink a single LED, this will work to blink D7.

@ DEVICE PIC12F675, INTRC_OSC_NOCLKOUT, WDT_OFF, MCLR_OFF

ANSEL=0
CMCON=%00000111
TRISIO=0
LEDS VAR GPIO

Loop:
LEDS = 2
Pause 200
LEDS = 1
PAUSE 200
goto Loop

End

If you look at the PICkit1 schematic, you'll see why & how this works.