PDA

View Full Version : How do I configure the PIC16F737?



LinkMTech
- 18th November 2007, 21:55
Hello folks with the most,
Being a total newbie at this, please excuse my almost total ignorance with this question.
I've been trying to configure the 16F737 for all the I/O's needed on my project that will use

1. RB0-RB5, RA6-RA7 as digital inputs and AN0-AN1 as analog inputs for pots.
2. RC0-RC7 as digital outputs. Seems to be working okay.
3. INT OSC at 4MHz with no outputs. Seems to working okay.

Get ready to laugh...
As you can see by my "test" program (copied and pasted). The configuration is doing something funny because the TRISB has to be changed occasionally to =11 just so RB1 is recognized or it measures about 75 ohms to GND!
The program was written the best way I know how (for the moment) to test various outputs, connected to LED's for visual confirmation, vs. inputs using binary or HEX.

I'm not asking that my work be done for me but just been looking for an outline on configuring these fantastic components so that I can use them properly. I've already been told "somewhere else" to "read the data sheet because it's all in there and it's very simple". I read and read to no avail, I think he was having a bad day...

Thanks for the help,

'************************************************* **************
'* Notes : Using the PIC16F737, this program will provide 8 pulsed outputs
'* : from decoding 8 digital inputs and 2 variable analog
'* : inputs. The output pulse time will be adjustable from 20ms to 120ms with the
'* : two pots.
'* :
'* :
'************************************************* ***************
@ DEVICE PIC16F737, INTRC_OSC_NOCLKOUT, WDT_ON, PROTECT_OFF, MCLR_ON

CLRW ' I think it clears it's throat
OSCCON = %01101000 ' Oscillator set to 4MHz, RA6 & RA7 as I/O
ADCON1 = %00001101 ' Disable all but AN0 & AN1 analog inputs

TRISA = 1 ' Sets PORTA pins as inputs
TRISB = 11 ' Sets PORTB pins as inputs
TRISC = 0 ' Sets PORTC pins as outputs

Pause 200 ' Keep outputs from pulsing at startup

loop:

' Pin 21 goes HI then pins 11 & 13 go HI
if PORTB.0 = 1 THEN
'PORTC = %00000101 ' works!
PORTC = $5 ' works!
else
PORTC = $00
ENDIF

' Pin 22 goes HI then pins 12 & 14 go HI
if PORTB.1 = 1 Then
'PORTC = %00001010 ' works!
PORTC = $A ' works!
ELSE
PORTC = $00
ENDIF

' Pin 23 goes Hi then pins 16 & 18 go HI
if PORTB.2 = 1 Then
'PORTC = %10100000 ' works!
PORTC = $A0 ' works!
ELSE
PORTC = $00
ENDIF

goto loop

' Pin 24 goes HI then pins 15 & 17 go HI
if PORTB.3 = 1 Then
'PORTC = %01010000 ' no response
PORTC = $50 ' no response
ELSE
PORTC = $00
ENDIF

' Pin 25 goes HI then pins 13 & 18 go HI
if PORTB.4 = 1 Then
'PORTC = %10000100 ' no response
PORTC = $84 ' no response
ELSE
PORTC = $00
ENDIF

' Pin 26 goes HI then pins 11 & 16 go HI
if PORTB.5 = 1 Then
'PORTC = %00100001 ' no response
PORTC = $21 ' no response
ELSE
PORTC = $00
ENDIF

' Pin 10 goes HI then pins 11, 13, 16, 18 go HI
if PORTA.6 = 1 Then
'PORTC = %10100101 ' no response
PORTC = $A5 ' no response
ELSE
PORTC = $00
ENDIF

' Pin 9 goes HI then pins 12, 14, 15, 17 go HI
if PORTA.7 = 1 Then
'PORTC = %01011010 ' no response
PORTC = $5A ' no response
ELSE
PORTC = $00
ENDIF

End

ronjodu
- 18th November 2007, 22:08
Welcome.
I lean on this forum myself quite often. I've found if you're willing to do your own legwork that the people here are more than willing to point you in the right direction.
As far as your program goes the one thing that jumped out at me was the way you are setting up the TRIS registers. Here is how I set them up for a program I'm working on now.


PORTA = %00000000 'Set all outputs to 0 (off)
TRISA = %00000000 'Set PORTA RA0-RA5 to outputs
PORTB = %00000000 'Set all outputs to 0 (off)
TRISB = %01000011 'Set PORTB to all output except RB0/INT , RB1/data in, RB6 on/off switch
PORTC = %00000000 'Set all outputs to 0 (off)
TRISC = %00000000 'Set PORTC to all output



Hope this helps some...

LinkMTech
- 18th November 2007, 22:25
Thanks for the input ronjodu,
I made the changes as recommended but still got the same "no response" from RB3-RB5, RA6-RA7. I'm thinking I hurt my only device when I first wired it up with 5V to pin 28 (but no GND) instead of pin 20, was to excited and in a hurry. Gonna order some more in the mean time.

ronjodu
- 18th November 2007, 22:44
I didn't mean for you to cut and paste what I posted. Did you change the ports to accomodate your aplication? In other words did you set the bits in each port for the inputs you are using and clear the bits for the outputs you are using?

The other thing jumping out at me is between your code for pin 23 and 24 you have the "goto loop" statement sending the pprogram back to the beginning.

That statement should be at the end of the program I believe.

As far as killing the pic, they are fairly resilient. If all you did is put 5 volts on an I/O pin you probably didn't damage it.

LinkMTech
- 18th November 2007, 23:01
I didn't mean for you to cut and paste what I posted. Did you change the ports to accomodate your aplication? In other words did you set the bits in each port for the inputs you are using and clear the bits for the outputs you are using?

The other thing jumping out at me is between your code for pin 23 and 24 you have the "goto loop" statement sending the pprogram back to the beginning.

That statement should be at the end of the program I believe.

As far as killing the pic, they are fairly resilient. If all you did is put 5 volts on an I/O pin you probably didn't damage it.

I understood what you are doing by making sure the ports are first turned OFF then setting them as needed. Thanks
"goto loop" statement , THAT WAS IT!! Thanks alot. Now all the ports are responding to my configuration so now I can move on to the next part of the learning curve.

ronjodu
- 18th November 2007, 23:05
With all the help I've gotten in this forum It's really exciting to give back a little help and have it mean something. Good Luck..