Beruflich Dokumente
Kultur Dokumente
In addition if you want to enable the receive-complete interrupt you must instead set
USCRB = 0b10011000; //hex 0x98
Bit 7 enables the interrupt, bit 4 enables the receiver, and bit 3 the transmitter.
and scanf are supplied. Floating point conversion support costs you a lot of code
space if you use it. There are also put-string and get-string commands (puts, gets), as
well as putsf, which means put-string-from-flash-memory. The lower-level commands
putchar and getchar are also available. Since there are 32 kbytes of flash memory and
Printf
only 2 kbytes of RAM, you should always store constant strings in flash. In the following
example, the fragment of code prompts the user with a string from flash memory, then
waits for an 's' from the serial port. All quoted literal strings used as parameters are
automatically stored in flash.
putsf("Press s to stop\r");
sflag = 0;
while(sflag!='s') sflag = getchar() ;
The input function, scanf, does not echo characters back to hyperterm. You can do this,
and have a backspace function, by using something similar to this code.
Avoiding Blocking Input in C
Usually you can tolerate a blocking stdio function when it is used for output (e.g. printf)
because you can estimate the length of time the transmission will take and because
embedded applications tend to sent short strings. However, if you are waiting for input
from a user, an input function (e.g. scanf) could wait for a very long time. This will cause
a cooperative multitasking program organization to fail. You can work around this
problem in two fundamentally different ways:
Polled transmit and receive functions. This scheme blocks the cpu while
executing, but is often easier to setup. A demo program shows fairly high-level
string send and receive functions. Another demo program shows one way of
parsing numbers from from an input string.
Interrupt driven transmit and receive functions. This scheme allows the fast cpu to
perfrom other functions while waiting for the slow serial interface. A demo
program shows basic UART transmit and receive interrupt routines for the
AT90S8515 mcu. Note that the 'transmit buffer empty" interrupt is set when the
mcu is reset. This means that you must initialize the message pointer before you
enable interrupts, or you will get garbage sent to the terminal at each reset.
Link: http://instruct1.cit.cornell.edu/courses/ee476/Serialcom/