Hello, I´m new using the PBP.
My programm shall be an PWM Controller for RGB LED.
I´m using a PIC16F88.
PortB is Digital Output (PWM 250Hz), PortA is Digital Input.
Is there something special at this chip (register/ansel/cmcon..) to watch for?
The MCLR is connected with 4k7 to VDD (Must this be? I would like to use this pin also as an high-active input)
When I apply Power (Power Supply is good, 100n attached) it works some times correct. When I apply power next time, chip hangs up
(outputs blinking undefined, chip is touch-sensitive). It seems as if any initialisation failes?? (no tris-setting?, but therefore I put already a pause 1000 in the beginning)
Thanks in Advance
(Sorry for my German-English)
Best regards
Norbert

Code:
REM Prozessordefinitionen und Register setzen
define osc4
osccon = $60

@ DEVICE INTRC_OSC, lvp_off, wdt_off, MCLR_off

cmcon = 7
ansel=0

pause 1000

trisa=%11101111 
REM RA4=Ausgang, alle anderen Eingang
trisb=%00000000 
REM RB=Ausgang

disable

ROTWERT var word
GRUENWERT VAR WORD
BLAUWERT VAR WORD
SCHNELLZAEHL var word
SCHNELLWERT VAR WORD
SCHNELLWERTZAEHL VAR WORD
TASTEEIN VAR BYTE
ROT var word
GRUEN var word
BLAU var word

LET SCHNELLWERT=30
LET SCHNELLWERTZAEHL=0
let SCHNELLZAEHL=1
LET TASTEEIN=0
let ROT=0
let GRUEN=0
LET BLAU=0

REM Programmstart
REM-----------------------------------------------------------------------------
REM ANFANG SCHWELLER
porta.4=1
portb=%11111111

SCHWELLER:
REM Rote LED wird von dunkel nach hell gesteuert
let ROT=0
for ROTWERT = 40 to 4000 step 40 
    for SCHNELLZAEHL = 1 to SCHNELLWERT
        porta.4=1
        portb.2=1
        portb.5=1
        gosub TASTE
        if tasteein=3 then let ROT=ROTWERT
        IF TASTEEIN>=1 then GOTO TASTENWERK
        pauseus 4000-ROTWERT
        porta.4=0
        portb.2=0
        portb.5=0
        pauseus ROTWERT
    next SCHNELLZAEHL
next ROTWERT
let rot=4000   
 
REM Gruene LED wird von dunkel nach hell gesteuert
let GRUEN=0
for GRUENWERT = 40 to 4000 step 40 
    for SCHNELLZAEHL = 1 to SCHNELLWERT
        portb.1=1
        portb.4=1
        portb.7=1
        gosub TASTE
        if tasteein=3 then let gruen=gruenwert
        IF TASTEEIN>=1 then GOTO TASTENWERK
        pauseus 4000-GRUENWERT
        portb.1=0
        portb.4=0
        portb.7=0
        pauseus GRUENWERT
    next SCHNELLZAEHL
next GRUENWERT 
LET gruen=4000

REM Blaue LED wird von dunkel nach hell gesteuert
let blau=0
for BLAUWERT = 40 to 4000 step 40 
    for SCHNELLZAEHL = 1 to SCHNELLWERT
        portb.0=1
        portb.3=1
        portb.6=1
        gosub TASTE
        if tasteein=3 then let blau=blauwert
        IF TASTEEIN>=1 then GOTO TASTENWERK
        pauseus 4000-BLAUWERT
        portb.0=0
        portb.3=0
        portb.6=0
        pauseus BLAUWERT
    next SCHNELLZAEHL
next BLAUWERT
let blau=4000 

REM Gruene LED wird von hell nach dunkel gesteuert
let gruen=4000
for GRUENWERT = 4000 to 200 step -40 
    for SCHNELLZAEHL = 1 to SCHNELLWERT
        portb.1=0
        portb.4=0
        portb.7=0
        pauseus GRUENWERT
        portb.1=1
        portb.4=1
        portb.7=1
        gosub TASTE
        if tasteein=3 then let gruen=gruenwert
        IF TASTEEIN>=1 then GOTO TASTENWERK
        pauseus 4000-GRUENWERT
    next SCHNELLZAEHL
next GRUENWERT
LET gruen=0

REM Rote LED wird von hell nach dunkel gesteuert
let rot=4000
for ROTWERT = 4000 to 200 step -40 
    for SCHNELLZAEHL = 1 to SCHNELLWERT
        porta.4=0
        portb.2=0
        portb.5=0
        pauseus ROTWERT
        porta.4=1
        portb.2=1
        portb.5=1
        gosub TASTE
        if tasteein=3 then let rot=rotwert
        IF TASTEEIN>=1 then GOTO TASTENWERK
        pauseus 4000-ROTWERT
    next SCHNELLZAEHL
next ROTWERT
LET rot=0

REM Blaue LED wird von hell nach dunkel gesteuert
let blau=4000
for BLAUWERT = 4000 to 200 step -40 
    for SCHNELLZAEHL = 1 to SCHNELLWERT
        portb.0=0
        portb.3=0
        portb.6=0
        pauseus BLAUWERT
        portb.0=1
        portb.3=1
        portb.6=1
        gosub TASTE
        if tasteein=3 then let blau=blauwert
        IF TASTEEIN>=1 then GOTO TASTENWERK
        pauseus 4000-BLAUWERT
    next SCHNELLZAEHL
