Forum: Mikrocontroller und Digitale Elektronik Mega128 und (RS)232


von Burt (Gast)


Lesenswert?

Hallo!

Hab mir heute alles nötige für die kommunizierung über die
Serielle schnittstelle mit dem PC zusammengebastelt.

kennt jemand n kleines asm program für den ATmel128, RX1 + TX1,
9700baud 8N1 welches den inhalt eines arbeitsregisters über die rs232
auf nem terminal ausgibt???

Danke, Burt

von Burt (Gast)


Lesenswert?

.... natürlich meine ich den ATmega128...... :-)

Burt

von Hilel (Gast)


Lesenswert?

Hallo.
Ich habe es in C. Es dürfte kein Problem sein, das Programm in asm
umzuschreiben. Hier ist der Code.

//ICC-AVR application builder : 23.12.2005 18:30:31
// Target : M128
// Crystal: 16.000Mhz

#include <iom128v.h>
#include <macros.h>

void port_init(void)
{
 PORTA = 0xFF;
 DDRA  = 0x00;
 PORTB = 0xFF;
 DDRB  = 0x00;
 PORTC = 0xFF; //m103 output only
 DDRC  = 0x00;
 PORTD = 0xFF;
 DDRD  = 0x00;
 PORTE = 0xFF;
 DDRE  = 0x00;
 PORTF = 0xFF;
 DDRF  = 0x00;
 PORTG = 0x1F;
 DDRG  = 0x00;
}

//UART1 initialisation
// desired baud rate:9600
// actual baud rate:9615 (0,2%)
// char size: 8 bit
// parity: Disabled
void uart1_init(void)
{
 UCSR1B = 0x00; //disable while setting baud rate
 UCSR1A = 0x00;
 UCSR1C = 0x06;
 UBRR1L = 0x67; //set baud rate lo
 UBRR1H = 0x00; //set baud rate hi
 UCSR1B = 0x18;
}

//call this routine to initialise all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 XDIV  = 0x00; //xtal divider
 XMCRA = 0x00; //external memory
 port_init();
 uart1_init();

 MCUCR = 0x00;
 EICRA = 0x00; //extended ext ints
 EICRB = 0x00; //extended ext ints
 EIMSK = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 ETIMSK = 0x00; //extended timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialised
}

void main(void)
{
   char c;
   init_devices();
   while(1)
   {
    while (!(UCSR1A & (1<<RXC1)));       /* Warte auf ein Zeichen */
     c = UDR1;
  if(c=='\r')
  {
    c='\n';
    while (!(UCSR1A & (1<<UDRE1)));    /* warten bis Senden moeglich */
       UDR1 = c;
    c='\r';
    while (!(UCSR1A & (1<<UDRE1)));    /* warten bis Senden moeglich */
       UDR1 = c;
    }
    while (!(UCSR1A & (1<<UDRE1)));      /* warten bis Senden moeglich
*/
     UDR1 = c;
   }
}

Das Programm empfängt Zeichen über die serielle Schnittstelle und
sendet sie zurück.

von Burt (Gast)


Lesenswert?

danke für den code!

Zum hardware testen wäre das ja optimal. Aber mein AVR Studio (WinAVR)
spuckt lauter fehler aus! Er kennt nicht mal die Ports usw....
Man muss sicherlich noch ne IncludeDatei oder sowas mit-verwenden.
Mit C hab ich überhaupt keine erfahrungen darum sorry wenns ne blöde
frage ist :-\

Danke, Burt

von marcelo costa (Gast)


Lesenswert?

assunto nôa estou conseguindo configurar a usart do atmega 128
em asm no avr estudio

von esta aki? (Gast)


Lesenswert?

... das kommt mir spanisch vor ...

von Rahul (Gast)


Lesenswert?

es ist portugisisch... (spricht man nun mal in .br[asilien])...

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.