pebisoft
17.04.2005, 23:51
hallo, bei ausgabe des wertes "wert_1 = 34000" kommt im terminal "-31536"
zur anzeige. warum kommen die zahlen über "32000" als negative zahl
zur ausgabe.
mfg pebisoft
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <string.h>
#include <delay_1.c>
#include <stdint.h>
#define READ 1
#define WRITE 2
#define USART_BAUD_RATE 19200
#define USART_BAUD_SELECT (F_CPU/(USART_BAUD_RATE*16l)-1)
void usart_init(int Enable, int Interupts)
{
if (Enable & READ) UCSRB = (1<<RXEN);
if (Enable & WRITE) UCSRB |= (1<<TXEN);
if (Interupts & READ) UCSRB |= (1<<RXCIE);
if (Interupts & WRITE) UCSRB |= (1<<TXCIE);
UBRRL = (unsigned char) USART_BAUD_SELECT;
}
void usart_writeChar(unsigned char c)
{
while (!(UCSRA & (1<<UDRE))) {}
UDR = c;
while(!(UCSRA & (1<<TXC))) {}
}
void usart_writeString(unsigned char *string) {
while (!(UCSRA & (1<<UDRE))) {}
while ( *string)
usart_writeChar(*string++);
}
int main (void)
{
char s[10];
uint16_t wert_1;
usart_init( (READ + WRITE) , READ);
wert_1=34000;
itoa( wert_1, s, 10);
while(1)
{
usart_writeString(s);
usart_writeString("\r");
warte(20000);
}
}
zur anzeige. warum kommen die zahlen über "32000" als negative zahl
zur ausgabe.
mfg pebisoft
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <string.h>
#include <delay_1.c>
#include <stdint.h>
#define READ 1
#define WRITE 2
#define USART_BAUD_RATE 19200
#define USART_BAUD_SELECT (F_CPU/(USART_BAUD_RATE*16l)-1)
void usart_init(int Enable, int Interupts)
{
if (Enable & READ) UCSRB = (1<<RXEN);
if (Enable & WRITE) UCSRB |= (1<<TXEN);
if (Interupts & READ) UCSRB |= (1<<RXCIE);
if (Interupts & WRITE) UCSRB |= (1<<TXCIE);
UBRRL = (unsigned char) USART_BAUD_SELECT;
}
void usart_writeChar(unsigned char c)
{
while (!(UCSRA & (1<<UDRE))) {}
UDR = c;
while(!(UCSRA & (1<<TXC))) {}
}
void usart_writeString(unsigned char *string) {
while (!(UCSRA & (1<<UDRE))) {}
while ( *string)
usart_writeChar(*string++);
}
int main (void)
{
char s[10];
uint16_t wert_1;
usart_init( (READ + WRITE) , READ);
wert_1=34000;
itoa( wert_1, s, 10);
while(1)
{
usart_writeString(s);
usart_writeString("\r");
warte(20000);
}
}