Search code examples
assemblyintelledmicroprocessors

different operations in displaying operation


I am trying to create a file named "test.txt" in a folder named "test" in the current directory and append some lines of text into it.

I am using this code segment in a program but getting an exception saying that the file is already in use by another process. Is there any problem in this segment?

File.Create(FileName);
string fullPathName2 = Path.GetFullPath(FileName);             
File.AppendAllText(fullPathName2, time + Environment.NewLine);

Solution

  • In the "static" code, you have a loop to set each column of the matrix. The column to be set each time is selected by the bitmask in DL, it starts with 0x80 (the first column) and than rotates right another 7 times (0x40, 0x20, 0x10, ... ) after that it comes back to its initial value, and since you have 8 columns in the matrix, you get the same image each time.

    Note that the memory dump is actually the bitmap of the drawn digit, each byte representing a single column, from left to right.

    In the "moving" version, after each loop (that we mentioned above), we perform another rotation to DL, causing it to start from the next column in the next loop, so if the first loop is from 0x80-0x01 (causing the columns of the matrix to take the values 00 00 41 FF 01 00 00 00), the second one is from 0x40-0x80. (causing the columns of the matrix to take the values 00 41 FF 01 00 00 00 00)

    E.g.

    Iteration 1:

    value  00  00  41  FF  01  00  00  00
    col    0   1   2   3   4   5   6   7
    

    Iteration 2:

    value  00  00  41  FF  01  00  00  00
    col    7   0   1   2   3   4   5   6 
    

    Edit:

    In each iteration we only lit LEDs in one of the columns, and the rest are off, but it seems as all of the columns are set (it's an illusion). I don't know if the light really persists or not, but this is how we see it anyway.

    I mean at any cell, if the corresponding row and column value is equal to 1,then the cell will glow?

    Yes, for example (X - LED on, O - LED off):

    0 O O O O O O O O    1 O O X X O O O O    1 O O O O O O O O
    0 O O O O O O O O    1 O O X X O O O O    1 O O O O O O O O
    1 O O O O O X O O    1 O O X X O O O O    1 O O O O O O O O
    0 O O O O O O O O    0 O O O O O O O O    1 O O O O O O O O
    0 O O O O O O O O    0 O O O O O O O O    1 O O O O O O O O
    0 O O O O O O O O    0 O O O O O O O O    1 O O O O O O O O
    0 O O O O O O O O    0 O O O O O O O O    1 O O O O O O O O
    0 O O O O O O O O    0 O O O O O O O O    1 O O O O O O O O
      0 0 0 0 0 1 0 0      0 0 1 1 0 0 0 0      0 0 0 0 0 0 0 0 
    

    A pseudo code of your static assembly will be like that:

    // rotation of a byte
    #define ROR(x, n)   (((x >> n) | (x << (8-n))) & 0xff)
    col_selector = 0x80;
    rows_map = {0x00,  0x00,  0x41,  0xFF,  0x01,  0x00,  0x00,  0x00}
    for (col_index = 0; i < col_index; ++col_index)
    {
        // 1st - 0x80 --> 0b10000000 --> 1st column from the left
        // 2nd - 0x40 --> 0b01000000 --> 2nd column from the left
        choose_cols(ROR(col_selector, col_index));
        // 1st - cols_map[0] --> 0x00 --> 0b00000000 --> don't set any row in column 0
        // 3rd - cols_map[2] --> 0x41 --> 0b01000001 --> set the 2nd and 8th rows in column 2
        choose_rows(rows_map[col_index]);
    }
    

    In the second case we wrap it in another loop:

    col_selector = 0x80;
    for (i = 0; i < 8; ++i)
        // 1st time, col_selector is 0x80
        // 2nd time, col_selector is ROR(0x80, 1) --> 0x40
        rows_map = {0x00,  0x00,  0x41,  0xFF,  0x01,  0x00,  0x00,  0x00}
        for (col_index = 0; i < col_index; ++col_index)
        {
            // first i iteration:
            // 1st - 0x80 --> 0b10000000 --> 1st column from the left
            // 2nd - 0x40 --> 0b01000000 --> 2nd column from the left
            // second i iteration:
            // 1st - 0x40 --> 0b01000000 --> 2nd column from the left
            // 2nd - 0x20 --> 0b00100000 --> 3rd column from the left
            // 8th - 0x80 --> 0b10000000 --> 1st column from the left
            choose_cols(rotate col_selector col_index times to the right);
    
            // this part is the same in both iterations
            // 1st - cols_map[0] --> 0x00 --> 0b00000000 --> don't set any row in column 0
            // 3rd - cols_map[2] --> 0x41 --> 0b01000001 --> set the 2nd and 8th rows in column 2
            choose_rows(rows_map[col_index]);
        }
        col_selector = ROR(col_selector, 1)
    }