davenjose
Newbie level 4
- Joined
- Feb 12, 2008
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,322
char
faterror[20] = "FAT16 not found",
filecontents[50] = "XX MMC/SD FAT16 library by Anton Rieckert\n";
//char filename[14] = "MIKRO00.TXT"; // File names
unsigned short tmp, charecter, loop;
unsigned long i, size;
void main()
{
PORTB = 0;
TRISB = 0;
trisd=0x00; ;
portd=0x00;
Usart_Init(9600);
Delay_100ms();
// portd=0xff;
Delay_ms(3000);
Spi_Init_Advanced(MASTER_OSC_DIV64, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
// Spi_Init();
Mmc_Init(&portC,2);
// use fat16 quick format instead of init routine if a formatting is needed
while ((Mmc_Fat_Init(&PORTC, 2)!=0))
{
tmp=0;
while(faterror[tmp])
Usart_Write(faterror[tmp++]);
portd=0x0f;
// Mmc_Fat_Assign("mikroc.txt",0x80);
Delay_ms(1000);
portd=0x00;
}
for(loop=1;loop<=5;loop++)
{
Spi_Init_Advanced(MASTER_OSC_DIV4, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
filename[7]=loop+64;
portd=0xff;
Delay_ms(1000);
// Mmc_Fat_QuickFormat(&portc,2,"MIKRO00.TXT");
Mmc_Fat_Assign("mikroc.txt",0x80);
Mmc_Fat_Rewrite();
filecontents[0]=loop/10 +48;
filecontents[1]=loop%10 +48;
Mmc_Fat_Write(filecontents,41);
Mmc_Fat_Append();
Mmc_Fat_Write(filecontents,41);
portd=0x00;
Delay_ms(200);
}
for(loop=1;loop<=5;loop++)
{
filename[7]=loop+64;
portd=0xff;
Delay_ms(1000);
Mmc_Fat_Assign("mikroc.txt",0xA0);
portd=0x00;
Mmc_Fat_Append();
Mmc_Fat_Set_File_Date(2010,5,8,10,loop,0);
Mmc_Fat_Write("mikroc electronica 2010\r\n",30);
Mmc_Fat_Append();
Mmc_Fat_Write(filecontents,41);
Mmc_Fat_Reset(&size);
for(i=0;i<=size;i++)
{
Mmc_Fat_Read(&charecter);
Usart_Write(charecter);
}
Delay_ms(200);
}
}
If you have any doubt you can ask me.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 char faterror[20] = "FAT16 not found", filecontents[50] = "XX MMC/SD FAT16 library by Anton Rieckert\n"; char filename[14] = "MIKRO00.TXT"; // File names unsigned short tmp, charecter, loop; unsigned long i, size; void main() { PORTB = 0; TRISB = 0; trisd=0x00; ; portd=0x00; Usart_Init(9600); Delay_100ms(); // portd=0xff; Delay_ms(3000); Spi_Init_Advanced(MASTER_OSC_DIV64, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH); // Spi_Init(); Mmc_Init(&portC,2); // use fat16 quick format instead of init routine if a formatting is needed while ((Mmc_Fat_Init(&PORTC, 2)!=0)) { tmp=0; while(faterror[tmp]) Usart_Write(faterror[tmp++]); portd=0x0f; // Mmc_Fat_Assign("mikroc.txt",0x80); Delay_ms(1000); portd=0x00; } for(loop=1;loop<=5;loop++) { Spi_Init_Advanced(MASTER_OSC_DIV4, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH); filename[7]=loop+64; portd=0xff; Delay_ms(1000); // Mmc_Fat_QuickFormat(&portc,2,"MIKRO00.TXT"); Mmc_Fat_Assign("mikroc.txt",0x80); Mmc_Fat_Rewrite(); filecontents[0]=loop/10 +48; filecontents[1]=loop%10 +48; Mmc_Fat_Write(filecontents,41); Mmc_Fat_Append(); Mmc_Fat_Write(filecontents,41); portd=0x00; Delay_ms(200); } for(loop=1;loop<=5;loop++) { filename[7]=loop+64; portd=0xff; Delay_ms(1000); Mmc_Fat_Assign("mikroc.txt",0xA0); portd=0x00; Mmc_Fat_Append(); Mmc_Fat_Set_File_Date(2010,5,8,10,loop,0); Mmc_Fat_Write("mikroc electronica 2010\r\n",30); Mmc_Fat_Append(); Mmc_Fat_Write(filecontents,41); Mmc_Fat_Reset(&size); for(i=0;i<=size;i++) { Mmc_Fat_Read(&charecter); Usart_Write(charecter); } Delay_ms(200); } }
Code C - [expand] 1 unsigned char Mmc_Init(unsigned short *port, unsigned short pin);
#define BUFFER_SIZE 15
//Memory Card Chip Select Connection
sfr sbit Mmc_Chip_Select at RB2_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISB2_bit;
//
// LCD module connections
sbit LCD_RS at RD0_bit;
sbit LCD_RW at RD1_bit;
sbit LCD_EN at RD2_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD2_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
unsigned char filename[] = "Temp.TXT";
unsigned char error;
unsigned char i;
unsigned int adc_value;
unsigned char Temperature_Log[BUFFER_SIZE];
void main()
{
unsigned char ones,tens,hundreds;
unsigned int temp;
TRISD = 0x00;
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Delay_ms(100);
Lcd_Out(1,1," TEMP. RECORDER");
Lcd_Out(2,1," BY HEMNATH ");
Delay_ms(1000);
ADCON0 = 0b00000001; //A/D Converter Power Up
ADCON1 = 0x00; //All Analog Channels
ADCON2 = 0b10111110; //Right Justfied and Slowest Clock for better accuracy
ADC_Init();
SPI1_Init();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
Delay_us(10);
error = MMC_Init();
while(error == 1)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1," CARD NOT FOUND");
error = MMC_Init();
}
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1," CARD DETECTED!");
Lcd_Out(2,1,"CARD INITIALIZED");
Delay_ms(1000);
MMC_Fat_Init();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
Mmc_Fat_Delete();
Mmc_Fat_Assign(&filename,0xA0);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"TEMPERATURE:");
while(1)
{
adc_value = ADC_Read(0); //Read Temperature from ADC
adc_value = adc_value*488;
adc_value = adc_value/10;
temp = adc_value/100;
Temperature_Log[0] = 'T';
Temperature_Log[1] = 'E';
Temperature_Log[2] = 'M';
Temperature_Log[3] = 'P';
Temperature_Log[4] = '=';
ones = temp%10;
temp = temp/10;
tens = temp%10;
temp = temp/10;
hundreds = temp%10;
ones = ones|0x30;
tens = tens|0x30;
hundreds = hundreds|0x30;
Temperature_Log[5] = hundreds;
Temperature_Log[6] = tens;
Temperature_Log[7] = ones;
Temperature_Log[8] = '.';
Lcd_Chr(2,1,hundreds);
Lcd_Chr(2,2,tens);
Lcd_Chr(2,3,ones);
ones = adc_value%10;
adc_value = adc_value/10;
tens = adc_value%10;
ones = ones|0x30;
tens = tens|0x30;
Temperature_Log[9] = tens;
Temperature_Log[10] = ones;
Temperature_Log[11] = ' ';
Temperature_Log[12] = 'C';
Temperature_Log[13] = '\r';
Temperature_Log[14] = '\n';
Lcd_Chr(2,4,'.');
Lcd_Chr(2,5,tens);
Lcd_Chr(2,6,ones);
Lcd_Chr(2,7,223);
Lcd_Chr(2,8,'C');
Mmc_Fat_Append();
Mmc_Fat_Write(Temperature_Log,15);
Delay_ms(300);
}
}
It works good. and I have tested in proteus. Not in hardware.
I believe that most people using mikroC do it for the comfort of the built-in libraries. On the other hand, it's a full featured C compiler, you are free to use other libraries, e.g. popular FATFS.With MikroC ,we must trust with a complete library without to know details
and if it doesn't work .. we are "Chocolat " ( What about to do ?)
I believe that most people using mikroC do it for the comfort of the built-in libraries
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?