SlideShare uma empresa Scribd logo
1 de 3
Baixar para ler offline
////////////////////////////////////////////////////////////////////////////
void inicializa_timer_0()
{
T0CONbits.TMR0ON=1;//1 liga timer0
T0CONbits.T08BIT=0;//1=8bits
T0CONbits.T0CS=0;//0 clock interno 1/2
T0CONbits.T0SE=1;//1 BORDA DE DESCIDA
T0CONbits.PSA=0;// 0=LIGA PRESCALER
T0CONbits.T0PS2=1;
T0CONbits.T0PS1=1;
T0CONbits.T0PS0=1;//111=1:256
//1000 atualizações do timer=7 segundos
}
////////////////////////////////////////////////////////////////////////////
void inicializa_timer_1()
{
T1CONbits.RD16=0;//0=8bits
T1CONbits.T1CKPS1=0;
T1CONbits.T1CKPS0=0;//11=1:8 00=1:1
T1CONbits.T1OSCEN=0;
T1CONbits.T1SYNC=1;//1 nao sincronizado
T1CONbits.TMR1CS=0;//0 clock interno 1/4
//T1CONbits.TMR1ON=1;//1 liga timer1
}
////////////////////////////////////////////////////////////////////////////
void inicializa_timer_2()
{
T2CONbits.TOUTPS3=1;//0110
T2CONbits.TOUTPS2=1;
T2CONbits.TOUTPS1=1;
T2CONbits.TOUTPS0=1;//0111 1:16 postscale
T2CONbits.T2CKPS1=0;//01
T2CONbits.T2CKPS0=1;//11 prescale=1:16
//8*16*4*256=131072/20MHz=6,55ms
T2CONbits.TMR2ON=1;//1 liga timer1
}
////////////////////////////////////////////////////////////////////////////
void inicializa_entradas_analogicas()
{
ADCON0bits.ADCS1=1;//AD CONVERSION CLOCK
ADCON0bits.ADCS0=0;//AD CONVERSION CLOCK
ADCON0bits.CHS2=0;//ANALOG CHANNEL SELECT BITS
ADCON0bits.CHS1=0;//ANALOG CHANNEL SELECT BITS
ADCON0bits.CHS0=0;//ANALOG CHANNEL SELECT BITS
//ADCON0bits.GO=1;//A/D CONVERSION STATUS BIT
ADCON0bits.ADON=1;//A/D ON BIT
ADCON1bits.ADFM=1;//A/D RESULT FORMAT SELECTION BIT
ADCON1bits.ADCS2=1;//A/D CONVERSION CLOCK
ADCON1bits.PCFG3=0;//A/D PORT CONFIGURATION CONTROL BITS
ADCON1bits.PCFG2=0;//A/D PORT CONFIGURATION CONTROL BITS
ADCON1bits.PCFG1=1;//A/D PORT CONFIGURATION CONTROL BITS
ADCON1bits.PCFG0=0;//A/D PORT CONFIGURATION CONTROL BITS
}
////////////////////////////////////////////////////////////////////////////
void inicializa_saidas()
{
lcd_rs_dir=0;
lcd_en_dir=0;
lcd_d4_dir=0;
lcd_d5_dir=0;
lcd_d6_dir=0;
lcd_d7_dir=0;
}
////////////////////////////////////////////////////////////////////////////
void PWM1_Set_Duty(unsigned int potencia)
{
if(potencia>PR2)CCPR1=PR2-1;
else if(potencia<=0)CCPR1=0;
else CCPR1=potencia;
}
////////////////////////////////////////////////////////////////////////////
void inicializa_pwm_1()
{
inicializa_timer_2();
//set the PWM period by writing to the PR2 register
PR2=255;//255=MAXIMO
//set the pwm duty cycle by writing to the CCPR1L register and CCP1CON<5:4> bits
//CCPR1=0;
CCPR1=PR2+1;
CCP1CONbits.DC1B1=0;
CCP1CONbits.DC1B0=0;
//make the CCP1 pin an output by clearing the TRISC<2> bit
TRISCbits.TRISC2=0;
//configure the CCP1 module for PWM operation
CCP1CONbits.CCP1M3=1;
CCP1CONbits.CCP1M2=1;
CCP1CONbits.CCP1M1=1;
CCP1CONbits.CCP1M0=1;
}
////////////////////////////////////////////////////////////////////////////
unsigned int ADC_Read(unsigned int canal)
{
if(canal==0)
{
ADCON0bits.CHS2=0;
ADCON0bits.CHS1=0;
ADCON0bits.CHS0=0;
}
if(canal==1)
{
ADCON0bits.CHS2=0;
ADCON0bits.CHS1=0;
ADCON0bits.CHS0=1;
}
if(canal==2)
{
ADCON0bits.CHS2=0;
ADCON0bits.CHS1=1;
ADCON0bits.CHS0=0;
}
if(canal==3)
{
ADCON0bits.CHS2=0;
ADCON0bits.CHS1=1;
ADCON0bits.CHS0=1;
}
delay_10us(1);
ADCON0bits.GO=1;
while(ADCON0bits.GO);
valor=ADRESL+(256*ADRESH);
return(valor);
}
Observação: Autoria Engenheiro Rodrigo Lacerda Taschetto.

