Habilitar Timer por meio do registrador

Software e Hardware para uC PIC

Moderadores: andre_luis, 51, guest2003, Renie

Habilitar Timer por meio do registrador

Mensagempor wBB » 24 Dez 2016 11:59

Pessoal, estou usando o MPLab onde, para habilitar uma interrupção qualquer usa-se "enable_interrupts(INT_XXX)". Preciso habilitar o Timer1, então neste caso ficaria "enable_interrupts(INT_TIMER1)". Isso funciona perfeitamente. Porém, com objetivo de tornar o código compatível com outros compiladores, estou tentando usar sempre os registradores diretamente para habilitar/setar/desabilitar as coisas. Neste meu caso a habilitação do Timer1 seria por meio do registrador T1CON (ENDEREÇO 10h) conforme mostra a figura anexa. Meu código fica mais ou menos assim:

Alguém sabe o motivo disso não funcionar com o registrador diretamente?

Código: Selecionar todos
#include <16f73>
#include <...>...
#fuses HS, NOWDT
.
.
.
// Registrador em questão
#byte T1CON = 0x10
.
.
.
void main()
{
    // Setando o bit de T1CON que DEVERIA habilitar o Timer1, mas não habilita
    T1CON = 0x01;

    // Se colocar isso abaixo, aí sim habilita o Timer1. Mas "T1CON = 0x01;" também deveria habilitar...
    enable_interrupts(INT_TIMER1)

    while (true) {

    }
}
Você não está autorizado a ver ou baixar esse anexo.
wBB
Bit
 
Mensagens: 23
Registrado em: 18 Nov 2016 18:45

Re: Habilitar Timer por meio do registrador

Mensagempor tcpipchip » 25 Dez 2016 09:50

unsigned char *PT_buffer=&TXB0D0;
------------------------------------------
http://www.youtube.com/tcpipchip
Avatar do usuário
tcpipchip
Dword
 
Mensagens: 6560
Registrado em: 11 Out 2006 22:32
Localização: TCPIPCHIPizinho!

Re: Habilitar Timer por meio do registrador

Mensagempor wBB » 26 Dez 2016 11:30

TXB0D0????????

Já resolvi. Existem dois bits em dois registradores diferentes que devem ser setados para que o Timer 1 funcione tal como se estivesse executando a função "enable_interrupts(INT_TIMER1)". São eles:
Código: Selecionar todos
// HABILITAR TIMER1==========================================
T1CON = 0x31;   //0011 0001
                // Prescale nos bits 5-4, 1:8 neste caso
                // Habilitação do Timer1 bit0
                // ds:"Timer1 can be enabled/disabled by setting/clearing
                //     control bit TMR1ON (T1CON<0>)"

PIE1_TMR1IE = 1; // bit0 do registrador PIE1
                 // ds: "This interrupt can be enabled/disabled by
                 //      setting/clearing TMR1 interrupt enable bit
                 //      TMR1IE (PIE1<0>)"

PIR1_TMR1IF = 0; // Flag de indicação de estouro do Timer1. Registrador PIR1, bit0


Obrigado!
wBB
Bit
 
Mensagens: 23
Registrado em: 18 Nov 2016 18:45


Voltar para PIC

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x