CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

MMC with 18F452
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 10, 2012 1:20 am     Reply with quote

Icarus wrote:
Hey ckielstra, I am using the version 4.057 .
V4.057 is one of the earlier v4.0xx compiler versions and full of bugs. Only around v4.075 the compiler started to work for most applications. Upgrade to a newer version, preferably v4.090 or higher.

Quote:
Should I send byte by byte each value of ADC ?
I don't understand the question. In computers you are always sending byte by byte.
Icarus



Joined: 02 May 2012
Posts: 16

View user's profile Send private message

PostPosted: Thu May 10, 2012 6:23 am     Reply with quote

Am using DS1302 in my project, I want to attach to each ADC value the real time in each the value was taken. Release them in excel file for example in the end.
temtronic



Joined: 01 Jul 2010
Posts: 9269
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu May 10, 2012 6:51 pm     Reply with quote

I suggest you get the ADC and RTC sections of code working as you want to, sending the data to a PC terminal program in CSV format.
That way you KNOW the data is correct, your program code is good..THEN..simply add a couple lines of code to save that data to your MMC/SD card.
Icarus



Joined: 02 May 2012
Posts: 16

View user's profile Send private message

PostPosted: Tue May 15, 2012 2:53 pm     Reply with quote

Am blocked there, how to do it ..
temtronic



Joined: 01 Jul 2010
Posts: 9269
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue May 15, 2012 3:22 pm     Reply with quote

CCS kindly supplies LOTS of examples in the 'examples' folder as well they have quite a few 'drivers' as well.
Icarus



Joined: 02 May 2012
Posts: 16

View user's profile Send private message

PostPosted: Tue May 15, 2012 3:31 pm     Reply with quote

I've tried 'ex_mmcsd' but no result !
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue May 15, 2012 8:55 pm     Reply with quote

Hi Icarus,

You've got to do something, anything really, in real hardware before anyone is going to take you seriously, and offer you anymore help. This is a forum for people that write their own code, and need an occasional hand, not for people that need code spoon fed to them.

Show us some real hardware that blinks an LED, or sends a serial message to a PC, and then we'll talk.

Good Luck!

John
Icarus



Joined: 02 May 2012
Posts: 16

View user's profile Send private message

PostPosted: Wed May 16, 2012 4:28 pm     Reply with quote

Sorry ezflyr, am writing my own code and am not waiting for someone to write it for me. It would miss something, or having a trouble. I compile it on CCS and it doesn't show any error. But on proteus I can't see nothing on LCD.
Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#include <fat.c>
#include <mmcsd.c>

#include <Math.h>
#include <ds1302.c>
#include <lcd.c>
#include <kbd.c>
#include <string.h>
#use fast_io(c)

 //enable_interrupts(INT_ADC);
 
int conv;
float valeur;
char *mesure;

int get_number() {  char first,second;
  do {
    first=kbd_getc();
  } while ((first<'0') || (first>'9'));
  lcd_putc(first);
  first-='0';

  do {
    second=kbd_getc();
  } while ((second<'0') || (second>'9'));
  lcd_putc(second);
  second-='0';

  return((first*10)+second);
}

void set_clock(){
   int day,mth,year,dow,hour,min;

   lcd_putc("\fYear 20: ");
   year=get_number();
   lcd_putc("\fMonth: ");
   mth=get_number();
   lcd_putc("\fDay: ");
   day=get_number();
   lcd_putc("\fWeekday 1-7: ");
   dow=get_number();
   lcd_putc("\fHour: ");
   hour=get_number();
   lcd_putc("\fMin: ");
   min=get_number();

   rtc_set_datetime(day,mth,year,dow,hour,min);
}

// gestion de fichier

void MakeFile(char *fileName)
{
   printf("\r\nMaking file '%s': ", fileName);
   if(mk_file(fileName) != GOODEC)
   {
      printf("Error creating file");
      return;
   }
   printf("OK");
}