Mais conteúdo relacionado

Mais de Simuladorgeradoreolico (20)

Biblioteca PIC18F452
Biblioteca PIC18F452Biblioteca PIC18F452
Biblioteca PIC18F452
 
Biblioteca LCD
Biblioteca LCDBiblioteca LCD
Biblioteca LCD
 
Biblioteca Atraso
Biblioteca AtrasoBiblioteca Atraso
Biblioteca Atraso
 
Grupo 1 - Velocidades
Grupo 1 - VelocidadesGrupo 1 - Velocidades
Grupo 1 - Velocidades
 
Grupo 2 - Velocidades
Grupo 2 - VelocidadesGrupo 2 - Velocidades
Grupo 2 - Velocidades
 
Grupo 3 - Velocidades
Grupo 3 - VelocidadesGrupo 3 - Velocidades
Grupo 3 - Velocidades
 
Grupo 4 - Velocidades
Grupo 4 - VelocidadesGrupo 4 - Velocidades
Grupo 4 - Velocidades
 
Programa simulador de gerador eólico
Programa simulador de gerador eólicoPrograma simulador de gerador eólico
Programa simulador de gerador eólico
 
PIC18F452
PIC18F452PIC18F452
PIC18F452
 
LCD
LCDLCD
LCD
 
Pinagem
PinagemPinagem
Pinagem
 
Atraso
AtrasoAtraso
Atraso
 
ANEXO A - Grupo 4
ANEXO A - Grupo 4ANEXO A - Grupo 4
ANEXO A - Grupo 4
 
ANEXO A - Grupo 3
ANEXO A - Grupo 3ANEXO A - Grupo 3
ANEXO A - Grupo 3
 
ANEXO A - Grupo 1
ANEXO A - Grupo 1ANEXO A - Grupo 1
ANEXO A - Grupo 1
 
ANEXO A - Grupo 2
ANEXO A - Grupo 2ANEXO A - Grupo 2
ANEXO A - Grupo 2
 
ANEXO A - Grupo 4
ANEXO A - Grupo 4ANEXO A - Grupo 4
ANEXO A - Grupo 4
 
ANEXO A - Grupo 3
ANEXO A - Grupo 3ANEXO A - Grupo 3
ANEXO A - Grupo 3
 
ANEXO A - Grupo 1
ANEXO A - Grupo 1ANEXO A - Grupo 1
ANEXO A - Grupo 1
 
ANEXO A - Grupo 2
ANEXO A - Grupo 2ANEXO A - Grupo 2
ANEXO A - Grupo 2
 

