int main(void){ configUart(115200, 'N', 1); TRISEbits.TRISE0 = 0; // RE0 como saída while(1){ while(U1STAbits.TRMT == 0); LATEbits.LATE0 = 1; //Set RE0 puts_("123456789AB"); LATEbits.LATE0 = 0; //Reset RE0 } }
// función principal int main (void) { // Inicializamos la placa initBoard(); // configuramos la UART a 9600 bps configUart(9600); setUartRxIsr(rx); // Bucle infinito while(1) { // enviamos un byte por la UART setUartTx('*'); // parpadeamos el led para saber que estamos vivos! togglePin(&LED[0]); // esperamos medio segundo para que no vaya tan rápido! delay_ms(500); } return 0; }
int main(void) { const static unsigned char pwmValues[]={3, 15, 40, 90}; /* ADC */ TRISBbits.TRISB14 = 1; // RB14 digital output disconnected AD1PCFGbits.PCFG14 = 0; // RB14 configured as analog input (AN4) AD1CON1bits.SSRC = 7; // Conversion trigger selection bits: in this // modeaninternalcounterendssamplingand AD1CON1bits.CLRASAM = 1; // Stop conversions when the 1st A/D converter AD1CON1bits.ON = 1; AD1CON3bits.SAMC = 16; // Sample time is 16 TAD (TAD = 100 ns) AD1CHSbits.CH0SA = 14; AD1CON2bits.SMPI = 7; // uma conversao consecutiva IPC6bits.AD1IP = 3; // valor aleatório entre 1 e 6, 0 é inativo e 7 prioridade máxima. Como só há uma interrupção pode ser qualquer valor entre 1 e 6 IEC1bits.AD1IE = 1; // autorizar interrupções pelo módulo A/D IFS1bits.AD1IF = 0; // Quando a conversao estiver concluida, este valor deve ser 1 /* TIMER 3 */ T3CONbits.TCKPS = 2; PR3 = 49999; // Fout = 20MHz / (32 * (39061,5 + 1)) = 2 Hz TMR3 = 0; // Reset timer T3 count register T3CONbits.TON = 1; // Enable timer T3 (must be the last command of the // timer configuration sequence) // configuraçao das interrupts tabela 7.1 IPC3bits.T3IP = 4; // Configurar a prioridade relativa IFS0bits.T3IF = 0; // Reset do Instruction Flag IEC0bits.T3IE = 1; // Autorizar a interrupção /* UART1 */ configUart(115200,'N',1); OC1CONbits.OCM = 6; // ativação do modo PWM OC1CONbits.OCTSEL = 1; // 1 ou 0 - ver página 16.8 OC1CONbits.ON = 1; // ativação do módulo EnableInterrupts(); // Autorização globalmente o sistema de interrupções AD1CON1bits.ASAM = 1; while(1){ int portval = (PORTE >> 4) & 0x3; switch (portval) { case 0: IEC0bits.T1IE = 1; setPWM(0); break; case 1: IEC0bits.T1IE = 1; setPWM(100); break; case 2: IEC0bits.T1IE = 0; int dc = (PORTE >> 6) & 0x3; setPWM(pwmValues[dc]); break; } IEC0bits.T1IE = 0; }; return 0; }