pin 12f683


Closed Thread
Results 1 to 23 of 23

Thread: pin 12f683

  1. #1

    Cool pin 12f683

    trying to program this 8 pin pic
    trouble defining pins in pbp
    microchip manual listpins as gp0 to gp4 this does not work
    tried just pin 1 ect this compiles but does not function on pic

    whats the correct syntax for the baby chips

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Comparators...

    Hi,
    Try this:
    Code:
    ANSEL = %00000000	'Make sure Analog functions are turned OFF (should not be needed)
    CMCON = 7		'Turn OFF comparators, datasheet section 8.3
    TRISIO = 0		'All pins except GPIO3(MCLR) as output.
    
    Start:
      GPIO.0 = 1
      Pause 100
      GPIO.1 = 0
      Pause 100
    Goto Start
    /Henrik Olsson.

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


    Did you find this post helpful? Yes | No

    Default

    GPIO.0, GPIO.1, etc, for I/O-pins, and TRISIO for TRIS regs. Here's a sample
    I/O-pin setup header from an old 683 test program..

    Code:
    @ DEVICE PIC12F683,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_ON, PWRT_ON
    
    OSCCON  = %01100000     ' Internal 4MHz osc
    ADCON0 = 0              ' A/D off
    CMCON0 = 7              ' Comparators off
    ANSEL = 0	        ' Set all digital
    WPU = 0                 ' Internal pull-ups = off
    OPTION_REG = %10000000  ' Pull-ups = off, GPIO.2 = I/O, prescaler to Timer1
    GPIO = %00000000        ' All outputs = 0 on boot
    TRISIO = %00111101      ' GPIO,0=data in, GPIO,1=IRLED out, GPIO,2,3,4,5 unused
    Regards,

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

  4. #4


    Did you find this post helpful? Yes | No

    Smile update

    this looks great
    only my program will require mostly inputs and at least 1 output
    can you tell what changes i need

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


    Did you find this post helpful? Yes | No

    Default

    TRISIO = %11111110 would setup GPIO.0 as an output leaving the rest setup as inputs.

    What is it you're doing?
    Regards,

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

  6. #6


    Did you find this post helpful? Yes | No

    Default responce

    setting up a alarm for my motorhome to sound if ignition is off and trans is not in park older coach does not have this feature also will sound alarm if turn signals are on too long

  7. #7
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile How many pins?

    How about (slow repetition) beep if head-lights are on and ignition off?
    We should be able to get this up to a 40 pin PIC
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

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


    Did you find this post helpful? Yes | No

    Default

    Sounds like a cool project. The 12F683 is a really nifty part.

    My wife thinks I'm a complete nerd, so she buys me all this odd stuff like RoboSapien robots and such. I got kind of bored with it after the first few minutes, and decided to have a go at controlling the thing from my PC with an 8-pin PIC.

    I used the 12F683 since I hadn't played with this one yet 'note the date of the code'. Here's what I came up with. It's pretty simple stuff, but still fun. I have a VB interface if anyone's interested. You can connect the PIC to your PC serial port, and control your RoboSapien robot with it by clicking buttons on-screen.
    Code:
    '****************************************************************
    '*  Name    : RoboSapien_IR.bas                                 *
    '*  Author  : Bruce Reynolds  11/11/2005                        *
    '*  Notes   : Serial IR controller for RoboSapien robot         *
    '*          : Replace RoboSapien hand-held IR transmitter with  *
    '*          : an 8-pin PIC & IR LED. Just goofin off one day.   *
    '****************************************************************
    ' Connections for a 12F683
    ' Pin #8 = gnd
    ' Pin #1 = Vcc
    ' GPIO.0 serial input from other controller or PC
    ' GPIO.1 IR LED drive ----/\/\/\---|>|----gnd  (note: use a 940nm IRLED)
    '                          330    IR LED
    ' Need more range use a simple NPN or mosfet driver.
    ' Rest of I/O-pins available for whatever.
    
    @ DEVICE PIC12F683, MCLR_OFF, INTRC_OSC_NOCLKOUT, WDT_OFF, BOD_ON, PWRT_ON
    DEFINE OSC 4
    DEFINE DEBUG_BAUD 2400 
    DEFINE DEBUGIN_REG GPIO 
    DEFINE DEBUGIN_BIT 0  
    DEFINE DEBUGIN_MODE 0   ' 0 = true mode (with a PC use a MAX232)
    
    @ #DEFINE IRTX GPIO  ; Define port to use for IR LED drive
    @ #DEFINE PIN 1      ; Define port pin to use for IR LED    
    
    BotHdr   CON 255     ' Pulse timing stuff
    BotHdr2  CON 25     
    Bot1     CON 3400   
    Bot0     CON 800     
    BotInter CON 38     
    Bot      CON "B"     ' Used for synch byte
    X        VAR BYTE    ' Bit index pointer
    Cycles   var BYTE    ' Holds number of 40KHz carrier cycles
    Device   VAR BYTE    ' Holds device select byte
    KeyNum   VAR BYTE    ' Key pressed
    
    OSCCON  = %01100000     ' Internal 4MHz osc
    ADCON0 = 0              ' A/D off
    CMCON0 = 7              ' Comparators off
    ANSEL = 0	            ' Set all digital
    WPU = 0                 ' Internal pull-ups = off
    OPTION_REG = %10000000  ' Pull-ups = off, GPIO.2 = I/O, prescaler to Timer1
    GPIO = %00000000        ' All outputs = 0 on boot
    TRISIO = %00111101      ' GPIO,0=data in, GPIO,1=IRLED out, GPIO,2,3,4,5 unused
    
    Main:
        DEBUGIN [Device,KeyNum] ' With MCS+ serial terminal program, sending B#135
        IF Device = Bot THEN    ' will move bot backwards. Full list of commands
           GOTO SendCmd         ' can be found in lower section.
        ENDIF
        GOTO Main
        
    SendCmd:
        Cycles = BotHdr  ' 1st part of synch pulse
        CALL Pulse
        Cycles = BotHdr2 ' 2nd part of synch pulse
        CALL Pulse
        
        FOR X = 7 to 0 STEP - 1 ' 8-bits per button command
            IF KeyNum.0[X] = 1 THEN
               PAUSEUS Bot1     ' high for logic 1 bit period
            ELSE
               PAUSEUS Bot0     ' or low for logic 0 bit period
            ENDIF
            Cycles = BotInter   ' Inter-bit period between data bits
            Call Pulse          ' During these periods the carier is on
        NEXT X
        GOTO Main
        
    Pulse:              ' Generate "Cycles" number of 40kHz pulses
    ASM
       bsf IRTX,PIN     ; 1uS, LED=on
       goto $+1         ; + 2uS = 3uS
       goto $+1         ; + 2uS = 5uS
       goto $+1         ; + 2uS = 7uS
       goto $+1         ; + 2uS = 9uS
       goto $+1         ; + 2uS = 11uS
       goto $+1         ; + 2uS = 13uS   
       bcf IRTX,PIN     ; 1uS, LED=off
       goto $+1         ; + 2uS = 3uS
       goto $+1         ; + 2uS = 5uS
       goto $+1         ; + 2uS = 7uS
       goto $+1         ; + 2uS = 9uS
       decfsz _Cycles,f ; + 1uS = 10S    
       goto _Pulse      ; + 2uS = 12uS
       return           ; Add 2uS for return to caller    
    ENDASM
     
        END
    
    ' Send ASCII character B followed by key commands below to
    ' control your RoboSapien from a PC or another PIC.
    
    ' A simple VB example to move RoboSapien forward would be;
    ' Private Sub Cmd_Forward_Click()
    ' MSComm1.Output = "B" & Chr$(134)
    ' End Sub
    
    ' Upper red commands
    ' Right arm up      = 129
    ' Right arm down    = 132
    ' Right arm in      = 133
    ' Right arm out     = 130
    ' Left arm up       = 137
    ' Left arm down     = 140
    ' Left arm in       = 141
    ' Left arm out      = 138
    ' Tilt body right   = 131
    ' Tilt body left    = 139
    
    ' Red commands - middle & lower controller
    ' Walk forward      = 134 
    ' Walk backward     = 135
    ' Turn left         = 136
    ' Turn right        = 128
    ' Stop              = 142
    ' Rht sensor pgm    = 146
    ' Master command program = 144
    ' Program / play    = 145
    ' Left sensor program = 147
    ' Sonic sens pgm    = 148
    
    ' Green commands - upper controller
    ' Right hand thump  = 161
    ' Right hand pickup = 164
    ' Lean backward     = 165
    ' Rht hand throw    = 162
    ' Sleep             = 163
    ' Listen            = 171
    ' Left hand throw   = 170
    ' Lean forward      = 173
    ' Left hand pickup  = 172
    
    ' Green commands - middle & lower controller
    ' Right turn step   = 160
    ' Backward step     = 167
    ' Forward step      = 166
    ' Reset             = 174
    ' Left turn step    = 178
    ' Right sensor program execute = 178
    ' Master command program execute = 176
    ' Wake up           = 177
    ' Sonic sensor program execute = 180
    ' Left sensor program execute  = 179
    
    ' Orange commands - upper controller
    ' Right hand sweep  = 193
    ' High 5            = 196
    ' Right hand strike = 197
    ' Burp              = 194
    ' Right hand strike 2 = 195
    ' Left hand strike 2  = 203
    ' Whistle           = 202
    ' Left hand strike  = 205
    ' Talk back         = 204
    ' Left hand sweep   = 201
    
    ' Orange commands - middle & lower controller
    ' Right hand strike 3 = 192
    ' Oops              = 199
    ' Left hand strike 3 = 200
    ' Roar              = 206
    ' Demo 1            = 210
    ' All demo          = 208
    ' Power off         = 209
    ' Dance demo        = 212
    ' Demo 2            = 211
    Here's a pic of the VB app;


    I ended up with an 8-pin PIC controlling my RCA TV, Motorolla cable box, DVD, stereo, RoboSapien 'when I could afford batteries every few minutes', etc. from my PC. Maybe my wife was right...;o}
    Regards,

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

  9. #9


    Did you find this post helpful? Yes | No

    Default wow

    great info bruce
    i think i want internal pull ups
    is this wpu=1
    thanks for your help

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


    Did you find this post helpful? Yes | No

    Default

    GPIO.0, 1, 2, 4 and 5 have pull-up enable/disable bits in WPU, but
    OPTION_REG.7 needs to be clear also.

    OPTION_REG.7 (GPPU) is the global pull-up enable/disable bit.

    OPTION_REG.7 = 0 ' GPIO pull-ups enabled by individual WPU bits
    TRISIO = %00000001 ' GPIO.0 = input, rest outputs (except for GPIO.3)
    WPU = %00000001 ' enable pull-up on GPIO.0, disable the rest.

    It's pretty straight forward. Look in your data sheet under OPTION_REG &
    WPU sections for details.
    Regards,

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

  11. #11


    Did you find this post helpful? Yes | No

    Default pull ups

    have set this up on a board which has a resistor 10 k to ground and a pb to vdd on gpi0.5. this is the way the board is set trying some programs but
    gpi0.5 stays high whenever pic is in socket i guess somehow i am not shutting off the pullups on this port have tried many many lines no changes to this
    any ideas whats up doc

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


    Did you find this post helpful? Yes | No

    Default

    Post the code you're having problems with. Hard to say without seeing that.
    Regards,

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

  13. #13


    Did you find this post helpful? Yes | No

    Cool highs and low

    got most things working now except
    cannot get changover from 1 to 0 on gpio.0
    its going high due to the pullup but when i ground does not respond

    might not be explaining this properly but can work on gpio.5

    where i have a resistor to gnd and a pb to 5 volts
    Attached Files Attached Files

  14. #14


    Did you find this post helpful? Yes | No

    Angry got to be crazy

    What Seems To Be Happening Is I Cannot Get Gpi0.0 To Change State Using The Pullup
    Dont Know If Its A Electrical Issue Or Not See Sample Program Above Just Grounding Pin 7 Momentarily
    But Prgram Does Not Respond Works On Gpi0.5 With A Res Pulled Low And A Pb To High
    Last edited by jcleaver; - 15th March 2007 at 13:36.

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


    Did you find this post helpful? Yes | No

    Default

    Which PIC are you actually using? Your code example above indicates a 12F675, but you asked about the 12F683?

    For the 12F675 you need CMCON = 7 to disable comparators.
    For the 12F683 you need CMCON0 = 7 to disable comparators.
    Last edited by Bruce; - 15th March 2007 at 14:56.
    Regards,

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

  16. #16


    Did you find this post helpful? Yes | No

    Wink pic

    bruce i tried both but the pic12f675 works with one of my programmers beter dont have to keep swaping out the pic so thats what i am trying now
    really does not mater after i get it working

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


    Did you find this post helpful? Yes | No

    Default

    How does it work with this?

    Code:
    @ DEVICE PIC12F675,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_ON,PWRT_ON
    ANSEL = 0         
    CMCON = 7  
    OPTION_REG = 0    
    TRISIO = %00100011
    WPU = %00000011
    
    ' Example program from manual to blink an LED connected to gpio.4 about once
    ' a sec
    led var gpio.0
    
    loop:
       if  led = 1 then
           low 2
       else
           high 2
       endif
    
       HIGH gpio.4
       ' Turn on LED connected to gpio.4
       Pause 1000    ' Delay for .5 seconds
       LOW gpio.4
       ' Turn off LED connected to gpio.4
       Pause 500       ' Delay for .5 seconds 
       Goto loop       ' Go back to loop and blink LED forever
       End
    Last edited by Bruce; - 15th March 2007 at 15:06.
    Regards,

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

  18. #18


    Did you find this post helpful? Yes | No

    Question onward

    this functions but not as expected at first pin to v+ caused change
    than after short time v- caused change which is what i would expect
    dont quiet understand inital operation but this is doing what i want
    thanks

  19. #19


    Did you find this post helpful? Yes | No

    Thumbs down backwards?

    this program works but still get times when it functions backwards
    should be gnd to pin to work but sometimes after downloading program
    it will be just the oppisite + volts to pin

    any changes that will stop this from accuring

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


    Did you find this post helpful? Yes | No

    Default

    Are you sure it's not a hardware problem? I ran this on a 12F675, and it works
    exactly as expected. No matter how many times I re-program it.
    Regards,

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

  21. #21


    Did you find this post helpful? Yes | No

    Cool hardware

    bruce:
    not 100 % sure but seems strange that sometimes + volts cause the pic the way - volts should than sometimes it works just the right way - volts causes the pic to respond properly is there some sort of start up or setting that could cause this maybe pullup not coming on?

  22. #22
    dharwood's Avatar
    dharwood Guest


    Did you find this post helpful? Yes | No

    Default

    Quick question:
    What are you using as V+ for your input signal ? +5v +12v etc.....?

    I had a project where I was trying to read a ~12v input (DCD on a rf modem) and it would sometimes work, other times not. Set up a voltage divider so that my input voltage would not exceed 5v and from that point on, it has worked as planned.

    HTH,

    Dale

  23. #23
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default an obvious hardware problem

    You have to give us your WHOLE schematic, there's no obvious reason why it shouldn't work.

    If you supply line is pure crap, it will give you crap. In car it's usual. Tie ALL unused pin to somewhere first. ALL floating i/o in car apps (and everywhere anyways, trust me or not i don't care)... is often a killer situation.

    Now if one of your input is MCLR and you didn't use the right voltage divider, your PIC will fall into programming mode... too bad.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. What's the best way to output 30 to 40 kHz from a 12F683 pin?
    By fizyxman in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st June 2009, 00:08
  3. DS1820 with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd May 2009, 05:07
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07

Members who have read this thread : 1

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