Forum: Mikrocontroller und Digitale Elektronik MAX7456 & STM32 Charakter überschrieben


von Dennis H. (somebuddy)


Lesenswert?

Guten Abend,

Habe vor einen MAX7456 an einem STM32 zu betreiben. Der TestCode mit dem 
Anzeigen eines "SAMPLE" Text funktionierte auch ohne Probleme.

Nachdem ich allerdings begonnen habe zu "spielen" und versucht habe 
einen Code von Ulrich Radig auf den STM zu portieren ( speziell folgende 
Funktion )

:
1
//Init Pal
2
void pal_init (void)
3
{   
4
    //Setup Serial Peripheral Interface
5
    DDRB |= (1<<PB3)|(1<<PB5)|(1<<PB2); 
6
    
7
    //CS Signal
8
    DDRB |= (1<<PB1);
9
    PAL_CS_HIGH;
10
    
11
    //Setup Serial Peripheral Interface (SPI) 
12
    SPCR |= (1<<SPE)|(1<<MSTR)|(1<<SPR0);
13
 
14
    //Programmieren des Zeichensatzes 
15
    for(unsigned char count = 0;count <91;count++)
16
    {
17
        unsigned int tmp = ((unsigned int)&FONT)+(64*count);
18
        unsigned char Index;
19
        pal_data_write(VIDEO_MODE_0_WRITE,0x00);
20
     
21
        pal_data_write(FM_ADDRH_WRITE,count);  
22
        for(Index = 0x00; Index < 0x36; Index++)
23
        {
24
            pal_data_write(FM_ADDRL_WRITE,Index);
25
            pal_data_write(FM_DATA_IN_WRITE,pgm_read_byte(tmp+Index));     
26
        }
27
        pal_data_write(FM_MODE_WRITE, 0xA0);
28
        //for(unsigned long a=0;a<100000;a++){asm("nop");};
29
        while ((pal_data_write(STATUS_READ,0) & 0x20) != 0x00);
30
    }
31
       
32
    pal_data_write (0x00,0x48);
33
    pal_data_write (0x04,0x04);
34
    pal_data_write (0x05,(display_memory_address&0xFF00)>>8);
35
    pal_data_write (0x06,(display_memory_address&0x00FF));
36
37
  return;
38
}

hat der Ärger angefangen..
Es lief nicht, da ich nicht genau wusste wie ich das PROGMEM zu ersetzen 
habe. Bei dem Testlauf habe ich mir scheinbar das Zeichen für 
"WHITESPACE" überschrieben. Zumindest zeigt sich bei dem vorher 
funktionstüchtigen Code folgendes Fehlerbild.

http://s14.directupload.net/images/130308/sjbzfqxu.jpg


Ich möchte nun erneut und richtig die Char Tabelle einlesen. Habe dazu 
folgenden Code gefunden:
1
/****************************************************************************
2
 *   Copyright (C) 2009-2013 by Claas Anders "CaScAdE" Rathje               *
3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
5
 *                                                                          *
6
 *   This program is free software; you can redistribute it and/or modify   *
7
 *   it under the terms of the GNU General Public License as published by   *
8
 *   the Free Software Foundation; either version 2 of the License.         *
9
 *                                                                          *
10
 *   This program is distributed in the hope that it will be useful,        *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
13
 *   GNU General Public License for more details.                           *
14
 *                                                                          *
15
 *   You should have received a copy of the GNU General Public License      *
16
 *   along with this program; if not, write to the                          *
17
 *   Free Software Foundation, Inc.,                                        *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
19
 ****************************************************************************/
20
 
21
#include "main.h"
22
#include <avr/io.h>
23
#include <avr/pgmspace.h>
24
#include <util/delay.h>
25
#include "max7456_software_spi.h"
26
 
27
 
28
#if (ALLCHARSDEBUG|(WRITECHARS != -1))
29
 
30
/**
31
 * easy char creation:
32
 * http://www.mylifesucks.de/tools/max7456/
33
 */
34
// chars 0 - 255 with 54 byte per char
35
// orginal filename: c-osd.mcm
36
// Wed, 21 Sep 2011 13:46:48 +0200
37
 
38
 
39
 
40
//       0      ------------
41
//       1      ------------
42
//       2      ------------
43
//       3      ------------
44
//       4      ------------
45
//       5      ------------
46
//       6      ------------
47
//       7      ------------
48
//       8      ------------
49
//       9      ------------
50
//      10      ------------
51
//      11      ------------
52
//      12      ------------
53
//      13      ------------
54
//      14      ------------
55
//      15      ------------
56
//      16      ------------
57
//      17      ------------
58
//              000000000011
59
//              012345678901
60
const char   chr0[] PROGMEM = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55};
61
 
62
 
63
//       0      ------------
64
//       1      ------------
65
//       2      -----##-----
66
//       3      ----#  #----
67
//       4      ---#   #----
68
//       5      --#    #----
69
//       6      --#    #----
70
//       7      --###  #----
71
//       8      ----#  #----
72
//       9      ----#  #----
73
//      10      ----#  #----
74
//      11      ----#  #----
75
//      12      ----#  #----
76
//      13      ----#  #----
77
//      14      ---##  ##---
78
//      15      --#      #--
79
//      16      --#      #--
80
//      17      ---######---
81
//              000000000011
82
//              012345678901
83
const char   chr1[] PROGMEM = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x41,0x55,0x55,0x28,0x55,0x54,0xa8,0x55,0x52,0xa8,0x55,0x52,0xa8,0x55,0x50,0x28,0x55,0x55,0x28,0x55,0x55,0x28,0x55,0x55,0x28,0x55,0x55,0x28,0x55,0x55,0x28,0x55,0x55,0x28,0x55,0x54,0x28,0x15,0x52,0xaa,0x85,0x52,0xaa,0x85,0x54,0x00,0x15};
84
 
85
86
 
87
 
88
//       0      ------------
89
//       1      ------------
90
//       2      ------------
91
//       3      ------------
92
//       4      ------------
93
//       5      ------------
94
//       6      ------------
95
//       7      -###--#---#-
96
//       8      #   ## #-# #
97
//       9      # ## #  #  #
98
//      10      # ## # # # #
99
//      11      # ## # # # #
100
//      12      #   ## ### #
101
//      13      # ##-# #-# #
102
//      14      # #--# #-# #
103
//      15      # #--# #-# #
104
//      16      # #--# #-# #
105
//      17      -#----#---#-
106
//              000000000011
107
//              012345678901
108
const char chr254[] PROGMEM = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x40,0x51,0x51,0x2a,0x08,0x48,0x20,0x8a,0x28,0x20,0x88,0x88,0x20,0x88,0x88,0x2a,0x08,0x08,0x20,0x48,0x48,0x21,0x48,0x48,0x21,0x48,0x48,0x21,0x48,0x48,0x45,0x51,0x51};
109
 
110
 
111
//       0
112
//       1
113
//       2
114
//       3
115
//       4
116
//       5
117
//       6
118
//       7
119
//       8
120
//       9
121
//      10
122
//      11
123
//      12
124
//      13
125
//      14
126
//      15
127
//      16
128
//      17
129
//              000000000011
130
//              012345678901
131
const char chr255[] PROGMEM = {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa};
132
 
133
 
