Okay, so after a lot of pouring over the internet, I've figured out how to work the Configuration Bits in the high tech c compiler. It's now in my code below - except that I have not been able to figure out how take off code protection. Unfortunately, even in simulation, when I try to write anything to PORTB, nothing happens. I'm not going to move back to PWM until I can turn an LED on. Does anyone have any ideas why RB0 - and later, RB2 - refuse to go high?
Thanks in advance.
//title "Project Zero"
#include <dspic.h>
#include <dspic30f4011.h>
#include <hitech.h>
#include <htc.h>
//-----------------------------------------------------------------------------
__CONFIG(FOSC, EC & FSCMDIS);
__CONFIG(FWDT,WDTDIS);
__CONFIG(FBORPOR, BORDIS & MCLREN & HPOL);
//#define FOSC 10000000 // 10Mhz
//#define FCY (FOSC / 4) // 1 inscruction cycle = 4 clock cycles
void init(void)
{
TRISB = 0b000000000;
RB0=1;
}
void initpwm(void)
{
PTEN = 0; //Disable MCPWM
PWMCON1_PEN1H = 1; //PWM1H enabled for PWM output
PWMCON1_PEN2H = 1; //PWM2H enabled for PWM output
PTCKPS0 = 1; //PTCKPS<1:0> set to 01. 1:4 Prescale.
PTCKPS1 = 0;
PTOPS0 = 0; //PTOPS<3:0> set to 0s. 1:1 Postscale
PTOPS1 = 0;
PTOPS2 = 0;
PTOPS3 = 0;
PTSIDL = 1; // STOP in Idle Mode: Yes
PTMOD0 = 0; //PTMOD<1:0> set to 00. Free running mode.
PTMOD1 = 0;
PTEN = 1; //ENABLE MCPWM
PTPER = 11250;
}
void main(void)
{
initpwm();
init();
while(1) //Infinite loop
{
PDC1 = 1875; //should set PMW1 duty cycle.
PORTB = 100;
}
}
Thanks in advance.
Last edited: