Mikrocontroller und Digitale Elektronik
›
Thread
Merkwürdiges Phänomen mit Display und SPI
S
sam
Gast
06.09.2012 09:14
#2823685
Hi ich habe vorhin einen Display über die SPI Schnittstelle meines
Controllers Programmiert. Der Controller ist geflasht allerdings sobald
ich das Programmiergerät abnehme und den Controller allein starte wird
nichts auf dem Display angezeigt. Das ganze funktioniert nur mit dem
Programmiergerät? Warum ist das so? Muss ich im Programmcode noch etwas
hinzufügen irgend etwas initialisieren?
Welcher Kontroller, welches Display, Schaltung, Bild vom Board.
Wie sollen wir wissen was du wie gemacht hast.
Im Code musst du sehr wahrscheinlich nichts ändern.
S
sam
Gast
06.09.2012 13:16
#2824077
Display:
http://www.komputer.de/zen/index.php?main_page=product_info&cPath=30&products_id=74
Controller ATmega16
Code:
1 #define LCD_RST PB3
2 #define SPI_CS PB2
3 #define SPI_MOSI PB5
4 #define SPI_SCK PB7
5 #define LCD_DC PB4
6
7 #define DISPLAY_PORT PORTB
8 #define DISPLAY_DDR DDRB
9
10 #define FONT c3x5
11 #define FONT_POS c3x5_pos
12
13 #define F_CPU 1000000UL
14
15 #include <avr/io.h>
16 #include <util/delay.h>
17
18 // unsigned char characters[248] = {0x00,0x5c, 0x06, 0x00, 0x06, 0x28, 0x7c, 0x28, 0x7c, 0x28, 0x5c, 0x54, 0xfe, 0x54, 0x74, 0x44, 0x20, 0x10, 0x08, 0x44, 0x28, 0x54, 0x54, 0x20, 0x50, 0x06, 0x38, 0x44, 0x44, 0x38, 0x02, 0x07, 0x02, 0x10, 0x10, 0x7c, 0x10, 0x10, 0xc0, 0x10, 0x10, 0x10, 0x10, 0x10, 0x40, 0x60, 0x10, 0x0c, 0x7c, 0x64, 0x54, 0x4c, 0x7c, 0x48, 0x7c, 0x40, 0x64, 0x54, 0x54, 0x54, 0x48, 0x44, 0x54, 0x54, 0x54, 0x6c, 0x3c, 0x20, 0x70, 0x20, 0x20, 0x5c, 0x54, 0x54, 0x54, 0x24, 0x7c, 0x54, 0x54, 0x54, 0x74, 0x04, 0x04, 0x64, 0x14, 0x0c, 0x7c, 0x54, 0x54, 0x54, 0x7c, 0x5c, 0x54, 0x54, 0x54, 0x7c, 0x44, 0xc4, 0x10, 0x28, 0x44, 0x28, 0x28, 0x28, 0x28, 0x28, 0x44, 0x28, 0x10, 0x08, 0x04, 0x54, 0x08, 0x7c, 0x44, 0x54, 0x54, 0x5c, 0x7c, 0x24, 0x24, 0x24, 0x7c, 0x7c, 0x54, 0x54, 0x54, 0x6c, 0x7c, 0x44, 0x44, 0x44, 0x44, 0x7c, 0x44, 0x44, 0x44, 0x38, 0x7c, 0x54, 0x54, 0x54, 0x44, 0x7c, 0x14, 0x14, 0x14, 0x04, 0x7c, 0x44, 0x44, 0x54, 0x74, 0x7c, 0x10, 0x10, 0x10, 0x7c, 0x44, 0x44, 0x7c, 0x44, 0x44, 0x60, 0x40, 0x40, 0x44, 0x7c, 0x7c, 0x10, 0x10, 0x28, 0x44, 0x7c, 0x40, 0x40, 0x40, 0x40, 0x7c, 0x08, 0x10, 0x08, 0x7c, 0x7c, 0x08, 0x10, 0x20, 0x7c, 0x38, 0x44, 0x44, 0x44, 0x38, 0x7c, 0x14, 0x14, 0x14, 0x08, 0x3c, 0x24, 0x64, 0x24, 0x3c, 0x7c, 0x14, 0x14, 0x14, 0x68, 0x5c, 0x54, 0x54, 0x54, 0x74, 0x04, 0x04, 0x7c, 0x04, 0x04, 0x7c, 0x40, 0x40, 0x40, 0x7c, 0x0c, 0x30, 0x40, 0x30, 0x0c, 0x3c, 0x40, 0x30, 0x40, 0x3c, 0x44, 0x28, 0x10, 0x28, 0x44, 0x0c, 0x10, 0x60, 0x10, 0x0c, 0x44, 0x64, 0x54, 0x4c, 0x44 };
19 // unsigned char character_pos[58] = {0, 1, 4, 9, 14, 19, 24, 25, 27, 29, 32, 37, 38, 43, 44, 47, 52, 55, 60, 65, 70, 75, 80, 85, 90, 95, 96, 97, 100, 105, 108, 112, 117, 122, 127, 132, 137, 142, 147, 152, 157, 162, 167, 172, 177, 182, 187, 192, 197, 202, 207, 212, 217, 222, 227, 232, 237, 242, };
20 //
21 unsigned char c3x5 [ 248 ] = { 0x00 , 0x2e , 0x06 , 0x06 , 0x3e , 0x14 , 0x3e , 0x0c , 0x36 , 0x18 , 0x32 , 0x08 , 0x26 , 0x14 , 0x2a , 0x34 , 0x06 , 0x1c , 0x22 , 0x22 , 0x1c , 0x14 , 0x08 , 0x14 , 0x08 , 0x1c , 0x08 , 0x40 , 0x60 , 0x08 , 0x08 , 0x08 , 0x20 , 0x60 , 0x1c , 0x03 , 0x3e , 0x22 , 0x3e , 0x24 , 0x3e , 0x20 , 0x32 , 0x2a , 0x26 , 0x22 , 0x2a , 0x3e , 0x0e , 0x08 , 0x3e , 0x2e , 0x2a , 0x3a , 0x3e , 0x2a , 0x3a , 0x02 , 0x3a , 0x06 , 0x3e , 0x2a , 0x3e , 0x2e , 0x2a , 0x3e , 0x14 , 0x40 , 0x64 , 0x08 , 0x14 , 0x22 , 0x14 , 0x14 , 0x14 , 0x22 , 0x14 , 0x08 , 0x02 , 0x2a , 0x06 , 0x3e , 0x22 , 0x2e , 0x3e , 0x0a , 0x3e , 0x3e , 0x2a , 0x36 , 0x3e , 0x22 , 0x22 , 0x3e , 0x22 , 0x1c , 0x3e , 0x2a , 0x22 , 0x3e , 0x0a , 0x02 , 0x3e , 0x22 , 0x3a , 0x3e , 0x08 , 0x3e , 0x22 , 0x3e , 0x22 , 0x30 , 0x20 , 0x3e , 0x3e , 0x08 , 0x36 , 0x3e , 0x20 , 0x20 , 0x3e , 0x04 , 0x3e , 0x3c , 0x08 , 0x1e , 0x3e , 0x22 , 0x3e , 0x3e , 0x0a , 0x0e , 0x3e , 0x22 , 0x7e , 0x3e , 0x0a , 0x34 , 0x2e , 0x2a , 0x3a , 0x02 , 0x3e , 0x02 , 0x3e , 0x20 , 0x3e , 0x1e , 0x20 , 0x1e , 0x3e , 0x10 , 0x3e , 0x36 , 0x08 , 0x36 , 0x06 , 0x38 , 0x06 , 0x32 , 0x2a , 0x26 };
22 unsigned char c3x5_pos [ 58 ] = { 0 , 1 , 2 , 3 , 6 , 9 , 12 , 15 , 16 , 18 , 20 , 23 , 26 , 28 , 31 , 32 , 35 , 38 , 41 , 44 , 47 , 50 , 53 , 56 , 59 , 62 , 65 , 68 , 71 , 74 , 77 , 80 , 83 , 86 , 89 , 92 , 95 , 98 , 101 , 104 , 107 , 110 , 113 , 116 , 119 , 122 , 125 , 128 , 131 , 134 , 137 , 140 , 143 , 146 , 149 , 152 , 155 , 158 };
23
24 int main ( void )
25 {
26 DISPLAY_DDR = 0xBF ;
27 DISPLAY_PORT = 0x00 ;
28
29 DISPLAY_PORT &= ~ ( 1 << LCD_RST );
30 _delay_ms ( 5 );
31 DISPLAY_PORT |= ( 1 << LCD_RST );
32
33 //init SPI
34 SPCR = ( 1 << SPE ) | ( 1 << MSTR ) | ( 1 << SPR0 );
35
36 display_init ();
37
38 //display_c('O');
39 display_str ( "SAM" );
40
41 while ( 1 )
42 {
43
44 }
45 }
46
47 void display_init ( void )
48 {
49 display_out ( 0x21 , 0 );
50 display_out ( 0xc0 , 0 );
51 display_out ( 0x06 , 0 );
52 display_out ( 0x13 , 0 );
53 display_out ( 0x20 , 0 );
54 display_clear ();
55
56 }
57
58 void display_out ( unsigned char data , unsigned char data_type )
59 {
60 DISPLAY_PORT &= ~ ( 1 << SPI_CS );
61
62 if ( data_type )
63 {
64 DISPLAY_PORT |= ( 1 << LCD_DC );
65 }
66 else
67 {
68 DISPLAY_PORT &= ~ ( 1 << LCD_DC );
69 }
70
71 SPDR = data ;
72 while (( SPSR & ( 1 << SPIF )) == 0 );
73
74 DISPLAY_PORT |= ( 1 << SPI_CS );
75 }
76
77 void display_clear ( void )
78 {
79 unsigned int i ;
80
81 display_out ( 0x0c , 0 );
82 display_out ( 0x80 , 0 );
83
84 for ( i = 0 ; i < 504 ; i ++ )
85 {
86 display_out ( 0x00 , 1 );
87 }
88 }
89
90 void display_c ( unsigned char c )
91 {
92 unsigned char i ;
93 unsigned char diff ;
94
95 c = c - 0x20 ;
96
97 if ( c > 0 )
98 {
99 diff = FONT_POS [ c ] - FONT_POS [ c - 1 ];
100 }
101 else
102 {
103 diff = 1 ;
104 }
105
106 for ( i = 0 ; i < diff ; i ++ )
107 {
108 display_out ( FONT [ FONT_POS [ c ] - diff + 1 + i ], 1 );
109 }
110
111 display_out ( 0x00 , 1 );
112 }
113
114 void display_str ( char * str )
115 {
116 while ( * str != '\0' )
117 {
118 display_c ( * str );
119 str ++ ;
120 }
121 }
Hallo Gemeinde
Habe auch das Problem, dass meine Schaltung nicht mehr läuft, wenn ich
den ISP Stecker abziehe.
Hat hier jemand eine Lösung ? Scheint ja ein üblicher Anfängerfehler zu
sein.
Danke
Torsten
N
Nobi_noob
Gast
08.10.2012 13:01
#2864121
Hat bestimmt etwas mit der reset leitung des mcu zu tun...
SH
Steffen H.
Gast
08.10.2012 13:07
#2864133
Auch bei dir Torsten:
Ohne Schaltplan kann dir keiner wirklich weiter helfen.
Steffen
Y
yagi
Gast
08.10.2012 13:07
#2864135
... oder mit Strom anschließen ...
Antwort schreiben
Bitte melde dich an, um einen Beitrag zu schreiben.
Noch kein Account?
Die Registrierung ist kostenlos und dauert nur eine Minute.
Jetzt registrieren