12f675_fuse_about_to_blow!


Closed Thread
Results 1 to 40 of 929

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Here is some code to do most of what your pic was originally programmed to do.
    I think it will run on the demo, if it is too long then just comment out the last couple of statements in the main.
    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
    'DEFINE OSC 4
    'DEFINE ADC_CLOCK 1
    'OSCCAL=%10000000
    'GPIO = 0 ' set all outputs low
    TRISIO = %00000001 'Set GPIO.0 to input
    cmcon = 7 'Disable analog comparators
    ANSEL = 1 
    'PCON =  %00000011    ' Bit 0 BOD 0=on 1=off bit 1 POR 0=on 1=off
    ADCON0 =%00000011   ' SET CHANNEL 0 RT JUSTIFIED VREF - VDD
                        ' BIT 7 1 LT JUSTIFY 0 RT JUSTIFY
                        ' BIT 6 1 = VREF 0 = VDD
                        ' BIT 5:4 UNIMPLEMENTED
                        ' BIT 3:2 00 CH 0
                        '         01 CH 1
                        '         10 CH 2
                        '         11 CH 3
    
    
    DELAY VAR WORD
    
    main:
    ADCIN 0,DELAY
    DELAY = (DELAY * 4)
    TRISIO = %11111001
    GPIO   = %00000010 'LED 7 ON
    PAUSE DELAY
    GPIO   = %00000100  'LED 6 ON
    PAUSE DELAY
    TRISIO = %11011011
    GPIO   = %00000100  'LED  5 ON
    PAUSE DELAY
    GPIO   = %00100000  'LED4 ON
    PAUSE DELAY
    ADCIN 0,DELAY       ' RECHECK A/D AND RECALIBRATE
    DELAY = (DELAY * 4)
    TRISIO = %11101011
    GPIO   = %00000100  ' led 3 ON
    PAUSE DELAY
    GPIO   = %00010000   'led 2 ON
    PAUSE DELAY
    TRISIO = %11001111
    GPIO   = %00100000
    PAUSE DELAY
    GPIO   = %00010000
    'PAUSE DELAY
    goto main
    After you play with these you may be ready to order PBP. Then you can UnComment the rest of this code.
    Last edited by Archangel; - 22nd February 2010 at 05:15.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi Joe

    Thanks for the two programs, I'm having problems running them though. They won't won't compile in Micro code studio without errors. I'm guessing the first program won't because it's for the 12F675 which isn't supported. I did try and copy-paste them into MPL-Labs-IDE I'm so hopeless I couldn't even do that!

    Could you post up the HEX code files please and I'll see if they run.

    I must say though that parts of the programs are beyond me at present (although I do recognise a lot of the terms contained within) I'm still learning to walk as it were. I will get there though. I might not be the brightest diamond in the tiara but I am persistent....lol.

    Dave

  3. #3
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Here's tonight efforts. Two programs that do exactly the same thing only differently, namely flash LED 'D0' on the PICkit1. One prog using: TRISIO/GPIO/HIGH/LOW the other using: OUTPUT statements.


    If anyone would care to comment on the accuracy of what I'm doing / saying it would be much appreciated: Dave


    PROG 1:

    ANSEL = %00000000
    CMCON0 = %00000111
    TRISIO = %11001111
    GPIO = %11011111

    Start
    main
    PAUSE 500 ' wait 500mili_secs
    HIGH GPIO.4 ' 'D0' HIGH turns LED-ON +5 volts
    PAUSE 500 ' wait 500mili_secs
    LOW GPIO.4 ' 'DO' LOW turns LED-OFF zero volts
    goto MAIN ' start all over again

    ---------------------------------------------------------------------
    PROG 2:

    ANSEL = %00000000
    CMCON0 = %00000111
    OUTPUT GPIO.4 ' Makes GPIO an output
    LOW GPIO.5 ' Makes GPIO.5 zero volts

    Start
    main
    PAUSE 500 ' wait 500mili_secs
    HIGH GPIO.4 ' 'D0' HIGH turns LED-ON +5 volts
    PAUSE 500 ' wait 500mili_secs
    LOW GPIO.4 ' 'DO' LOW turns LED-OFF
    goto MAIN ' start all over again
    Last edited by LEDave; - 22nd February 2010 at 22:11.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    That is the best way to learn, try things.

    Let us know the results
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi mackrackit.

    Both the programs work and do the same thing. Thing is are these programs accurate? Because I don't fully understand what I'm doing (yet) I'm assuming they are because they work. I just have that nagging feeling I've lucked in again.

    Dave

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I just have that nagging feeling I've lucked in again.
    I know what you mean...
    I feel the same way when my code works

    If they work they are "accurate". There is always more than one way to do anything. With MCUs we try to find the way that uses the least amount of code space, but that will come.

    The test board you have is a little different than what most people use(I do not hear of many here using the PICkit1) so you have to do things just a bit differently. Every LED you want to turn on you have to deal with two pins. One HIGH and one LOW. To turn on some of the LEDs you will also have to make a third pin an INPUT.

    So now try to do the sequence LEDs 1-3 using HIGH/LOW. You will see what I mean.

    Another thing about the HIGH/LOW commands. They over ride the TRIS settings.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    "The test board you have is a little different than what most people use (I do not hear of many here using the PICkit1)"

    What do most on here use?

    "So now try to do the sequence LEDs 1-3 using HIGH/LOW. You will see what I mean."

    Tomorrow's challenge....!

    "Every LED you want to turn on you have to deal with two pins. One HIGH and one LOW. To turn on some of the LEDs you will also have to make a third pin an INPUT."

    It is strange (to me anyway) how Microchip have configured the LED's on the PICkit1.

    I'm off to bed now, see you tomorrow.

    Dave

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Here is some code to do most of what your pic was originally programmed to do.
    I think it will run on the demo, if it is too long then just comment out the last couple of statements in the main.
    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
    'DEFINE OSC 4
    'DEFINE ADC_CLOCK 1
    'OSCCAL=%10000000
    'GPIO = 0 ' set all outputs low
    TRISIO = %00000001 'Set GPIO.0 to input
    cmcon = 7 'Disable analog comparators
    ANSEL = 1 
    'PCON =  %00000011    ' Bit 0 BOD 0=on 1=off bit 1 POR 0=on 1=off
    ADCON0 =%00000011   ' SET CHANNEL 0 RT JUSTIFIED VREF - VDD
                        ' BIT 7 1 LT JUSTIFY 0 RT JUSTIFY
                        ' BIT 6 1 = VREF 0 = VDD
                        ' BIT 5:4 UNIMPLEMENTED
                        ' BIT 3:2 00 CH 0
                        '         01 CH 1
                        '         10 CH 2
                        '         11 CH 3
    
    
    DELAY VAR WORD
    
    main:
    ADCIN 0,DELAY
    DELAY = (DELAY * 4)
    TRISIO = %11111001
    GPIO   = %00000010 'LED 7 ON
    PAUSE DELAY
    GPIO   = %00000100  'LED 6 ON
    PAUSE DELAY
    TRISIO = %11011011
    GPIO   = %00000100  'LED  5 ON
    PAUSE DELAY
    GPIO   = %00100000  'LED4 ON
    PAUSE DELAY
    ADCIN 0,DELAY       ' RECHECK A/D AND RECALIBRATE
    DELAY = (DELAY * 4)
    TRISIO = %11101011
    GPIO   = %00000100  ' led 3 ON
    PAUSE DELAY
    GPIO   = %00010000   'led 2 ON
    PAUSE DELAY
    TRISIO = %11001111
    GPIO   = %00100000
    PAUSE DELAY
    GPIO   = %00010000
    'PAUSE DELAY
    goto main
    After you play with these you may be ready to order PBP. Then you can UnComment the rest of this code.
    Here is this hex:
    Code:
    :020000040000FA
    :1000000052280F39A0000310A00DA00D1F08E039E1
    :10001000200401389F000030A100323023209F14BB
    :100020009F181028A1011E084D28A301A200FF302F
    :10003000A207031CA307031C4D280330A100DF30D7
    :1000400023201728A101E83EA000A109FC30031CD1
    :100050002C28A00703182928A0076400A10F29282D
    :1000600020183228A01C362800003628080010303E
    :10007000A800A101A001A70CA60C031C452822087A
    :10008000A00723080318230FA107A10CA00CA50C9F
    :10009000A40CA80B3B2824084D28831303138312B8
    :1000A0006400080083168030900083128501831657
    :1000B00001308500831207309900831601309F00BC
    :1000C00003308E00831203309F0000300120B800FF
    :1000D0002108B9003808A6003908A7000430A2009A
    :1000E000A3013720B8002508B9008316F930850030
    :1000F0008312023085003908A30038081620043026
    :1001000085003908A300380816208316DB308500E7
    :100110008312043085003908A300380816202030E7
    :1001200085003908A3003808162000300120B800E7
    :100130002108B9003808A6003908A7000430A20039
    :10014000A3013720B8002508B9008316EB308500DD
    :100150008312043085003908A300380816201030B7
    :1001600085003908A300380816208316CF30850093
    :100170008312203085003908A3003808162010307B
    :1001800085003908A3003808162065286300C628B2
    :02400E00DC3F95
    :00000001FF
    I uncommented that which was commented.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    It is strange (to me anyway) how Microchip have configured the LED's on the PICkit1.
    In the long run you will be happy that you are learning on the PICkit1. Many do not learn about TRIS until something does not work. Another nice thing about the LEDs this way is that 8 LEDs can be controlled with 4 pins from the PIC.
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi Joe

    Very impressed with the two programs you posted, thanks for those and very clever. The coding in parts is way beyond me at present but the effect on my PIC1 board are great and shows what can be done.

    I'll try and do the sequence mackrackit suggested today (time permitting).

    "So now try to do the sequence LEDs 1-3 using HIGH/LOW."

    It sounds straight forward enough (ish) but I've just got a feeling.......!

    Dave

  11. #11
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi mackrackit. I've been working like a Beaver this PM and have come up with this program to your: "So now try to do the sequence LEDs 1-3 using HIGH/LOW." exercise. If you get a minute could check my program comments for accuracy please, because I'm making assumptions the conclusions I'm drawing are accurate and they may well not be. The program does work though:Many thanks: Dave


    ANSEL = %00000000
    CMCON0 = %00000111

    Sart
    MAIN
    OUTPUT GPIO.5 ' Makes GPIO.5 an output
    LOW GPIO.4 ' Makes GPIO.4 zero volts
    HIGH GPIO.5 ' D1 HIGH turns LED-ON +5 volts
    PAUSE 500 ' wait 500mili_secs
    LOW GPIO.5 ' D1 LOW turns LED-OFF
    PAUSE 500 ' wait 500mili_secs

    INPUT GPIO.5 ' Stops cross-feed to other Diodes
    OUTPUT GPIO.4 ' Makes GPIO.4 an output
    LOW GPIO.2 ' Makes GPIO.2 zero volts
    HIGH GPIO.4 ' D2 HIGH turns LED-ON +5 volts
    PAUSE 500 ' wait 500mili_secs
    LOW GPIO.4 ' D2 LOW turns LED-OFF
    INPUT GPIO.2 ' Stops cross-feed to other Diodes
    PAUSE 500 ' wait 500mili_secs

    OUTPUT GPIO.2 ' Makes GPIO.2 an output
    LOW GPIO.4 ' Makes GPIO.4 zero volts
    HIGH GPIO.2 ' D3 HIGH turns LED-ON +5 volts
    PAUSE 500 ' wait 500mili_secs
    LOW GPIO.2 ' D3 LOW turns LED-OFF
    INPUT GPIO.2 ' Stops cross-feed to other Diodes
    PAUSE 500 ' wait 500mili_secs

    goto MAIN ' start all over again
    Last edited by LEDave; - 23rd February 2010 at 18:07.

  12. #12
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    So here's a question (or yet another question to be more accurate here).

    Is it possible to use multiple OUTPUT & HIGH statements on one line for example:

    OUTPUT GPIO.0 GPIO.1 GPIO.2

    As opposed to:

    OUTPUT GPIO.0
    OUTPUT GPIO.1
    OUTPUT GPIO.2

    Followed by:

    HIGH GPIO.0 GPIO.1 GPIO.2

    As opposed to:

    HIGH GPIO.0
    HIGH GPIO.1
    HIGH GPIO.2

    David

  13. #13
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Yes and no, you can use our old friend Skimask's favourite character - the colon - and do
    Code:
    High GPIO.0 : High GPIO.1 : High GPIO.2
    But it doesn't make any difference as to how it actually works, it will generate exactly the same code when compiled as having each command on a separate line.

    What you usually do is write directly to the register, or port in this case, like this:
    Code:
    TRISIO = %11100000 'Set lower five bits to outputs
    GPIO = %00000111   'Set the lower three bits.
    PAUSE 1000
    GPIO = %00010101   'Set some other bits.
    The HIGH and LOW commands automatically sets the pin to an output (by also writing to the TRIS register "behind the scenes" (basically what the OUTPUT command does)) which is handy sometimes but completely unneccessary to do EVERY time you change the state of the pin. By using the more "direct" aproach you'll save code space and execution time.

  14. #14
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by LEDave View Post
    Hi Joe

    Very impressed with the two programs you posted, thanks for those and very clever. The coding in parts is way beyond me at present but the effect on my PIC1 board are great and shows what can be done.

    I'll try and do the sequence mackrackit suggested today (time permitting).

    "So now try to do the sequence LEDs 1-3 using HIGH/LOW."

    It sounds straight forward enough (ish) but I've just got a feeling.......!

    Dave
    Hi Dave,
    Really simple and not beyond where you are right now.
    Tris is short for TriState. 3 states: in / output H / output L
    Port determines if the tristate is high or low.
    "Most" of the 12F , 8 pin devices use GPIO as Port name, it stands for General Purpose Input output. the TRIS is TRISIO. Here is the really simple part the letter" I " (for input) looks like a number 1 and the letter" O" (for Output) looks like a 0. so you see GPIO%00000011 means the 2 lowest bits are "set" as inputs. All the other bits are " cleared ". and are Outputs.
    The Port register is done in a similar way. 1 is logic HIGH and 0 is logic LOW. Logic high is +5v and Logic Low is 0 volts.
    I get that you might know this, but the next newbie may not. No offense intended.
    Consider this statement:
    TRISIO = %11111001
    GPIO = %00000010 'LED 7 ON

    TRISIO = %11111001 makes ports 1:2 into outputs
    GPIO = %00000010 makes Port 1 Logic high and port 2 logic low.
    Pay attention to the terminology "set" & "cleared" as you will see them in the data sheets.
    Generally speaking you will set the Port first then the tris, if you have a circuit like this where you have a bidirectional load, you might consider making all tris as inputs, set your port and then set the tris to enable the outputs. Your loads might be something very different than LEDs.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  15. #15
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Dave,
    Sure, that should work. You can also use the value stored in a variable when writing to the register, like this:
    Code:
    i VAR BYTE     'Declare a variable named 'i' as a BYTE
    i = 8
    GPIO = i   'Will set GPIO to %00001000
    This in turn means that to make the display count you can do this:
    Code:
    i VAR BYTE     'Declare a variable named 'i' as a BYTE
    MAIN:
    FOR i = 0 to 9 'Count up, from 0 to 9
      GPIO = i
      Pause 500
    Next
    
    FOR i = 9 to 0 STEP -1  'Count Down, from 9 to 0
      GPIO = 0
      Pause 500
    Next
    
    Goto Main             'Do it again
    May I kindly suggest that you also read thru the PBP manual a lot of what we've gone thru here is available in it, sometimes in a bit more condensed form but if you read thru it you'll get a better picture of "what's available", then we can work on the details and specifics together.

  16. #16
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Once again many thanks for all the INPUT.As always very much appreciated.

    mackrackit, I've book marked that link, very useful.

    Joe, if I could get my PIC's to dance like that I'll know I've arrived. I'm still adding the building blocks at present, that said there's been a big improvement in what I know and can do in just a week, great stuff.

    Henrik, so are we're saying that the program is counting up from 0-9 in bytes? Does it load and output the values $00000000 (LOOP1) $00000001 (LOOP2) ...etc. If that's the case I could directly output to a seven segment display!

    So the question is: Is there a PIC for my PICkit1 that has an eight bit wide output GPIO?

    Dave

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