Preview only show first 10 pages with watermark. For full document please download

Luz Usb3

Programa de automação residencial para microcontorladores, foi desenvolvido para pic18f4550 com conexão usb (simulando uma porta serial).

   EMBED

  • Rating

  • Date

    December 2018
  • Size

    2.5KB
  • Views

    3,661
  • Categories


Share

Transcript

#include <18F4550.h>,,,,,,,,,, #device adc=8,,,,,,,,,, #fuses XTPLL,MCLR, NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN, NOPBADEN #use delay(clock=48000000),,,,,,,,,, /*,,,,,,,,,, #define LCD_ENABLE_PIN PIN_D0 ////,,,,,,,,,, #define LCD_RS_PIN PIN_D1 ////,,,,,,,,,, #define LCD_RW_PIN PIN_D2 ////,,,,,,,,,, #define LCD_DATA4 PIN_D4 ////,,,,,,,,,, #define LCD_DATA5 PIN_D5 ////,,,,,,,,,, #define LCD_DATA6 PIN_D6 ////,,,,,,,,,, #define LCD_DATA7 PIN_D7 ,,,,,,,,,, #include ,,,,,,,,,, */,,,,,,,,,, // #define USB_CON_SENSE_PIN,,,,,,,,,, ,,,,,,,,,, #include ,,,,,,,,,, ,,,,,,,,,, void main() {,,,,,,,,,, //BYTE i, j, address, value;,,,,,,, char dados=0, flag='a';,,,,,,,,, int g=100, valor, i=0;,,,,,,,, unsigned int8 status;,,,,,,,,,, int16 q,q1;,,,,,,,,, float p;,,,,,,,,,, //lcd_init();,,,,,,,,,, q1=0;,,,,,,,,,, ,,,,,,,,,, setup_adc_ports(AN0);,,,,,,,,,, setup_adc(ADC_CLOCK_INTERNAL);,,,,,,,,,, set_adc_channel(0);,,,,,,,,,, ,,,,,,,,,, // set_tris_e(0b00000000);,,,,,,,,,, // set_tris_b(0b00000100);,,,,,,,,,, ,,,,,,,,,, usb_cdc_init();,,,,,,,,,, usb_init();,,,,,,,,,, ,,,,,,,,,, while(!usb_cdc_connected()) {output_high(pin_d1);},,,,,,,,,, ,,,,,,,,,, do {,,,,,,,,,, usb_task();,,,,,,,,,, output_low(pin_d1);,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, if (usb_enumerated()) {,,,,,,,,,, delay_ms(10);,,,,,,,,,, valor = read_adc(); ,,,,,,,,,, ,,,,,,,,,, //printf(lcd_putc,\f%u, valor);,,,,,,,, ,,,,,,,,,, ;,,,,,,,,,, if(usb_cdc_kbhit()),,,,,,,,,, {,,,,,,,,,, ,,,,,,,,,, dados = usb_cdc_getc();,,,,,,,,,, output_high(pin_d1);,,,,,,,,,, },,,,,,,,,, ,,,,,,,,,, if (dados && dados!='g' && dados !='s' && dados!='f') flag=dados;,,,,,,,,,, ,,,,,,,,,, if (dados=='g') ,,,,,,,,,, {,,,,,,,,,, ,,,,,,,,,, g=valor;,,,,,,,,,, //printf(lcd_putc,\fLuz Salva : %c, g);,,,,,,,, //delay_ms(100);,,,,,,,,,, dados='a';,,,,,,,,,, ,,,,,,,,,, },,,,,,,,,, ,,,,,,,,,, if (dados=='s') {,,,,,,,,,, ,,,,,,,,,, if (usb_cdc_putready()),,,,,,,,,, {,,,,,,,,,, ,,,,,,,,,, usb_cdc_putc(valor);,,,,,,,,,, dados='f';,,,,,,,,,, },,,,,,,,,, },,,,,,,,,, //i++;,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, if (flag =='l' ) output_high(pin_e0);,,,,,,,,,, if (flag =='k' ) output_high(pin_e1);,,,,,,,,,, if (flag =='j' ) output_high(pin_e2);,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, if (flag =='e' ) output_low(pin_e0);,,,,,,,,,, if (flag =='d' ) output_low(pin_e1);,,,,,,,,,, if (flag =='c' ) output_low(pin_e2);,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, if (flag =='a' ),,,,,,,,,, {,,,,,,,,,, if (valor<= g) output_high(pin_e0);,,,,,,,,,, if (valor<= g-20) output_high(pin_e1);,,,,,,,,,, if (valor<= g-40) output_high(pin_e2);,,,,,,,,,, ,,,,,,,,,, if (valor> g) output_low(pin_e0);,,,,,,,,,, if (valor> g-20) output_low(pin_e1);,,,,,,,,,, if (valor> g-40) output_low(pin_e2);,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, },,,,,,,,,, },,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, } while (TRUE);,,,,,,,,,, },,,,,,,,,,