Could someone please tell me why the below code does not give me apx. 50% brightness on an LED?
#chip 18f14k22,16
#config MCLRE=ON, OSC=IRC, LVP=OFF, PLLEN=off
#define Up portb.5
#define Down portb.6
dim bright as byte
dir Up in
dir Down in
dir portc.5 out
start:
set PR2 = 250
set T2CON.T2CKPS0 On
set T2CON.T2CKPS1 On
set CCPR1L = 125
set CCP1CON.DC1B1 on
set CCP1CON.DC1B0 on
set CCP1CON.CCP1M3 on
set CCP1CON.CCP1M2 on
set CCP1CON.CCP1M1 off
set CCP1CON.CCP1M0 off
set T2CON.TMR2ON On
goto start
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The problem lay with Microchip and how they decided to handle the debug bit for the 18fxxK22 devices. My Pickit 2 can manually set the !debug bit by ticking the config4L.7 box. Hugh has fixed this for the internal asm, which is how I deal with it when working with my 18lf14k22. I end up commenting out the MPASM lines in the COMPILE.BAT and MAKEASM.BAT and uncomment the following GCASM lines. One of these lines may not be required, because I think GCASM is default, I forget which one.
Could someone please tell me why the below code does not give me apx. 50% brightness on an LED?
#chip 18f14k22,16
#config MCLRE=ON, OSC=IRC, LVP=OFF, PLLEN=off
#define Up portb.5
#define Down portb.6
dim bright as byte
dir Up in
dir Down in
dir portc.5 out
start:
set PR2 = 250
set T2CON.T2CKPS0 On
set T2CON.T2CKPS1 On
set CCPR1L = 125
set CCP1CON.DC1B1 on
set CCP1CON.DC1B0 on
set CCP1CON.CCP1M3 on
set CCP1CON.CCP1M2 on
set CCP1CON.CCP1M1 off
set CCP1CON.CCP1M0 off
set T2CON.TMR2ON On
goto start
It's spot on, good job!
The problem lay with Microchip and how they decided to handle the debug bit for the 18fxxK22 devices. My Pickit 2 can manually set the !debug bit by ticking the config4L.7 box. Hugh has fixed this for the internal asm, which is how I deal with it when working with my 18lf14k22. I end up commenting out the MPASM lines in the COMPILE.BAT and MAKEASM.BAT and uncomment the following GCASM lines. One of these lines may not be required, because I think GCASM is default, I forget which one.
COMPILE.BAT
MAKEASM.BAT
Good to use the code tags when posting code next time. Also initializing registers usually before Main/Start.
P.S. I've heard that the newest MPLAB MPASM may have fixed the !debug bit problem, for at least some of the 18fxxK22's, but haven't yet tried myself.