#include <system.h>
#pragma DATA 0x2007, _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _HS_OSC
#pragma CLOCK_FREQ 12000000
void main()
{
set_bit(trisb,6); //USB D+
set_bit(trisb,7); //USB D-
clear_bit(trisa,1); //LED1
clear_bit(trisb,4); //LED2
while(true)
{
set_bit(porta,1);
set_bit(portb,4);
char data=0;
while(true) //keep checking PB6 and PB7 for data, light LEDs if '1' bits received
{
if(test_bit(portb,6))
clear_bit(porta,1); //light LED1
else
set_bit(porta,1);
if(test_bit(portb,7))
clear_bit(portb,4); //light LED2
else
set_bit(portb,4);
//delay_ms(255);
}
/*
**Ignore: early attempt to read in a single byte
for(int i=0;i<8;i++)
{
data<<=1;
data|=test_bit(portb,6);
}
if(data==0)
clear_bit(porta,1); //turn on the red LED if it was a null byte
*/
}
}