PDA

View Full Version : Please explain me WHY!



financecatalyst
- 27th September 2009, 21:16
I am using PIC16F690.
I am wondering why when I use the following program:
"
intcon=0
cm1con0=0
cm2con0=0
ansel=0
anselh=0
trisc=0
portc=0
define OSC 4
option_reg = %00001000

main:
high portC.0
high portC.1
high portC.2
high portC.3
pause 1000
low portc.0
low portc.1
low portc.2
low portc.3
pause 1000
goto main
"
All leds connected to PORTC work as expected.
AND why they don't work when I use the following code:
"
intcon=0
cm1con0=0
cm2con0=0
ansel=0
anselh=0
trisc=0
portc=0
define OSC 4
option_reg = %00001000

main:
high portC
pause 1000
low portC
pause 1000
goto main
"

MarcBergeron
- 27th September 2009, 21:27
Try adding this to your loading values:

trisC = %00000000


This will set your portC as outputs.
The zeros fromleft to right are portC.7, portC.6, portC.5, portC.4, portC.3, portC.2, portC.1, portC.0.
You can changed the 1's or 0's depending on what you want them to be. In your case, all zeros for outputs.

or
'add your stuff here'
trisC = %00000000

Main:
PORTC = %00001111
pause 1000
PORTC = %11110000
pause 1000
Goto Main

comwarrior
- 27th September 2009, 22:16
for tris, 0 is output and 1 is input

Archangel
- 28th September 2009, 02:20
I am using PIC16F690.
I am wondering why when I use the following program:
"
intcon=0
cm1con0=0
cm2con0=0
ansel=0
anselh=0
trisc=0
portc=0
define OSC 4
option_reg = %00001000

main:
high portC.0
high portC.1
high portC.2
high portC.3
pause 1000
low portc.0
low portc.1
low portc.2
low portc.3
pause 1000
goto main
"
All leds connected to PORTC work as expected.
AND why they don't work when I use the following code:
"
intcon=0
cm1con0=0
cm2con0=0
ansel=0
anselh=0
trisc=0
portc=0
define OSC 4
option_reg = %00001000

main:
high portC
pause 1000
low portC
pause 1000
goto main
"

Can't tell you why, except <b>maybe </b>it's not supposed too, You CAN do this:
PortC = 255
pause 1000
PortC = 0

Put ADCON0 = 0 in to disable the A/D converters too

vaporized
- 28th September 2009, 10:48
Hi.
Joe and Marc told you what to do to get desired result, I'll only add that the reason behind it is: high & low are commands that work with one pin you specify not the whole port...

MarcBergeron
- 29th September 2009, 00:45
CMCON = 7 will tuen off the comparator module, if your chip has this.

Can you post a picture of your project? It would be nice to see how you got everything setup.

Acetronics2
- 29th September 2009, 07:52
Hi,

Would be interesting to compare the produced asm code with " High PORTC " vs " High PORTC.1 " ...

Explanation is nowhere else ...

I Still haven't found a use for the first one ... Performs some kind of Read then Write Port sequence.

Alain