//Memory Card Chip Select Connection
sfr sbit Mmc_Chip_Select at RB2_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISB2_bit;
unsigned char filename[] = "vivek.txt";
unsigned char error;
unsigned int temp;
double adc_value,voltage;
unsigned char tagline[] = " hello i am vivek using mikro c ";
unsigned char voltage_Log[7];
void main()
{
unsigned char ones,point_ones,point_hundreds,newline='\r\n';
TRISD =0x00;
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);
error = MMC_Init();
while(error == 1)
{
LATD=0xff;
error = MMC_Init();
}
LATD =0x00;
MMC_Fat_Init();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
Mmc_Fat_Assign(&filename,0x80);
while(1)
{
adc_value = ADC_Read(0); //Read Temperature from ADC
voltage=adc_value*5/1023;
ones = voltage/1;
ones = ones | 0x30;
temp=voltage*10;
point_ones = temp%10;
point_ones = point_ones | 0x30;
temp=voltage*100;
point_hundreds = temp%10;
point_hundreds = point_hundreds | 0x30;
voltage_Log[0] = ones;
voltage_Log[1] = '.';
voltage_Log[2] = point_ones;
voltage_Log[3] = point_hundreds;
voltage_Log[4] = 'V';
voltage_Log[5] = '\r';
voltage_Log[6] = '\n';
Mmc_Fat_Append();
//Mmc_Fat_Write(tagline,sizeof(tagline));
Mmc_Fat_Write(voltage_Log,sizeof(voltage_Log));
}
}