Amigos Tengo un Inconveniente con el código...
Estoy realizando pruebas de interrupciones y ese tipo de cosas para luego hacer el almacenamiento de datos en la mmc/sd
Estoy usando MikroC_dsPIC V5.1 debido a que actualmente es la que me proporciona las librerías más sencillas para el almacenamiento de datos en la MMC/SD
El Inconveniente presentado es cuando se están configurado el ADC, El Timer y la MMC/SD
El mismo cuando finaliza de configurar automáticamente vuelve a hacerlo es decir se configura 2 veces antes de empezar a realizar las acciones...
Voy a explicarlo mejor....
Aquí está el código
sbit LCD_RS at LATB5_bit;
sbit LCD_EN at LATB4_bit;
sbit LCD_D4 at LATB3_bit;
sbit LCD_D5 at LATB2_bit;
sbit LCD_D6 at LATB1_bit;
sbit LCD_D7 at LATB0_bit;
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;
sbit Mmc_Chip_Select at LATF0_bit;
sbit Mmc_Chip_Select_Direction at TRISF0_bit;
char filename[14] = "OPE00X.TXT";
const LINE_LEN = 43;
char file_contents[LINE_LEN] = "XX MMC/SD FAT16 library by Anton Rieckertn";
unsigned short loop, loop2;
unsigned long i, size;
char Buffer[512];
char VALOR;
void BORRAR (){
Lcd_Cmd(_LCD_CLEAR);
}
void CONF_ADC(){
Lcd_Out(1,1,"CONF. ADC");
Delay_MS(750);
ADPCFG = 0xFBFF;
ADCHS = 0x000A;
ADCSSL = 0x0400;
ADCON1 = 0x8046;
ADCON2 = 0x0000;
ADCON3 = 0x011A;
BORRAR();
}
void CONF_TIM(){
Lcd_Out(1,1,"CONF. INT");
DELAY_MS(750);
SR = 0x0000;
CORCON = 0x0000;
INTCON1 = 0x0000;
INTCON2 = 0x0000;
IFS0 = 0x0000; // BANDERA DE INTERRUPCIONES, TM3, ADIF, ADIF
IFS1 = 0x0000;
IFS2 = 0x0000;
IEC0 = 0x0880; // ADC, TIMER3 Interrupt Enable
IEC1 = 0x0000;
IEC2 = 0x0000;
IPC0 = 0x1000;
IPC1 = 0x0000;
IPC2 = 0x1000;
IPC3 = 0x0000;
IPC4 = 0x0000;
IPC5 = 0x0000;
IPC6 = 0x0000;
T3CON = 0x8030;
TMR3 = 0;
PR3 = 39062;
BORRAR();
}
void CONF_MMC(){
Lcd_Out(1,1,"CONF. MMC/SD");
DELAY_MS(750);
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_64,
_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
if (!Mmc_Fat_Init()) {
SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_4,
_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
Lcd_Out(1,1,"MMC/SD CONEXT");
DELAY_MS(750);
BORRAR();
}
else {
Lcd_Out(1,1,"MMC/SD DESCONEXT");
DELAY_MS(750);
BORRAR();
}
BORRAR();
}
void NEW_FILE(){
filename[5] = 'A';
Mmc_Fat_Set_File_Date(2005,6,21,10,35,0);
Mmc_Fat_Assign(&filename, 0xA0);
Mmc_Fat_Rewrite();
Lcd_Out(1,1,"ARCHIVO CREADO");
DELAY_MS(750);
BORRAR();
for(loop = 1; loop <= 99; loop++) {
file_contents[0] = loop / 10 + 48;
file_contents[1] = loop % 10 + 48;
Mmc_Fat_Write(file_contents, LINE_LEN-1); // write data to the assigned file
}
Lcd_Out(1,1,"Fin de Escritura");
DELAY_MS(750);
BORRAR();
}
void ADC1Int() org 0x2A {
VALOR = ADCBUF0;
LATD = ~PORTD;
/* filename[5] = 'A';
Mmc_Fat_Assign(&filename, 0xA0);
Mmc_Fat_Write(VALOR, LINE_LEN-1);
Lcd_Out(1,1,"Fin de Escritura");*/
IFS0 = 0x0000; // Limpia las Banderas.
}
void CONFIG (){
Lcd_Out(1,1,"CONFIGURACION");
DELAY_MS(1000);
BORRAR();
CONF_MMC();
NEW_FILE();
CONF_ADC();
CONF_TIM();
}
void main() {
TRISB = 0xFFFF;
TRISD = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
CONFIG();
while(1);
}
El Entra en el siguiente ciclo...
CONF_MMC();
NEW_FILE();
CONF_ADC();
CONF_TIM();
Configura la MMC, Crea un archivo nuevo y graba dentro del mismo, Luego configura el ADC y por Ultimo configura las Interrupciones...
Ahora todo esto lo estoy visualizando en la LCD 16x2 y la misma me muestra que cuando termina de configurar el timer vuelve otra vez a configurar la MMC y todo de nuevo...
Al Final cuando lo hace 2 veces es que se queda esperando las interrupciones que genera el adc por el desbordamiento del TIMER 3
Si Alguien me pudiera ayudar a ver que estoy haciendo mal se lo agradecería.