Author Topic: toggle a PIN between input and output  (Read 3095 times)

0 Members and 1 Guest are viewing this topic.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
toggle a PIN between input and output
« on: October 10, 2008, 09:50:23 PM »
Guys i read this tutorial ( http://www.societyofrobots.com/member_tutorials/node/161 ) about tri state switch.according to it in order to brake the motor i have to convert a output pin to a input pin.example i use A0 as an output and when i want to brake the motor i have to write a code to make A0, a input pin.I don't know how to this.Any help would be great.Hope you understand what I'm saying.(I use CCS C for programming and using PIC16F877A so please post relevant C code for this) ???
thanks :)
« Last Edit: October 10, 2008, 09:52:25 PM by aruna1 »
I'm Me

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: toggle a PIN between input and output
« Reply #1 on: October 10, 2008, 10:54:44 PM »
I don't know about CCS C, but if you look in the tutorial in my signature, you can see a macro called FLIP_PORT that does toggling, it can be used for either high/low or input/output

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: toggle a PIN between input and output
« Reply #2 on: October 10, 2008, 10:58:34 PM »
I don't know about CCS C, but if you look in the tutorial in my signature, you can see a macro called FLIP_PORT that does toggling, it can be used for either high/low or input/output
thanks i'll check
I'm Me

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: toggle a PIN between input and output
« Reply #3 on: October 13, 2008, 01:59:22 PM »
On an ATMEL/AVR chip you use the Data Direction Register to control whether a pin is an output pin or an input pin. Not sure what the equivalent is with a PIC but after a quick look at the datasheet then assuming you are using PORTA then the equivalent direction port is TRISA where a 0=output and 1=input. So if you are using PORT A pin 2 then:
TRISA |= (1<<2) ; will make PORTA pin2 an input
TRISA &= ~(1<<2); will make PORTA pin2 an output
This is only a guess - as I dont have any PIC experience.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: toggle a PIN between input and output
« Reply #4 on: October 13, 2008, 07:07:21 PM »
On an ATMEL/AVR chip you use the Data Direction Register to control whether a pin is an output pin or an input pin. Not sure what the equivalent is with a PIC but after a quick look at the datasheet then assuming you are using PORTA then the equivalent direction port is TRISA where a 0=output and 1=input. So if you are using PORT A pin 2 then:
TRISA |= (1<<2) ; will make PORTA pin2 an input
TRISA &= ~(1<<2); will make PORTA pin2 an output
This is only a guess - as I dont have any PIC experience.
i didn't get it it. if TRISA means port A how to define port a pin 1 and pin 2(or any other pin)?
I'm Me

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: toggle a PIN between input and output
« Reply #5 on: October 14, 2008, 10:21:15 AM »
Check the tutorial in my signature :P

 


Get Your Ad Here

data_list