Embedded software Assessment 2

Dependencies:   MCP23017 SDFileSystem USBDevice WattBob_TextLCD mbed

Revision:
12:582753a4f1fb
Parent:
11:0b2801513f93
Child:
13:6094b94b3b7c
diff -r 0b2801513f93 -r 582753a4f1fb Function.h
--- a/Function.h	Fri Feb 21 10:45:29 2014 +0000
+++ b/Function.h	Fri Feb 21 11:52:48 2014 +0000
@@ -26,7 +26,8 @@
 uint8_t Error_Code;
 uint16_t Freq;
 char Temp[4];
-    
+FILE *fp;
+
 Timer FreqMsurT;
 Timer FreqTimeOut;
 Timer LogTimer;
@@ -39,13 +40,26 @@
 Ticker CallBinaryCounter;
 Ticker CallLogFile;
 
+
+void Init_LCD();
+void FreqMsur();
+void ReadDigitalin();
+void ReadAnalogin();
+void Display();
+void InputCheck();
+void BinaryCounter();
+void InitFile();
+void LogFile();
+
+/********************************************************************************
+                            Functions
+###############################################################################*/
 void Write_LCD(const char STR[],int8_t PY,int8_t PX,bool clr){
     if(clr)
         LCD.cls();
     LCD.locate(PY,PX);
     LCD.printf(STR);
 }
-
 void Init_LCD(){
     Port.write_bit(1,BL_BIT); 
     Write_LCD("Muaiyd",0,4,1);
@@ -54,7 +68,6 @@
     //LCD.cls();
 }
 
-
 /*
 Measure the frequency of a 3.3v square wave signal once every second. The frequency range
 is 500Hz to 1000Hz with 50% duty cycle). 
@@ -81,7 +94,7 @@
         }    
         FreqMsurT.stop();
         float Period=FreqMsurT.read_us();
-        Freq=1/Period*1000000.0+0.5;  //Adding 0.5 to round the frequency to nearst int
+        Freq=1/Period*1000000.0;  //Adding 0.5 to round the frequency to nearst int
     }
     else{
         Freq=0xffff; 
@@ -94,12 +107,10 @@
 }
 
 //Read TWO digital inputs every 400mS (switch_1 and switch_2) 
-
 void ReadDigitalin(){
     Swch1=Switch1;
     Swch2=Switch2;    
 }
-
 /*
 Read TWO analogue inputs every 800mS (Analogue_in_1 at pin 19
 and Analogue_in_2 at pin 20). Also, averaging the last 4 readings
@@ -155,7 +166,6 @@
     sprintf(Temp, "%d", Error_Code);
     Write_LCD(Temp,0,15,0);
 }
-
 void InputCheck(){
     if(Swch1&&(Analug1_valu[4]>Analug2_valu[4])){
         Error_Code=3;
@@ -181,18 +191,16 @@
          Bin=0x00;
     }         
 }
-
-void LogFile(){
-    char* Frq;
-    printf("Hello World!\n");   
- 
-    mkdir("/sd/mydir", 0777);
-    
-    FILE *fp = fopen("/sd/mydir/sdtest.txt", "a");
+void InitFile(){
+    fp = fopen( "/sd/LogDir/sdtest.txt" , "a");
     if(fp == NULL) {
         error("Could not open file for write\n");
-    }
-    Freq=999;
+    } 
+    fclose(fp);  
+}
+void LogFile(){
+    char* Frq; 
+    fp = fopen("/sd/LogDir/sdtest.txt", "a");  
     if( Freq<1200 && Freq>400){
         sprintf(Temp, "%d", Freq); 
         Frq = Temp;
@@ -208,6 +216,5 @@
     fprintf(fp," %d",Analug2_valu[4]);
     fprintf(fp," %s","\r\n");
     fclose(fp); 
- 
     printf("Goodbye World!\n");    
 }
\ No newline at end of file