12F675 Code Help


Closed Thread
Results 1 to 6 of 6
  1. #1
    papa-smurf's Avatar
    papa-smurf Guest

    Post 12F675 Code Help

    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

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    papa-smurf's Avatar
    papa-smurf Guest


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

    Code:
    	'
    	'	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).

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.


  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by Bruce; - 9th August 2004 at 18:37.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. LANC code 12F675
    By MikeDD in forum General
    Replies: 4
    Last Post: - 9th May 2008, 05:44
  5. 12F675 code sample
    By marad73 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 23rd May 2006, 13:53

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts