Tareq Domi
Junior Member level 2
- Joined
- Nov 16, 2014
- Messages
- 22
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 167
well , i used this method and wrote a text file on the sd card in proteus ( simulation ) , but when i came into the real hardware nothing works :/
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 //MMC module connections sfr sbit Mmc_Chip_Select at LATC0_bit; sfr sbit Mmc_Chip_Select_Direction at TRISC0_bit; // MMC module connections // LCD configiration sbit LCD_RS at LATD4_bit; sbit LCD_EN at LATD5_bit; sbit LCD_D7 at LATD3_bit; sbit LCD_D6 at LATD2_bit; sbit LCD_D5 at LATD1_bit; sbit LCD_D4 at LATD0_bit; sbit LCD_RS_Direction at TRISD4_bit; sbit LCD_EN_Direction at TRISD5_bit; sbit LCD_D7_Direction at TRISD3_bit; sbit LCD_D6_Direction at TRISD2_bit; sbit LCD_D5_Direction at TRISD1_bit; sbit LCD_D4_Direction at TRISD0_bit; //
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 //MMC module connections sbit Mmc_Chip_Select at LATC0_bit; sbit Mmc_Chip_Select_Direction at TRISC0_bit; // MMC module connections // LCD configiration sbit LCD_RS at LATB4_bit; sbit LCD_EN at LATB5_bit; sbit LCD_D7 at LATB3_bit; sbit LCD_D6 at LATB2_bit; sbit LCD_D5 at LATB1_bit; sbit LCD_D4 at LATB0_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D7_Direction at TRISB3_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D4_Direction at TRISB0_bit; // unsigned int error1 , error2 ; char filename[] = "myFile.txt" ; unsigned char txt[] = "This is a test string\r\n" ; char mmc_fat_label[] = "FAT16FORMAT"; void main() { ANSELA = 0x00; ANSELB = 0x00; ANSELC = 0x00; ANSELD = 0x00; ANSELE = 0x00; CM1CON0 = 0x00; CM2CON0 = 0x00; TRISA = 0xFF; TRISB = 0x00; TRISC = 0xC0; TRISD = 0xC0; TRISE = 0x08; UART1_Init(9600); Delay_ms(200); UART_Write_Text("UART OK\r\n"); Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,"Hello"); // on first row Delay_ms(500); LATD = 0xFF ; Lcd_Out(2,1,"PORTD ON"); // on second row Delay_ms(1000); SPI1_Init(); SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); UART_Write_Text("SPI Slow OK...\r\n"); error1 = MMC_Init(); while(error1 == 1) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"CARD NOT FOUND"); Lcd_Out(2,1,"Insert the CARD"); UART_Write_Text("Card Not Found...\r\n"); error1 = MMC_Init(); Delay_ms(2000); } UART_Write_Text("asdfgf...\r\n"); error1 = 2; while(error1 != 0) { error1 = Mmc_Fat_QuickFormat(&mmc_fat_label); if (error1 == 0) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Initialization"); Lcd_Out(2,1,"Succeed"); UART_Write_Text("SD Card Formatted and Initialized...\r\n"); } else if(error1 == 1) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Initialization"); Lcd_Out(2,1,"Failed"); UART_Write_Text("Initialization Failed...\r\n"); } else if(error1 = 0xFF) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"SD Card not"); Lcd_Out(2,1,"detected"); UART_Write_Text("SD Card not detected...\r\n"); } Delay_ms(2000); } error2 = 2; while(error2 != 0) { error2 = Mmc_Fat_init(); if (error2 == 0) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Initialization"); Lcd_Out(2,1,"Succeed"); UART_Write_Text("SD Card Formatted and Initialized...\r\n"); } else if(error2 == 1) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Boot Sector"); Lcd_Out(2,1,"not found"); UART_Write_Text("Boot Sector not found...\r\n"); } else if(error2 = 0xFF) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"SD Card not"); Lcd_Out(2,1,"detected"); UART_Write_Text("SD Card not detected...\r\n"); } Delay_ms(2000); } if(error2 == 0) { SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); Mmc_Fat_Assign(filename, 0x80); MMc_Fat_rewrite(); MMc_Fat_Write(txt , 8) ; Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Writing on SD OK"); UART_Write_Text("Writing on SD Card OK...\r\n"); } UART_Write_Text("All Done\r\n"); while(1) { ; } }
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 //MMC module connections sbit Mmc_Chip_Select at LATC0_bit; sbit Mmc_Chip_Select_Direction at TRISC0_bit; // MMC module connections // LCD configiration sbit LCD_RS at LATB4_bit; sbit LCD_EN at LATB5_bit; sbit LCD_D7 at LATB3_bit; sbit LCD_D6 at LATB2_bit; sbit LCD_D5 at LATB1_bit; sbit LCD_D4 at LATB0_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D7_Direction at TRISB3_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D4_Direction at TRISB0_bit; // unsigned int error1 , error2 ; char filename[] = "myFile.txt" ; unsigned char txt[] = "This is a SD Card Test\r\n" ; char mmc_fat_label[] = "FAT16FORMAT"; void main() { ANSELA = 0x00; ANSELB = 0x00; ANSELC = 0x00; ANSELD = 0x00; ANSELE = 0x00; CM1CON0 = 0x00; CM2CON0 = 0x00; TRISA = 0xFF; TRISB = 0x00; TRISC = 0xC0; TRISD = 0xC0; TRISE = 0x08; UART1_Init(9600); Delay_ms(200); UART_Write_Text("UART OK\r\n"); Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,"Hello"); // on first row Delay_ms(500); LATD = 0xFF ; Lcd_Out(2,1,"PORTD ON"); // on second row Delay_ms(1000); SPI1_Init(); SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); UART_Write_Text("SPI Slow OK...\r\n"); error1 = MMC_Init(); while(error1 == 1) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"CARD NOT FOUND"); Lcd_Out(2,1,"Insert the CARD"); UART_Write_Text("Card Not Found...\r\n"); error1 = MMC_Init(); Delay_ms(2000); } UART_Write_Text("asdfgf...\r\n"); error1 = 2; while(error1 != 0) { error1 = Mmc_Fat_QuickFormat(&mmc_fat_label); if (error1 == 0) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Initialization"); Lcd_Out(2,1,"Succeed"); UART_Write_Text("SD Card Formatted and Initialized...\r\n"); } else if(error1 == 1) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Initialization"); Lcd_Out(2,1,"Failed"); UART_Write_Text("Initialization Failed...\r\n"); } else if(error1 = 0xFF) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"SD Card not"); Lcd_Out(2,1,"detected"); UART_Write_Text("SD Card not detected...\r\n"); } Delay_ms(2000); } error2 = 2; while(error2 != 0) { error2 = Mmc_Fat_init(); if (error2 == 0) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Initialization"); Lcd_Out(2,1,"Succeed"); UART_Write_Text("SD Card Formatted and Initialized...\r\n"); } else if(error2 == 1) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Boot Sector"); Lcd_Out(2,1,"not found"); UART_Write_Text("Boot Sector not found...\r\n"); } else if(error2 = 0xFF) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"SD Card not"); Lcd_Out(2,1,"detected"); UART_Write_Text("SD Card not detected...\r\n"); } Delay_ms(2000); } if(error2 == 0) { SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); Mmc_Fat_Assign(filename, 0x80); MMc_Fat_rewrite(); MMc_Fat_Write(txt , strlen(txt)) ; Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Writing on SD OK"); UART_Write_Text("Writing on SD Card OK...\r\n"); } UART_Write_Text("All Done\r\n"); while(1) { ; } }
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?