Cf again

General discussion on mikroC.
Post Reply
Author
Message
bassin
Posts: 5
Joined: 17 Jun 2005 14:38

Cf again

#1 Post by bassin » 23 Jun 2005 16:11

Hi, I'm developing a CF example the code its this:

Code: Select all

unsigned i;
char size;


void initcf(){
Cf_Init(&PORTB,&PORTD);
while(Cf_Detect()==0)
    {
     LCD_Out(1,1, "Insert CF");
    }
 LCD_Out(1,1, "CF Inserted");
 Delay_ms(2000);
}

void filew (){
 i = 0;
 Delay_ms(1000);
 Cf_Write_Init(590, 1);
 for (i = 0; i < 512; i++) {
    Cf_Write_Byte(i + 33);  }


 Lcd_Cmd(Lcd_CLEAR);
 i=0;
 LCD_Out(1,1, "Start READ");
 Delay_ms(1000);
 Cf_Read_Init(590, 1);
 for (i = 0; i < 512; i++) {
    size = Cf_Read_Byte();
    LCD_Out(1,1, size);
    Delay_ms(500);
  }
}

When I wait for the read command it returns some garbage and them the program freeze. Some ideas? I verify the hardware dozen thimes and it's correct.

bassin
Posts: 5
Joined: 17 Jun 2005 14:38

OOPS

#2 Post by bassin » 23 Jun 2005 16:25

:oops: opps I forgot a piece of the code,
here is the correct one

Code: Select all

unsigned i;
char size;


void initcf(){
Cf_Init(&PORTB,&PORTD);
while(Cf_Detect()==0)
    {
     LCD_Out(1,1, "Insert CF");
    }
 LCD_Out(1,1, "CF Inserted");
 Delay_ms(2000);
}

void filew (){
 i = 0;
 Delay_ms(1000);
 Cf_Write_Init(590, 1);
 for (i = 0; i < 512; i++) {
    Cf_Write_Byte(i + 33);  }


 Lcd_Cmd(Lcd_CLEAR);
 i=0;
 LCD_Out(1,1, "Start READ");
 Delay_ms(1000);
 Cf_Read_Init(590, 1);
 for (i = 0; i < 512; i++) {
    size = Cf_Read_Byte();
    LCD_Out(1,1, size);
    Delay_ms(500);
  }
}



void main() {
TRISC=0;
Lcd_Init(&PORTC);         // Initialize LCD connected to PORTC
Lcd_Cmd(Lcd_CLEAR);       // Clear display
initcf();
filew();
LCD_Out(1,1,"ok");
while(1);
}

pizon
mikroElektronika team
Posts: 823
Joined: 11 Oct 2004 08:53

Re: OOPS

#3 Post by pizon » 25 Jun 2005 16:53

Code: Select all

 size = Cf_Read_Byte();
    LCD_Out(1,1, size);
puts a non-ASCII variable size directly to LCD. You must do

Code: Select all

unsigned i;
char size;
char cfrd[5];     // <---this

void initcf(){
Cf_Init(&PORTC,&PORTD);
while(Cf_Detect()==0)
    {
     LCD_Out(1,1, "Insert CF");
    }
 LCD_Out(1,1, "CF Inserted");
 Delay_ms(2000);
}//~

void filew () {
 i = 0;
 Delay_ms(1000);
 Cf_Write_Init(590, 1);
 for (i = 0; i < 512; i++) {
    Cf_Write_Byte(i + 33);  }


 Lcd_Cmd(LCD_CLEAR);
 i=0;
 LCD_Out(1,1, "Start READ");
 Delay_ms(1000);
 Cf_Read_Init(590, 1);
 for (i = 0; i < 512; i++) {
    size = Cf_Read_Byte();
    ByteToStr(size, cfrd);     // <-- this
    LCD_Out(1,1, cfrd);     // <-- this
    Delay_ms(500);
  }
}//~



void main() {
  Lcd_Init(&PORTB);         // Initialize LCD connected to PORTC
  Lcd_Cmd(LCD_CLEAR);       // Clear display
  initcf();
  filew();
  LCD_Out(1,1,"ok");
}//~!
I altered PORTB and PORTC roles to have a more convenient wiring.
pizon

Post Reply

Return to “mikroC General”