134
const char *chars[] PROGMEM = { chr0, chr1, chr2, chr3, chr4, chr5, chr6, chr7, chr8, chr9, chr10, chr11, chr12, chr13, chr14, chr15, chr16, chr17, chr18, chr19, chr20, chr21, chr22, chr23, chr24, chr25, chr26, chr27, chr28, chr29, chr30, chr31, chr32, chr33, chr34, chr35, chr36, chr37, chr38, chr39, chr40, chr41, chr42, chr43, chr44, chr45, chr46, chr47, chr48, chr49, chr50, chr51, chr52, chr53, chr54, chr55, chr56, chr57, chr58, chr59, chr60, chr61, chr62, chr63, chr64, chr65, chr66, chr67, chr68, chr69, chr70, chr71, chr72, chr73, chr74, chr75, chr76, chr77, chr78, chr79, chr80, chr81, chr82, chr83, chr84, chr85, chr86, chr87, chr88, chr89, chr90, chr91, chr92, chr93, chr94, chr95, chr96, chr97, chr98, chr99, chr100, chr101, chr102, chr103, chr104, chr105, chr106, chr107, chr108, chr109, chr110, chr111, chr112, chr113, chr114, chr115, chr116, chr117, chr118, chr119, chr120, chr121, chr122, chr123, chr124, chr125, chr126, chr127, chr128, chr129, chr130, chr131, chr132, chr133, chr134, chr135, chr136, chr137, chr138, chr139, chr140, chr141, chr142, chr143, chr144, chr145, chr146, chr147, chr148, chr149, chr150, chr151, chr152, chr153, chr154, chr155, chr156, chr157, chr158, chr159, chr160, chr161, chr162, chr163, chr164, chr165, chr166, chr167, chr168, chr169, chr170, chr171, chr172, chr173, chr174, chr175, chr176, chr177, chr178, chr179, chr180, chr181, chr182, chr183, chr184, chr185, chr186, chr187, chr188, chr189, chr190, chr191, chr192, chr193, chr194, chr195, chr196, chr197, chr198, chr199, chr200, chr201, chr202, chr203, chr204, chr205, chr206, chr207, chr208, chr209, chr210, chr211, chr212, chr213, chr214, chr215, chr216, chr217, chr218, chr219, chr220, chr221, chr222, chr223, chr224, chr225, chr226, chr227, chr228, chr229, chr230, chr231, chr232, chr233, chr234, chr235, chr236, chr237, chr238, chr239, chr240, chr241, chr242, chr243, chr244, chr245, chr246, chr247, chr248, chr249, chr250, chr251, chr252, chr253, chr254, chr255};
135
 
136
/**
137
 * put the above chars in the memory of the MAX7456
138
 * TODO: read out character, compare and write only if different
139
 */
140
void learn_all_chars_pgm(void) {
141
    char *pointer;
142
    for (uint16_t c = 0; c < 256; c++) {
143
        LED3_ON
144
        // select character to write (CMAH)
145
        spi_send_byte(0x09, c);
146
 
147
        _delay_ms(1);
148
 
149
        pointer = (char*)pgm_read_word(&chars[c]);
150
 
151
        for (uint8_t i = 0; i < 54; i++) {
152
            // select 4pixel byte of char (CMAL)
153
            spi_send_byte(0x0A, i);
154
 
155
            _delay_ms(1);
156
 
157
            // write 4pixel byte of char (CMDI)
158
            spi_send_byte(0x0B, pgm_read_byte(pointer++));
159
            _delay_ms(1);
160
        }
161
 
162
        // write to the NVM array from the shadow RAM (CMM)
163
        spi_send_byte(0x08, 0b10100000);
164
 
165
        LED3_OFF
166
        // according to maxim writing to nvram takes about 12ms, lets wait longer
167
        _delay_ms(50);
168
    }
169
}
170
 
171
 
172
 
173
#endif

Mir ist jedoch unklar wie ich diesen STM32 fähig mache.

Speziell :
1
pointer = (char*)pgm_read_word(&chars[c]);
2
3
//und
4
5
spi_send_byte(0x0B, pgm_read_byte(pointer++));


Vielen Dank !

von Dennis H. (somebuddy)


Lesenswert?

Habe nun alle char arrays in ein 2d array gepackt.Nicht schoen aber 
funktioniert. Vielleicht findet sich ja noch jemand mit einer Loesung

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.