// feito por Andre e Matheus #include /* include peripheral declarations */ #include void main(void) { // byte pw; byte i; int soma; byte leitura; byte anterior; // byte a; PTA = 0; /* clear/initialize Port A */ /* do PWM */ TSC_TSTOP = 1; // stop counter TSC_PS = 0; // prescaler divide por 1 TSC_TRST = 1; // reset counter TMODH = 0; TMODL = 250; // PWM frequency 20kHz TCH1H = 0; TCH1L = 50; // pulse width TSC0_MS0B = 0; // PWM TSC1_MS1A = 1; // output compare TSC1_ELS1B = 1; TSC1_ELS1A = 0; // clear on compare TSC1_TOV1 = 1; // toggle on overflow TSC_TSTOP = 0; // start counter // _DDRA.Bits.DDRA1 = 1; /* set Bit 1 as output */ /* do AD */ ADSCR_CH = 2; // entrada pino AD2=PTA4 ADSCR_ADCO = 1; // convert continously ADICLK_ADIV = 2; // AD clock = 5MHz/4 (about 1MHz) for(;;) { soma = 0; anterior = 0; for(i=0;i<200;i++) { while(!PTA_PTA1); // for(a=0;a<100;a++); // atraso de 25 microsegundos // leitura = ADR; leitura=abs(ADR-0x80); leitura = abs(leitura-((95*anterior)/100)); // Aplicacao da Pre-Enfase soma += leitura; anterior = leitura; while(PTA_PTA1); // for(a=0;a<100;a++); // atraso de 25 microsegundos } if(soma>3500) { /* 5 <= TCH1L <= 230 */ if(TCH1L == 230) TCH1L = 5; else TCH1L = 230; // PTA_PTA1 = !PTA_PTA1; } } }