void AppendFile(char *fileName, char *appendString)
{
   FILE stream;
   
   char *mode1,*mode2;
   mode1[1]="a";
   mode2="\r\n";
   
   printf("\r\nAppending '%s' to '%s': ", appendString, fileName);
   if(fatopen(fileName, mode1, &stream) != GOODEC)
   {
      printf("Error opening file");
      return;
   }
   
   fatputs(appendString, &stream);
   fatputs(mode2, &stream);

   if(fatclose(&stream) != GOODEC)
   {
      printf("Error closing file");
      return;
   }
   printf("OK");
}

// fin gestion de fichier

void main() {
   char cmd;
   int day,mth,year,dow,hour,min,sec;
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(ALL_ANALOG);

   rtc_init();
   lcd_init();
   kbd_init();
   mmcsd_init();
   
   lcd_putc("\f1: Changer, 2: Afficher");
   
   do {
      cmd=kbd_getc();
   }
   
   while ((cmd!='1')&&(cmd!='2'));

   if(cmd=='1')
     set_clock();

   while (1) {
      lcd_putc('\f');
      rtc_get_date( day, mth, year, dow);
      rtc_get_time( hour, min, sec );
      printf(lcd_putc,"%2u/%2u/%2u\n%2u:%2u:%2u",mth,day,year,hour,min,sec);
      delay_ms(250);
   }
   
MakeFile(*mesure);

 while (1) {
     conv=read_adc();
     valeur=0.46875*conv+130;
     
      lcd_putc('\f');
      rtc_get_date( day, mth, year, dow);
      rtc_get_time( hour, min, sec );
      printf(lcd_putc,"%2u:%2u:%2u\n\n%f%2s",hour,min,sec,valeur," Volts");
     delay_ms(250);
            if (INT_AD)
         {
         AppendFile(*mesure,year);
         AppendFile(*mesure,mth);
         AppendFile(*mesure,day);
         AppendFile(*mesure,hour);
         AppendFile(*mesure,min);
         AppendFile(*mesure,sec);
         AppendFile(*mesure,valeur);
         }
 }
 
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed May 16, 2012 4:49 pm     Reply with quote

KISS: Keep It Simple, Stupid

Your program is now doing too many things which makes debugging more difficult.
If one thing is not working, then create a tiny program to do just that one thing. This helps you to get focus and makes the chances better that you only have to solve a single error instead of perhaps multiple errors at the same time which is way more difficult.

Just looking quickly at your code a few huge errors stand out:
- Your call to makefile has an uninitialized pointer. Without file name how would you expect a file to be created?
- AppendFile expects a string as input. You give it an integer.
-
Code:
mode1[1]="a";
Ouch... mode1 is not an array with two members. You are here writing to undefined memory and corrupting data.
-
Code:
MakeFile(*mesure);
I'm surprised the compiler doesn't give a warning on this. What does the '*' character mean when you use it like this?

Last edited by ckielstra on Wed May 16, 2012 4:59 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 16, 2012 4:59 pm     Reply with quote

In addition to that, here are some more things wrong:
Quote:

char *mode1,*mode2;
mode2="\r\n";

For mode2, you have only created a char pointer. Then you have
loaded the pointer with a carriage return and linefeed. You
actually want to declare mode2 as an array of 3 bytes.

What you really want to do, is this:
Code:

char mode1[] = "a";
char mode2[] ="\r\n";

This creates two arrays to hold your strings. It lets the compiler set
the size of the array (which it will do correctly).


Quote:
if (INT_AD)

INT_AD is a constant value. Look in 18F452.h to see what it is.
Because it's a constant, the if() statement will always be true.
To see how to do what you actually want, read this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=47828
Also note that you need to clear the interrupt after you determine
that it's active.

However, it's not clear why you are doing this in your program, because
calling read_adc() will set the INT_AD flag. You already called the
read_adc() function and got the byte. Why check for the A/D interrupt ?
You already have the data. The read_adc() function waits until the
data is ready. You got it.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed May 16, 2012 8:07 pm     Reply with quote

Hi All,

I think Icarus is just finding code here and there and cobbling it together to try to make something work. I don't think he really has any clue what the code is doing. Even after all the code is cleaned up, this is still a Proteus project, not a real hardware project, so I think you guys are ultimately just wasting your time.

John
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group