PDA

View Full Version : Port Values



Pesticida
- 2nd January 2007, 19:39
Hi,

I have a simple Question,but I can not find a Answer.
I have a Pic 16F870 And I want to use My PortC as High/Low,I now how to do this but can I do this like here:

Data @1,3,6,12,9

For Counter = 1 to 4
Read Counter,State

PortC = State
Gosub DelayCheck

Next Counter


3 is PortC = %00000011 and 6 is PortC = %00000110 and so on.

Can I do this.

Thanks.

mister_e
- 2nd January 2007, 19:51
Sure you can do this, but don't forget to set the TRISC register at the top of your code to configure your i/o as output.



TRISC=0 ' configure all PORTC I/Os to output
'
'
'
'
PORTC=%00001010 ' Write to PORTC

Pesticida
- 2nd January 2007, 20:04
Hi,
Thanks Mister,
I can use decimal numbers like here PortC=3 and this don't disturbe my Hserin Communication on PortC.?!

Thanks.

mister_e
- 2nd January 2007, 20:33
Mmm, interesting point, i've never think about it.

A simple experimentation here reveal that it doesn't cause ANY problem as long as you did a HSEROUT before writing to PORTC. Once you did it, those RX and TX I/Os are dedicated to HSERIN/HSEROUT only.

i tried...


'
' Pic Configuration
' =================
@ __CONFIG _XT_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF
' XT (4Mhz) oscillator
' Enable watch dog timer
' Enable power up timer
' Enable brown out detect
' Disable low voltage programming

'
' Hardware configuration
' ======================
TRISC=%10000000 ' PORTC.7 as input => USART RX,
' Others as output

'
' Serial Communication definition
' ===============================
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25 ' 9600 Baud @4MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

'
' Variables definition
' ===================
CounterA var byte

'
' Main program
' ============
HSEROUT [0]
Start:
PORTC=%11111111
PAUSE 500
PORTC=0
PAUSE 500
GOTO START

If you use it, you'll discover that nothing happen to PORTC.6 and PORTC.7... well they stay at their usual levels... High.

Now a slight better test...


Start:
HSEROUT ["Send me data...",13,10]
hserin [DEC Countera]
PORTC=countera
GOTO START
Use MicroCode Serial Communicator to do you Tests... it still work

Pesticida
- 2nd January 2007, 20:44
Yes its Working!

I forgot this TRISC=0 :-)

Thanks Mister