This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
Interrupciones y EUSART pic 16F887
#1
Buenas, estoy haciendo un programa para que comunicar una serie de pics que controlora cada uno una matriz de leds.
Cada pic mostrara un caracter multiplexando las salidas, eso OK, con interrupciones del TMR0 lo logro sin problemas, el pic master ha de enviar el caracter a cada uno y una vez que el ultimo le confirma que lo ha recibido da la orden de encender a todos.
El problema viene que dicho master no me envia nada por el pin RC6/TX si tengo habilitado el bit 7 del registro INTCON. Yo necesito las interrupciones del TMR0 y la de recepcion de EUSART, si pongo el bit GIE a 0 me envia el caracter sin problemas, al habilitarlo, el pin se queda a nivel alto.
Alguna idea?
Saludos.
  Responder
#2
Sin ver el código es difícil de decir. ¿Puede ser que se esté disparando otra interrupción continuamente y por eso no llegues a la parte que necesitas (enviar el byte)? Si tienes el bit TXIE (En el registro PIE1) a 1, va a estar disparándose siempre que no tengas nada cargado en TXREG (Que va a ser casi siempre). En general, revisa que interrupciones tienes habilitadas que puedan estar interfiriendo, si es que tienes alguna aparte de la del timer 0 y la recepción de la uart.
  Responder
#3
Hola, gracias por la respuesta, te pongo el codigo principal, omito las funciones de temporizacion o LCD.
Utilizo el compilador CC5X mas mplab.
Saludos.

Código:
#pragma chip PIC16F887

#pragma config=0b0010.0011.0010.0.100  

# pragma origin 0x04            




#pragma rambank 0
char k,K,K2,i;
char dat1,dat2,dat3,dat4;
uns16 DataFlash;
uns16 LLEGITflash;
uns16 FILA,COLUMNA,cFILA,cCOLUMNA;
bit CAL,BitVal,CAB;
char cPORTA,cPORTC;
char rep1, REP1[10],MBFrame, TempO,zk ,Benv,REP2[10],estat;
uns16 CRC, Generator,vb ,ib;
uns16 tempsRx, cambio;    
bit i800u,FiCol,REBUT,REBUT2,envio,esperaConfirm,posRep,confirmacion;
#pragma rambank 1
uns16 CARACTER[13];
char texto , lletra , start, ok;
uns16 contador,espera;
static const char mensaje1 [11] = {1,14,13,25,13,0,3,0,11,25,255}; //BON NADAL
static const char mensaje2 [11] = {25,1,14,13,25,0,13,23,25,25,255}; //BON ANY
static const char mensaje3 [11] = {25,25,25,27,35,26,30,25,25,25,255}; //2015





#pragma rambank 2


//****************************************************************************************************************************
//************************************ D E C L A R A C I Ó N    D E   F U N C I O N  E S  **************************************
//****************************************************************************************************************************
void configurar_puertos (void);

void retardo_20u();
void retardo_100m();
void retardo_500m();
void retardo_1m();
void RAM_LCD (void);
void Enviar_lcd (char linea, char columna, uns16 dato, bit bd, bit dp, bit xi);
void enviar_asinc (char dato);

//void recibir_asinc(void);
uns16 leer_FLASH (uns16 Direccio);





//**************************************************************************************************************************
//************************************************ I N T E R R U P C I O N E S ***********************************************
//****************************************************************************************************************************
    
#include "int16CXX.H"                        

interrupt captura_datos (void)                
{    
    
    int_save_registers                         // Guarda W, STATUS y PCLATH.
    char sv_FSR = FSR;  // save FSR if required
    if (T0IF)
        {
            K++; if(K>11) { K=1; K2=1;}
            FiCol=1;
            contador ++;
            espera ++;
            TMR0 = -50;
            T0IF=0;

            
        }

    if (RCIF)
        {
            rep1 = 0; tempsRx = 0; REBUT=1;
            ok = RCREG;
            nop();rep1++;
            while (!RCIF) {nop();} //||(tempsRx<64000)) {clrwdt();tempsRx ++;}
            if (RCIF)
            {
                //if(FERR)....error
                //REP1[rep1] = RCREG; // 2on byte enviat    
                    
            }
            //if(tempsRx>=64000) REP1[rep1] ='z';
            //else BIT error....
            RCIE=0;REBUT2=1;
            // ----- NETEJO REGISTRES RECEPCIO  ---------------------------
            //    CREN = 0;    nop();     CREN = 1;
        }
    FSR = sv_FSR;       // restore FSR if saved


    int_restore_registers                             // Restaura W, STATUS y PCLATH.
    
}

//*******************************************************************************************************************
//****************************************** L I B R E R Í A S   Y   C A B E C E R A S ***************************************
//*******************************************************************************************************************

#include "LCD_4bit.h"
#include "Temporiz_8Mhz.h"

//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                               #pragma codepage 0 // página 0 de códi (1ª página): Programa Principal
//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*==*=*=*=*= *

//*****************************************************************************************************************
//*****************************************  P R O G R A M A   P R I N C I P A L ***************************************
//*****************************************************************************************************************

void main (void)
{

    configurar_puertos ();  // Poso  POR  i  BOR a 1 en PCON    -----> cal inicialitzar sempre
    

    while(1)
    {

        
        enviar_asinc(129);
        retardo_1m();
        enviar_asinc(126);
        retardo_1m();
        

            
        
        
        
    }
    
}


//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                             #pragma codepage 1 // página 1 de códi (2ª página): Funció Ajust
//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

//****************************************************************************************************************************
//********************************** C Ó D I    D E   L A  F U N C I Ó   A J U S T     ************************************
//****************************************************************************************************************************

