lcd kod degisimi

bir takograf projesinde (lcd kodlari icin) kullanilmak uzere yazildi.

muhtemelen kimsenin de isine yaramayacaktir.

dil : c

// ##################################################################
// author : yasin tasan
// date : 12.10.2012
// brief : lcd karakter kodlari ureten GLCD Font Creator isimli
// programın urettigi kodlari, proje ihtiyacına gore 
// olan 9x14 pixellik boyutlara cevirir.
// ##################################################################

#include "stdafx.h"
#define SIZE 359

unsigned char TransferAndWrite(unsigned char *temp_stack, unsigned char size);

int main()
{
    unsigned char stack[55];
    unsigned char temp_lcd[16][16];
    unsigned char characters[96][329];
    unsigned char char_2_stack[2];
    unsigned char lcd[14][2];
    unsigned char stack_lcd[14][2];
    char line[SIZE];
    unsigned int i;
    char test = 0 ;
    unsigned int line_number = 0;

    FILE *output_file_pointer;
    FILE *input_file_pointer;

    // output dosyasi varsa sil
    system("erase lcd_code_output.txt");

    // karakterlerin hepsini dosyadan oku
    fopen_s(&input_file_pointer,"lcd_code_input.txt","r");

    while ( fgets (line , SIZE , input_file_pointer) != NULL) {  
        line_number++;
        if ((line[8] == '0') && line[9] == 'x') {       
            for (int i = 0; i < 0x37; i++) {
                char_2_stack[0] = line[i+10+i*5];
                char_2_stack[1] = line[i+10+i*5+1];
                // okunan character'leri decimal degere cevir 
                if (char_2_stack[0] >= 48 && char_2_stack[0] <= 57 ) // 0-9 araligi cevirisi
                    char_2_stack[0] = char_2_stack[0] - 48;
                if (char_2_stack[1] >= 48 && char_2_stack[1] <= 57 ) // 0-9 araligi cevirisi
                    char_2_stack[1] = char_2_stack[1] - 48;
                if (char_2_stack[0] >= 65 && char_2_stack[0] <= 70 ) // A-F araligi cevirisi
                    char_2_stack[0] = char_2_stack[0] - 55;
                if (char_2_stack[1] >= 65 && char_2_stack[1] <= 70 ) // A-F araligi cevirisi
                    char_2_stack[1] = char_2_stack[1] - 55;
                // cevrilen character'leri stack'e aktar
                stack[i] = char_2_stack[0]*16 + char_2_stack[1];
            }
            TransferAndWrite(stack, 55);
            if (line_number == 108)
                break;
            for (int i = 0; i < SIZE; i++)
                line[i] = 0 ;
        }
    }

    fclose( input_file_pointer );

    return 0;   
}

unsigned char TransferAndWrite(unsigned char *temp_stack, unsigned char size)
{
    unsigned char lcd[14][2];
    unsigned char temp_lcd[16][16];
    unsigned char stack[55];
    FILE *output_file_pointer;
    for (int i = 0; i < size; i++)
        stack[i] = temp_stack[i];

    // cikti matrixini temizle
    for (int i = 0; i < 14; i++) {
        for (int j = 0; j < 2; j++)
            lcd[i][j] = 0;
    }

    // ilk 8 satir
    for (int j = 0; j < 8; j++) {
        // 1. satir
        for (int i = 0; i < 16; i++)
            temp_lcd[j][i] = stack[i*3+1] & 0x01;

        // 2. satir icin shift 
        for (int i = 0; i < 16; i++)
            stack[i*3+1] = stack[i*3+1] >> 1;
    }

    // sonraki 8 satir
    for (int j = 8; j < 16; j++) {
        // 1. satir
        for (int i = 0; i < 16; i++)
            temp_lcd[j][i] = stack[i*3+2] & 0x01; 

        // 2. satir icin shift 
        for (int i = 0; i < 16; i++)
            stack[i*3+2] = stack[i*3+2] >> 1;
    }

    // temp_lcd'den lcd'ye aktarma isi icin shift islemleri 
    for (int j = 0; j < 14; j++) {
        for (int i = 0; i < 8; i++) {
            temp_lcd[j][i] = temp_lcd[j][i] << (7-i);
            lcd[j][0] |= temp_lcd[j][i];
        }
        for (int i = 8; i < 16; i++) {
            temp_lcd[j][i] = temp_lcd[j][i] << (15-i);
            lcd[j][1] |= temp_lcd[j][i];
        }
    }

    // ciktiyi dosyaya yazma
    fopen_s(&output_file_pointer,"lcd_code_output.txt","a");
    fprintf(output_file_pointer, "{");
    printf("{");

    for (int i = 0; i < 14; i++) { 
        //deger 0 oldugunda yanina 1 tane 0 daha eklemek icin
        if (lcd[i][0] <= 15) {
            fprintf(output_file_pointer, "0x0%x", lcd[i][0]);
            printf("0x0%x", lcd[i][0]);
        } else {
            fprintf(output_file_pointer, "0x%x", lcd[i][0]);
            printf("0x%x", lcd[i][0]);
        }

        //deger 0 oldugunda yanina 1 tane 0 daha eklemek icin
        if (i != 13) { // sonuncu elemana gelmedigi surece en sona virgul koy       
            if (lcd[i][1] <= 15) {
                fprintf(output_file_pointer, "0%x,", lcd[i][1]);
                printf("0%x,", lcd[i][1]);
            }
            else {
                fprintf(output_file_pointer, "%x,", lcd[i][1]);
                printf("%x,", lcd[i][1]);
            } 
        }
        else { // sonuncu elemana geldiginde en sona virgul koyma
            if (lcd[i][1] <= 15) {
                fprintf(output_file_pointer, "0%x", lcd[i][1]);
                printf("0%x", lcd[i][1]);
            }
            else {
                fprintf(output_file_pointer, "%x", lcd[i][1]);
                printf("%x", lcd[i][1]);
            } 
        }
    }

    fprintf(output_file_pointer, "},");
    printf("},");

    fprintf(output_file_pointer, "\n");
    printf("\n");

    fclose( output_file_pointer );
    return 0;
}