View Full Version : pin 12f683
jcleaver
- 13th March 2007, 12:53
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
HenrikOlsson
- 13th March 2007, 13:45
Hi,
Try this:
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.
Bruce
- 13th March 2007, 13:54
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..
@ 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
jcleaver
- 13th March 2007, 19:21
this looks great
only my program will require mostly inputs and at least 1 output
can you tell what changes i need
Bruce
- 13th March 2007, 19:44
TRISIO = %11111110 would setup GPIO.0 as an output leaving the rest setup as inputs.
What is it you're doing?
jcleaver
- 14th March 2007, 00:13
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
Pic_User
- 14th March 2007, 00:40
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-
Bruce
- 14th March 2007, 00:59
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.
'************************************************* ***************
'* 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;
http://www.rentron.com/ABC/Sapien.gif
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}
jcleaver
- 14th March 2007, 13:42
great info bruce
i think i want internal pull ups
is this wpu=1
thanks for your help
Bruce
- 14th March 2007, 14:06
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.
jcleaver
- 14th March 2007, 15:49
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
Bruce
- 14th March 2007, 15:52
Post the code you're having problems with. Hard to say without seeing that.
jcleaver
- 15th March 2007, 01:12
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
jcleaver
- 15th March 2007, 01:50
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
Bruce
- 15th March 2007, 14:36
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.
jcleaver
- 15th March 2007, 14:55
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
Bruce
- 15th March 2007, 15:02
How does it work with this?
@ 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
jcleaver
- 15th March 2007, 15:55
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
jcleaver
- 15th March 2007, 20:11
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
Bruce
- 16th March 2007, 16:15
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.
jcleaver
- 17th March 2007, 01:44
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?
dharwood
- 22nd March 2007, 20:39
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
mister_e
- 22nd March 2007, 22:29
http://www.mister-e.org/Pics/CrystalBall_Informations.gif
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.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.