Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC12F683 TRISIO issues...help needed.

Status
Not open for further replies.
Using PICBASIC PRO,
I previously built a device to monitor a single input, status being a contact open or closed. Each status change would blink an led, only once. EX: contact closed, LED A blinks once...contact open, LED B blinks once. This loop continued forever. But now insted of a 12vdc hardwired system, I am going to a coin battery 3v system. I also went to the 12F683 instead of the 16F84A. Here is the issue: I cannot get the inputs GPIO.0, 1, 4, 5 to stay outputs,,,,,and the GPIO.2 & 3 to stay inputs. I would like to have 2 inputs and 4 outputs. This way I can monitor 2 separate contact status positions, using a total of 4 LED indicators. They need to operate independently from one another.

TRISIO %00001100 'seems to put I/O in properly.

Why do some of the outputs move from hi to low when another output is told to go high and then back to low? It is almost like they are being re-written to go low...and there is no programming for this to be happening...can someone please make a recommendaion to how they feel this should be initialized? I have been chasing this for 4 days now, and I am missing something.
 
Last edited:

bananasiong

New Member
Hi,

Please post your code, and the schematic if possible so that we can have the clear picture of what's going on.
 

Pommie

Well-Known Member
Most Helpful Member
The problems you are having are because the 683 has analogue pins. To turn off the analogue function write 7 to CMCON0 and zero to ANSEL.

Mike.
 
Last edited:
I will be able to post in the morning. Thanks for the help. Please check back again then, I am somewhat new and this 683 is not making things any easier. I must use the nano to keep power use very low. 32kHz as well.
 
Here is the part of the code that I am using to trigger programming events.

"POMMIE said...The problems you are having are because the 683 has analogue pins. To turn off the analogue function write 7 to CMCON0 and zero to ANSEL."

This is the part I need help in getting right. Not familiar with this/these functions. Remember I am using PBP.

HERE IS MY CODE FOR THE PROGRAM:
''''''''''''''''''''''''''''''''''''''''''''''''''''
' variables
B0 VAR BYTE
B1 VAR BYTE
B2 VAR BYTE
B3 VAR BYTE
B4 VAR BYTE
B5 VAR BYTE
'***********************************************
'The 12F683 has only 6 IO pins.
'GPIO.0 is an output pin7
'GPIO.1 is an output pin6
'GPIO.2 is an input pin5
'GPIO.3 is an input pin4 (configured as an input)
'GPIO.4 is an output pin3
'GPIO.5 is an output pin2
'***********************************************
DEFINE OSC 3 ' Frequency in Mhz (TBD).
'***********************************************
'this is one way to set the clock speed see data sheet 3.0
' bit 6,5,4=000=32khz, bit 0=1
osccon=%00000001 ' Int Osc 32khz
'***********************************************
GPIO = $FF ' Set outputs HIGH ($ = Hex).
TrisIO = %00001100 'pins 7,6,3,2 output...pins 5,4 input
'pins xx765432

PAUSE 'Delay for MC initialization 500mS.
B0 = 0
B1 = 1
B2 = 0

B3 = 0
B4 = 1
B5 = 0

LOOP:

IF(GPIO.2 = 1)and(B0 = B2)then
B0 = B1
Pause 10 '1 second
GPIO.0 = 0 'pull down pin 7
Pause 20 '2 seconds on LED A
GPIO.0 = 1 'pin 7 back to 3v
ENDIF

IF(GPIO.2 = 0)and(B0 = B1)then
B0 = B2
Pause 10 '1 second
GPIO.1 = 0 'pull down pin
Pause 20 '2 seconds on LED B
GPIO.1 = 1 'pin 6 back to 3v
ENDIF

IF(GPIO.3 = 1)and(B3 = B5)then
B3 = B4
Pause 10 '1 second
GPIO.5 = 0 'pull down pin 7
Pause 20 '2 seconds on LED A
GPIO.5 = 1 'pin 2 back to 3v
ENDIF

IF(GPIO.3 = 0)and(B3 = B4)then
B3 = B5
Pause 10 '1 second
GPIO.4 = 0 'pull down pin
Pause 20 '2 seconds on LED B
GPIO.4 = 1 'pin 3 back to 3v
ENDIF

nap 7 '~2.304 second nap

Goto LOOP
 

Pommie

Well-Known Member
Most Helpful Member
You don't appear to understand the code at all and so I guess you just copied it of the internet somewhere. However, I'm feeling good and so you should add,
Code:
osccon=%00000001 ' Int Osc 32khz
'***********************************************
[COLOR="Red"]CMCON0=7
ANSEL=0[/COLOR]
GPIO = $FF ' Set outputs HIGH ($ = Hex).
TrisIO = %00001100 'pins 7,6,3,2 output...pins 5,4 input

Mike.
 
I have this same code running on a 16F84A....so the conversion to this 12F683 has made some changes. 16F84A did not require the settings you just posted. And as for not understanding the code..you are correct, but for copying off the internet, you are wrong. This is a hacked up mod of my original 12vdc prototype, trying to go portable and on a coin battery. Thanks for the post....I will compile and test the pins for proper response and get back to you if need be.
 
I am new to the world of micro controllers in general, so there is a lot that I don't know. So if this is what you mean...then yes I wrote the code and don't understand it. "It" being the part I have not yet learned. I have been trying to learn as I go in these projects, using the data sheets as best I can. But this chip has moved me into an area that I am not familiar with and/or don't yet understand. Your post has helped me to understand this better. I am always interested in learning better ways of writing code, that's what its all about, right?

Thanks again for the help, your assistance appears to be moving me in the right direction on this project. Sorry if my lack of understanding has offended you in any way.

Ron
 

ronsimpson

Well-Known Member
Most Helpful Member
Hi Ron
I think Ponie is right.
CMCON0=7
ANSEL=0
Just to test your programmer and process try setting outputs hi then low. Some thing very simple. Then add more code slowely.
TrisIO = %00001100
:loop
GPIO = 0
paues 10
GPIO = %11111111
pause 10
goto loop
 
You are pulling my leg , right? I have multiple associates in my office that assisted in this project as well....and so how could I/We have found the exact code required to run a prototype that we have never seen or used before? That would be way to coincidental even for myself to comprehend! My associates are also interested in the likelyhood as well at this point. Can you direct me to evidence of the same code on the internet? You have our curiosities up now.
 

Pommie

Well-Known Member
Most Helpful Member
You didn't understand my post and so you could not have written the code.

Mike.
 
I was not going to disclose your true identity RON! I should have known you were on the other end of this somewhere!!!!! But it still does not disprove the fact that I wrote this code.....and it was not copied off the internet.
 

Pommie

Well-Known Member
Most Helpful Member
You did not write this code. You do not understand basic. If you understood basic and did write this code you would have understood my first post and not asked for clarification.

I hate people that are untruthful.

Mike.
 

birdman0_o

Active Member
There is no shame in saying code is not yours, unless it is for money. Pommie CLEARLY stated what steps you would need to follow, try them out and let us know the results instead of arguing, we are here to help.
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top