Hi all,
Numpty here is tearing his hair out.
All I want this code to do is run in an endless loop, where RB0 is low I want the pulse to be faster than when RB0 is high.
#define _XTAL_FREQ 8000000 //set osc. frequency
#include <xc.h> //include xc8 header
#define PULSE LATAbits.LATA0 //define pin RA0 as PULSE pin
#define DIR LATAbits.LATA1 //define pin AR1 as DIRECTION pin
#define SPEED PORTBbits.RB0 //define pin RB0 as SPEED pin
int main ()
{
ADCON1 = 0xFF; //switch OFF Port-A ADC
CMCON = 0xFF; //switch OFF comparitors
TRISAbits.RA0 = 0; //define A0 as OUTPUT
TRISAbits.RA1 = 0; //define A1 as OUTPUT
TRISBbits.RB0 = 1; //define B0 as INPUT
DIR = 0; //Change value to '1' for reversed motor
while (1) //inititalise while loop
{
if (SPEED == 1) {
PULSE= ~PULSE; //Set PULSE toggle
__delay_us(50); //Toggle pulse SLOW
}
else {
PULSE= ~PULSE;
__delay_us(5); //Toggle pulse FAST
}
}
return 0;
}
Now I've written this all by myself (ha) and I'm very fresh at this with a combined C coding experience measured in only a few hours.
Why does the RB0 show as a Digital OUTPUT in the MPBLab simulator?
Yours, expecting he's done something stupid!
Ed.