PDA

View Full Version : PORTC bits not 'latching' on 16F610



comwarrior
- 22nd December 2010, 23:42
simple little xmas lights project which i posted several weeks ago... RGB LEDs ramping up and down with software PWM...

The same program compiled for the 18F4550 works correctly, however, when compiled for the 16F610 as soon as PORTC.1 goes high it makes PORTC.0 low even though i've set it high...

For the fun of it, i've included the source code below... Can anyone see any problems with it? Have i missed something?

Thanks


Define OSC 8 ' Set clock speed

TRISA = %00000000
PORTA = %00000000
TRISC = %00000000
PORTC = %00000000

RED VAR PORTC.0
GREEN VAR PORTC.1
BLUE VAR PORTC.2
REDSCALE VAR WORD
GREENSCALE VAR WORD
BLUESCALE VAR WORD
Aloop VAR byte
Bloop VAR BYTE
DUTY var BYTE
clear
REDSCALE = 1
BLUESCALE = 1
GREENSCALE = 1
DUTY = 100

gosub powerupred
MAIN:
gosub powerupgreen
gosub powerdownred
gosub powerupblue
gosub powerdowngreen
gosub powerupred
gosub powerdownblue
GOTO MAIN

POWERUPRED:
for Aloop = 1 to DUTY
FOR Bloop = 1 to REDSCALE
HIGH RED
pause Aloop
LOW RED
pause (duty-Aloop)
NEXT Bloop
NEXT Aloop
HIGH RED
return

POWERDOWNRED:
for Aloop = 1 to duty
FOR Bloop = 1 to REDSCALE
HIGH RED
pause (duty-Aloop)
LOW RED
pause Aloop
NEXT Bloop
NEXT Aloop
return

POWERUPGREEN:
for Aloop = 1 to duty
FOR Bloop = 1 to GREENSCALE
HIGH GREEN
pause Aloop
LOW GREEN
pause (duty-Aloop)
NEXT Bloop
NEXT Aloop
HIGH GREEN
return

POWERDOWNGREEN:
for Aloop = 1 to duty
FOR Bloop = 1 to GREENSCALE
HIGH GREEN
pause (duty-Aloop)
LOW GREEN
pause Aloop
NEXT Bloop
NEXT Aloop
return

POWERUPBLUE:
for Aloop = 1 to duty
FOR Bloop = 1 to BLUESCALE
HIGH BLUE
pause Aloop
LOW BLUE
pause (duty-Aloop)
NEXT Bloop
NEXT Aloop
HIGH BLUE
return

POWERDOWNBLUE:
for Aloop = 1 to duty
FOR Bloop = 1 to BLUESCALE
HIGH BLUE
pause (duty-Aloop)
LOW BLUE
pause Aloop
NEXT Bloop
NEXT Aloop
return

Bruce
- 23rd December 2010, 00:05
Place ANSEL = 0 in the top section to disable A/D.

Analog pins always read as 0, and the HIGH/LOW commands cause the whole port to be read, bits flipped, and the whole value being placed back on the port, so previous pins always get returned to 0.

comwarrior
- 23rd December 2010, 00:40
That works, thank you