Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

read text file in a SD card line by line and display those strings on LCD one by one

Status
Not open for further replies.

akhs

Newbie level 6
Joined
Nov 9, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
i want is to read line by line in a text file of a SD card and display those strings one by one on a LCD display.

first i tried to display strings in 2 lines separately but i was unable to do it,the below code what i developed is only display the 2nd line string........

Code:
// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

// SD module connections
sbit Mmc_Chip_Select           at LATC0_bit;  // for writing to output pin always use latch (PIC18 family)
sbit Mmc_Chip_Select_Direction at TRISC0_bit;
// End SD module connections

unsigned long  i,k, size;
char           filename[14] = "ASML.TXT";          // File names
char character[]="";





void main(){

ADCON1 |= 0x0D;             // Configure AN0 and AN1 pins as analog
CMCON  |= 7;                // coparators off

TRISB = 0x00;               //PORTB output
Delay_ms(100);

//Initialize LCD
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF );
Lcd_Out(1, 1, "Status:");
Lcd_Cmd(_LCD_SECOND_ROW);


// Initialize SPI1 module
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);

// use fat16 quick format instead of init routine if a formatting is needed
if (Mmc_Fat_Init() == 0) {

// reinitialize spi at higher speed
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);


//error = Mmc_Fat_Assign(&filename, 0);
Mmc_Fat_Assign(&filename, 0);

Mmc_Fat_Reset(&size);            // To read file, procedure returns size of file

for (i = 1; i <= size; i++) {
Mmc_Fat_Read(&character);

}

while(character[k]!='\r')   //break when find "\r"
k++;
k++;
k++;

Lcd_Out(2,1,&character[k]);



}else{
//Lcd_Cmd(_LCD_CLEAR);
//Lcd_Cmd(_LCD_CURSOR_OFF );
//Lcd_Out(1,2,"MMC init not OK");

}

}

in here i used character of "\r" carriage return to separately identify the two strings, but i can not display the string in the first line and display the 2nd line string at next
thank you.........
 

Why are you incrementime k 3 times in the while loop for every check.. That way you will miss some chars. i.e., some chars will not be checked. Just use one k++ in the while loop. Actully it displays so fast that you are seeing only the end of the string read. insert a delay after displaying

Change
Code:
 char character[]="";
to
Code:
 char character[512]="";

use a counter to count 0 to 15 inside the while loop and whenever the counter becomes 15 display read characters on lcd and give a delay of 1 sec and then reset the counter to 0 and repeat the process.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top