Bibliotecas Complementares

  • 1. //////////////////////////////////////////////////////////////////////////// void inicializa_timer_0() { T0CONbits.TMR0ON=1;//1 liga timer0 T0CONbits.T08BIT=0;//1=8bits T0CONbits.T0CS=0;//0 clock interno 1/2 T0CONbits.T0SE=1;//1 BORDA DE DESCIDA T0CONbits.PSA=0;// 0=LIGA PRESCALER T0CONbits.T0PS2=1; T0CONbits.T0PS1=1; T0CONbits.T0PS0=1;//111=1:256 //1000 atualizações do timer=7 segundos } //////////////////////////////////////////////////////////////////////////// void inicializa_timer_1() { T1CONbits.RD16=0;//0=8bits T1CONbits.T1CKPS1=0; T1CONbits.T1CKPS0=0;//11=1:8 00=1:1 T1CONbits.T1OSCEN=0; T1CONbits.T1SYNC=1;//1 nao sincronizado T1CONbits.TMR1CS=0;//0 clock interno 1/4 //T1CONbits.TMR1ON=1;//1 liga timer1 } //////////////////////////////////////////////////////////////////////////// void inicializa_timer_2() { T2CONbits.TOUTPS3=1;//0110 T2CONbits.TOUTPS2=1; T2CONbits.TOUTPS1=1; T2CONbits.TOUTPS0=1;//0111 1:16 postscale T2CONbits.T2CKPS1=0;//01 T2CONbits.T2CKPS0=1;//11 prescale=1:16 //8*16*4*256=131072/20MHz=6,55ms T2CONbits.TMR2ON=1;//1 liga timer1 } //////////////////////////////////////////////////////////////////////////// void inicializa_entradas_analogicas() { ADCON0bits.ADCS1=1;//AD CONVERSION CLOCK ADCON0bits.ADCS0=0;//AD CONVERSION CLOCK ADCON0bits.CHS2=0;//ANALOG CHANNEL SELECT BITS ADCON0bits.CHS1=0;//ANALOG CHANNEL SELECT BITS ADCON0bits.CHS0=0;//ANALOG CHANNEL SELECT BITS //ADCON0bits.GO=1;//A/D CONVERSION STATUS BIT ADCON0bits.ADON=1;//A/D ON BIT ADCON1bits.ADFM=1;//A/D RESULT FORMAT SELECTION BIT ADCON1bits.ADCS2=1;//A/D CONVERSION CLOCK ADCON1bits.PCFG3=0;//A/D PORT CONFIGURATION CONTROL BITS ADCON1bits.PCFG2=0;//A/D PORT CONFIGURATION CONTROL BITS
  • 2. ADCON1bits.PCFG1=1;//A/D PORT CONFIGURATION CONTROL BITS ADCON1bits.PCFG0=0;//A/D PORT CONFIGURATION CONTROL BITS } //////////////////////////////////////////////////////////////////////////// void inicializa_saidas() { lcd_rs_dir=0; lcd_en_dir=0; lcd_d4_dir=0; lcd_d5_dir=0; lcd_d6_dir=0; lcd_d7_dir=0; } //////////////////////////////////////////////////////////////////////////// void PWM1_Set_Duty(unsigned int potencia) { if(potencia>PR2)CCPR1=PR2-1; else if(potencia<=0)CCPR1=0; else CCPR1=potencia; } //////////////////////////////////////////////////////////////////////////// void inicializa_pwm_1() { inicializa_timer_2(); //set the PWM period by writing to the PR2 register PR2=255;//255=MAXIMO //set the pwm duty cycle by writing to the CCPR1L register and CCP1CON<5:4> bits //CCPR1=0; CCPR1=PR2+1; CCP1CONbits.DC1B1=0; CCP1CONbits.DC1B0=0; //make the CCP1 pin an output by clearing the TRISC<2> bit TRISCbits.TRISC2=0; //configure the CCP1 module for PWM operation CCP1CONbits.CCP1M3=1; CCP1CONbits.CCP1M2=1; CCP1CONbits.CCP1M1=1; CCP1CONbits.CCP1M0=1; } //////////////////////////////////////////////////////////////////////////// unsigned int ADC_Read(unsigned int canal) { if(canal==0) { ADCON0bits.CHS2=0; ADCON0bits.CHS1=0; ADCON0bits.CHS0=0; } if(canal==1) { ADCON0bits.CHS2=0; ADCON0bits.CHS1=0;