next BLAUWERT
let blau=0 

goto SCHWELLER
REM ENDE SCHWELLER
REM-----------------------------------------------------------------------------
REM ANFANG STATISCH ROT, GRUEN, BLAU
STATISCH_ROT:
rem rot_an
porta.4=0
portb.2=0
portb.5=0
rem blau_aus
portb.0=1
portb.3=1
portb.6=1
rem gruen_aus
portb.1=1
portb.4=1
portb.7=1
gosub taste
IF TASTEEIN>=1 then GOTO TASTENWERK
goto statisch_rot

STATISCH_GRUEN:
rem rot_aus
porta.4=1
portb.2=1
portb.5=1
rem blau_aus
portb.0=1
portb.3=1
portb.6=1
rem gruen_an
portb.1=0
portb.4=0
portb.7=0
gosub taste
IF TASTEEIN>=1 then GOTO TASTENWERK
goto statisch_gruen

STATISCH_BLAU:
rem rot_aus
porta.4=1
portb.2=1
portb.5=1
rem blau_an
portb.0=0
portb.3=0
portb.6=0
rem gruen_aus
portb.1=1
portb.4=1
portb.7=1
gosub taste
IF TASTEEIN>=1 then GOTO TASTENWERK
goto statisch_blau
REM ENDE STATISCH ROT, GRUEN, BLAU 
REM-----------------------------------------------------------------------------
REM START STATISCHES LICHT AUS GESTOPPTEN SCHWELLER
SCH_STAT:
REM ROTER STATISCHER WERT AUS SCHWELLER
porta.4=0
portb.2=0
portb.5=0
pauseus ROT
porta.4=1
portb.2=1
portb.5=1
pauseus 4000-ROT
REM GRUENER STATISCHER WERT AUS SCHWELLER
portb.1=0
portb.4=0
portb.7=0
pauseus GRUEN
portb.1=1
portb.4=1
portb.7=1
pauseus 4000-GRUEN
REM BLAUER STATISCHER WERT AUS SCHWELLER
portb.0=0
Portb.3=0
portb.6=0
pauseus BLAU
portb.0=1
portb.3=1
portb.6=1
pauseus 4000-BLAU
gosub taste
IF TASTEEIN>=1 then GOTO TASTENWERK
GOTO SCH_STAT
REM ENDE STATISCHES LICHT AUS GESTOPPTEN SCHWELLER
REM-----------------------------------------------------------------------------
REM ANFANG ZUORDNUNG DER GEDRÜCKTEN TASTE ZU EINER VARIABLEN
TASTE:
let tasteein=0
'if porta.0=1 then let TASTEEIN=1
'IF porta.1=1 then let tasteein=2
'if porta.2=1 then let tasteein=3
'if porta.3=1 then let tasteein=4
'if porta.5=0 then let tasteein=5
'if porta.6=1 then let tasteein=6
'if porta.7=1 then let tasteein=7
RETURN
REM ENDE ZUORDNUNG DER GEDRÜCKTEN TASTE ZU EINER VARIABLEN
REM-----------------------------------------------------------------------------
REM ANFANG AUSWAHL DER MODULE
TASTENWERK:
PAUSE 100
select case tasteein
        case 1
            goto EIN
        case 2
            goto schnell
        case 3 
            goto sch_stat
        case 4
            goto AUS
        case 5
            goto statisch_rot
        case 6
            goto statisch_gruen
        case 7
            goto statisch_Blau
end select
let tasteein=0
goto schweller
REM ENDE AUSWAHL DER MODULE
REM-----------------------------------------------------------------------------
REM ANFANG EIN
EIN:
READ 0,ROT.byte0
READ 1,ROT.byte1
read 2,BLAU.byte0
read 3,blau.byte1
read 4,gruen.byte0
read 5,gruen.byte1
pause 100
goto sch_stat
REM ENDE EIN
REM-----------------------------------------------------------------------------
REM ANFANG AUS
AUS:
write 0,rot.byte0
write 1,rot.byte1
write 2,blau.byte0
write 3,blau.byte1
write 4,gruen.byte0
write 5,gruen.byte1
pause 10
AUSAUS:
porta.4=1
portb.2=1
portb.5=1
portb.0=1
portb.3=1
portb.6=1
portb.1=1
portb.4=1
portb.7=1
gosub taste
IF TASTEEIN>=1 then GOTO TASTENWERK
goto ausaus
REM ENDE AUS
REM-----------------------------------------------------------------------------
REM ANFANG GESCHWINDIGKEITSEINSTELLUNG SCHWELLER
SCHNELL:
pause 100
let SCHNELLWERTZAEHL=SCHNELLWERTZAEHL+1
IF SCHNELLWERTZAEHL=4 THEN LET SCHNELLWERTZAEHL=1

SELECT CASE SCHNELLWERTZAEHL
CASE 1
SCHNELLWERT=5
CASE 2
SCHNELLWERT=15
CASE 3
SCHNELLWERT=30
END SELECT
let SCHNELLZAEHL=1
let tasteein=0
GOTO SCHWELLER
REM ENDE GESCHWINDIGKEITSEINSTELLUNG SCHWELLER
REM-----------------------------------------------------------------------------
END