We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hi there,
i just started to use the µVision compiler. when i try to use my old programs there is one big problem. i cant give hex values written in a unsigned char to other functions... i got an example:
/*** Einbinden von Include-Dateien ***/ #include <stdio.h> // Standard Ein-/Ausgabefunktionen #include <at89c51cc03.h> // CC03er-Register #include <stdlib.h> /******************************************************************************************/ /*** CC03er-SFR´s und SFR-Bits besonders für dieses Projekt ***/ /*** Beachten: diese Festlegungen überschreiben die Festlegungen aus ´at89c51cc03.h´ ***/ /*** Das ergibt aber keine Probleme ! ***/ /******************************************************************************************/ /******************************************************/ /*** CS\-Adressen der externen Peripherie-Bausteine ***/ /******************************************************/ unsigned char xdata DIN _at_ 0xB3; unsigned char xdata CLK _at_ 0xB4; //Portpin P3.5, serielle Freigabeleitung unsigned char xdata LOAD _at_ 0xB5; /********************************************************************************/ /* Funktion void init_seri(void) initialisiert die serielle Schnittstelle */ /* */ /* Schnittstellenparameter: 9600Baud, 8 Datenbit, 1 Stopp Bit */ /* asynchroner Betrieb */ /* */ /********************************************************************************/ void init_seri(void) { SCON=0x52; TMOD |=0x20; TH1=0xfd; // Reloadwert 0xfd bei 11,0592MHz TR1=1; TI=1; } /******************************************************************************************/ /*** Löschen des Terminal-Bildschirms ***/ void clear_screen(void) { printf("\x1b\x48\x1b\x4a"); } /*******************************************************************************************/ void _wait_ms(unsigned int multiplikator) { unsigned int i,j; for(i=0;i<multiplikator;i++) { for(j=0;j<123;j++); } } void send_2_byte (signed char adresse, signed char daten) // Funktion für Serielle Datenübertragung über { unsigned char teiler; int i; LOAD=0; teiler = 0x80; for(i=1;i<9;i++) //Ausgabe der Adresse { if (adresse & teiler!=0) { DIN=1; // Datenleitung setzen } else { DIN=0; } CLK=1; //Takt CLK=0; //Ausgeben teiler=teiler/2; //nächstes Bit } teiler = 0x80; for(i=1;i<9;i++) //Ausgabe der Adresse { if (daten&teiler!=0) { DIN=1; // Datenleitung setzen } else { DIN=0; } CLK=1; //Takt CLK=0; //Ausgeben teiler=teiler/2; //nächstes Bit } LOAD=1; // Datenübertragung abgeschlossen } void init_MAX7219(void) { int i; send_2_byte(0x09, 0xff); // BCD Code B Decode-Mode für alle 8 Display-Stellen! send_2_byte(0x0a, 0x0f); // Maximale Lichtintensität gewählt! send_2_byte(0x0b, 0x07); // Alle 8 Display-Stellen aktiviert! send_2_byte(0x0c, 0x01); // LED-Display eingeschaltet, shut down aufgehoben! for (i=1; i<9; i++) // Schleife zum Löschen der alten Displayinhalte! send_2_byte(i, 0x0f); send_2_byte(0x0f, 0x01); // Displaytest eingeschaltet! _wait_ms(1000); // 1 Sekunde warten, dann send_2_byte(0x0f, 0x00); // Displaytest wieder ausschalten! } /********************************************************************************/ void main(void) { char WAT_NU; init_seri(); // Initialisierung der seriellen Schnittstelle! // Löschen des Terminal-Bildschirms clear_screen(); init_MAX7219(); // Grundinitialisierung des MAX7219 durchführen LOAD = 1; // Grundzustand auf den seriellen Bus einstellen! CLK = 0; printf("Das Arbeiten mit dem seriellen LED-Treiber-Baustein MAX7219\n"); while(1); // Endlosschleife }
it doesnt init the MAX7219... althought the function usualy works... i hope someone can give me hint!
greetings from berlin... jens
I suspect the problem is here:
unsigned char xdata DIN _at_ 0xB3; unsigned char xdata CLK _at_ 0xB4; //Portpin P3.5, serielle Freigabeleitung unsigned char xdata LOAD _at_ 0xB5;
Try replacing that with:
#define DIN P3_3 #define CLK P3_4 #define LOAD P3_5
no, it isnt... the ports are set...
i have this problem with the hex adress into the unsigned char which i try to give to the function... when i use an other compiler everything works fine
Note that the 8051 chip has bit variables. And the I/O pins are bit-addressable. But "unsigned char xdata" specify a byte variable, not a bit variable.
I'm in doubt about missing paranthesis
if (adresse & teiler!=0)
and your delay function.
as Dan noted is declaring ports pins as xdata and as char such as unsigned char xdata CLK _at_ 0xB4; //Portpin P3.5
till that is corrected all other issues are moot
to the OP: look up sbit in the documentation
Erik
no, it isnt...
Yes it is.
the ports are set...
Those declarations do not let you access the ports. Whatever "sets" those ports, access via those variables is not it.
Im Sorry! It works now... i changed the the port declaration...
thanks for your help!!!!
Again me: you should use a timer to make a delay function. This was often discussed here. JC