From b7a73ecab0b7cf22d9d322e60cac067662ed3465 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Thu, 6 Nov 2014 19:53:09 +0100 Subject: Added explaining comments to code --- .gitattributes | 1 + .gitignore | 31 ++++++++++++++++++++++++++++++- Tacho_screen.atsuo | Bin 2560 -> 2560 bytes Tacho_screen.c | 43 +++++++++++++++++++++++-------------------- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/.gitattributes b/.gitattributes index 157cc39..2dd9c86 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,6 +9,7 @@ *.fsproj merge=union *.dbproj merge=union *.cproj merge=union +*.c diff=c diff --git a/.gitignore b/.gitignore index 714a294..5f1e7e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +@@ -1,227 +1,26 @@ ################# ## Eclipse ################# @@ -224,4 +225,32 @@ pip-log.txt .lss .map .o -.srec \ No newline at end of file +.srec + No newline at end of file +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union +*.cproj merge=union +*.c diff=c + + + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain + diff --git a/Tacho_screen.atsuo b/Tacho_screen.atsuo index c58da35..1fd7620 100644 Binary files a/Tacho_screen.atsuo and b/Tacho_screen.atsuo differ diff --git a/Tacho_screen.c b/Tacho_screen.c index 9b5a138..ea7cf55 100644 --- a/Tacho_screen.c +++ b/Tacho_screen.c @@ -8,10 +8,10 @@ #include #include -#define _PRIM PORTC -#define _SEC PORTD +#define _PRIM PORTC //Right digit +#define _SEC PORTD //Left digit -#define _WHEEL_SIZE 207 +#define _WHEEL_SIZE 207 //In cm //Define characters (negative) #define _C1 0b10101111 @@ -27,25 +27,25 @@ #define _C_ 0b11111101 #define _CCLEAR 255 -uint32_t cntr; -unsigned int speed; +uint32_t cntr; //counter for Timer +unsigned int speed; //global var to save the calculated speed in -ISR(TIMER0_OVF_vect) +ISR(TIMER0_OVF_vect) //ISR for TIMER0 overflow { cntr++; } inline void calcSpeed(void) { - float tmrSpeed = F_CPU / 256; - float tmrTime = 1 / tmrSpeed; - float comTime = tmrTime * cntr; + float tmrSpeed = F_CPU / 256; //The timer overflow speed in Hz + float tmrTime = 1 / tmrSpeed; //The timer overflow speed in s + float comTime = tmrTime * cntr; //calculate the total time - float mps = (_WHEEL_SIZE / 100) / comTime; + float mps = (_WHEEL_SIZE / 100) / comTime; //Convert wheelsize to m and derive by the complete time - float kmph = mps * 3.6; + float kmph = mps * 3.6; //km/h = m/s * 3.6 - speed = (int)kmph; + speed = (int)kmph; //cast to int and write into global var speed }//calcSpeed() inline void render(int _screen) @@ -55,7 +55,10 @@ inline void render(int _screen) int i1, i2; itoa(_screen, cNr, 10); //convert int to string for rendering - + /* + * If _screen is smaller than 10, the cNr contains 1xxxxxxxxxx, but if it is bigger than 10 it looks like this: 10xxxxxxxxxx + * So I have to change the digits + */ if(_screen < 10) { i1 = 0; @@ -159,24 +162,24 @@ int main(void) TCCR0 = (1 << CS00); // Prescaler 1 TIMSK = (1<