//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                           #pragma codepage 2 // página 2 de códi (3ª página): Funcions Auxiliares
//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

//****************************************************************************************************************************
//******************************* C Ó D I    D E   F U N C I O N S   A U X I L I A R S   ********************************
//****************************************************************************************************************************


void configurar_puertos (void)
{

    OSCCON       =0b.0.111.1111;     //0b.0.111.0101; // Osc Intern a 8Mhz  bit 4 - 6    

    OPTION_REG = 0b.0.1.0.0.1.000;    
    INTCON     = 0b.0110.0000;  // b5 ->  TOIE a 1 per permetre int de TIMER0,, b6 -> PEIE a 1 per permetre Int de Periferics

    PIE1 = 0b.0011.0000; // PERMISIO de INTERRUPCIO dels periferics
              // b7  n.u.   _   b6-> ADIE permet int del ADC          b5 -> RCIE permet int USART REBEN        b4 -> TXIE permet int USART EMETEN
              // b3 -> SSPIE permet int USART Sync                   b2 -> CCP1IE permet int de CCP1
              // b1 -> TMR2IE permet int de Tim2 quan = PR2      b0 -> TMR1IE int per overflow de Tim1


    PIR1 = 0; // Flags de INTERRUPCIO dels periferics de PIE1
    PIE2 = 0b.0000.0000; // PERMISIO de INTERRUPCIO de osc, comp..etc
    PIR2 = 0; // Flags de INTERRUPCIO de PIE2
    
    PCON = 0b.00.0.1.00.1.1; //nu,,nu,,WakeUP no enabled =0,, BrownOut Enabled --> 1 (ULL en Config1--> BOREN ha de ser 01,,
    //                         nu,, nu,, /POR pasa a 0 quan Power On Reset --> cal posar-lo a 1,,
    //                                    BOR pasa a 0 quan Brow Out --> cal posar-lo a 1,,
    

    ADCON0   = 0b.10.0000.0.1;      // Fosc/32,, selec entrada 0000 ,, GO =0 ,, ADON =1 --> enabled
    ADCON1   = 0b.1.0.00.0000;         // Conversion A/D: Alineación del resultado a la derecha (bits de mayor peso a cero) ,, no Vref  
    ANSEL    = 0x00;                 // Canales analógicos AN0..AN4 (bits 0..4).
    ANSELH   = 0x00;                 // Resto de pines como canales digitales (bits 0..6).
    //                                                                                // COMPARADORS i REFERENCIES per CM1CON0 ,,  CM2CON0 ,,  CM2CON1 ,, SRCON ,, VRCON ,,
    TRISA    = 0b.00.00.0000;                // PORTA --> Entrades.
    TRISB    = 0x11;                 // Sortides de moment .. Configuramos PORTB como todo entradas, excepte RB6 que es sortida
    PORTC    = 0x00;                // PORTC  --> Sortides a nivell 0
    TRISC    = 0b.0100.0000;                 // PORTC  --> Sortides
    TRISE     = 0b.0000.1000;                                // PortD a 0 elks que siguin sortida
    TRISD    = 0x00;        // Configuramos PORTD com sortida    



    
    // SPI  ,, I2C
    //======================
    // USART
    // per Emetre
    BRGH  = 1;                                // Velocidad alta.
    SPBRG = 51;                                // f = 9600 Hz para fosc = 8 MHz.
    SYNC  = 0;                                // Modo asíncrono.
    TX9   = 0;                                // Transmisión a 8 bits.
    TXIE  = 0;                                // Sin interrupciones.
    TXEN  = 1;                                // Transmisión habilitada.
    //  per Rebre
    RCIE = 1;    // 0 --> sin interrupciones,, 1 --> interrupcions    
    RX9 = 0;    //a 8 bits
    CREN = 1;    //modo recepción continua
    ADDEN = 0;
    SPEN  = 1;
    //=====================
    WDTCON = 0b.000.1011.0;  // Control WDG  ,, nu,,nu,,nu ,, 1011 --> 1/65536 ,, SWDTEN --> a 1 enable, tot i que ja hi es per Config1

    
}
// ============================


//================================================================================================================
void enviar_asinc (char dato)
{

    char i;
    while (!TRMT);
    TXREG = dato;
    retardo_1m ();    
    
                            
}
  Responder
#4
Tiene pinta de ser lo que te decía. cambia PIE1 = 0b.0011.0000; por PIE1 = 0b.0010.0000; (En configurar_puertos)

En la función de envío (eviar_asinc) ya controlas que no se intente enviar nada si no se ha enviado lo anterior ( while(!TMRT); hace justo eso: esperar a que se envíe lo que hay en TXREG si es que había algo), así que con el cambio que te digo debe bastar.
  Responder


Posibles temas similares…
Tema Autor Respuestas Vistas Último mensaje
  Reloj/cronometro PIC 16F84A axisgar 16 7,602 23-06-2020, 09:11 PM
Último mensaje: richarddamian
  [INFO+TUTO] Programador USB PIC K150 cansi22 30 38,538 08-12-2018, 02:06 PM
Último mensaje: Shellmer
  Placa de evaluación gratis pic 8 bits Jorge 24 6,851 21-11-2018, 01:11 AM
Último mensaje: Shellmer
  DUDA bootloader para pic OtreblaCU 7 3,615 29-11-2017, 04:17 PM
Último mensaje: OtreblaCU
  Iniciarse programación Pic (USB PIC K150) Kvothe 4 4,419 12-03-2017, 09:33 PM
Último mensaje: Shellmer