Esse é o nosso código:
#include "exusb.h"
//Incluí a biblioteca da USB usando a serial
#include
#define LED PIN_C0 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
#define PORT_B *0xF81
void main()
{
setup_adc_ports (NO_ANALOGS|VSS_VDD);
setup_adc (ADC_CLOCK_DIV_2);
setup_psp (PSP_DISABLED);
setup_spi (SPI_SS_DISABLED);
setup_wdt (WDT_OFF);
setup_timer_0 (RTCC_INTERNAL);
setup_timer_1 (T1_DISABLED);
setup_timer_2 (T2_DISABLED, 0, 1) ;
setup_ccp1 (CCP_OFF);
setup_comparator (NC_NC_NC_NC);
setup_vref (FALSE);
//Inicia a USB
usb_init_cs ();
output_b(0);
//Example blinking LED program
while (true)
{
usb_task ();
if (usb_cdc_kbhit () )
{
int c;
c = usb_cdc_getc ();
if (c == 'A')
{
//acende
output_high (PIN_B7) ;
}
else if (c == 'a')
{
//apaga
output_low (PIN_B7) ;
}
else if (c == 'B')
{
//acende
output_high (PIN_B6) ;
}
else if (c == 'b')
{
//apaga
output_low (PIN_B6) ;
}
else if (c == 'C')
{
//acende
output_high (PIN_B5) ;
}
else if (c == 'c')
{
//apaga
output_low (PIN_B5) ;
}
else if (c == 'D')
{
//acende
output_high (PIN_B4) ;
}
else if (c == 'd')
{
//apaga
output_low (PIN_B4) ;
}
else if (c == 'E')
{
//acende
output_high (PIN_B3) ;
}
else if (c == 'e')
{
//apaga
output_low (PIN_B3) ;
}
else if (c == 'F')
{
//acende
output_high (PIN_B2) ;
}
else if (c == 'f')
{
//apaga
output_low (PIN_B2) ;
}
else if (c == 'G')
{
//acende
output_high (PIN_B1) ;
}
else if (c == 'g')
{
//apaga
output_low (PIN_B1) ;
}
else if (c == 'H')
{
//acende
output_high (PIN_B0) ;
}
else if (c == 'h')
{
//apaga
output_low (PIN_B0) ;
}
//ativa
else if (c == 'i')
{
usb_cdc_putc(PORT_B);
usb_cdc_putc(0);
}
}
}
}