HTEB1
User manual
3.3 SCI
SCI is used here for a simple RS232 (V24) terminal connection. Please use a terminal program like HyperTerm (included in Windows), select Baudrate 9600 Baud, 8 Databits, No Parity and 1 Stopbit (8N1). After connection and setup, hit some keys and you will see a message responding on every keycode sent.
/*
**
**main.c - contains C entry point main()
**This file was generated by HEW IAR Icch8 project generator
**
*/
#include "mydefs.h" |
| // see file for further include | ||
/* some | defines */ |
|
|
|
#define | TIE | 0x80 |
|
|
#define | RIE | 0x40 |
|
|
#define | TE | 0x20 |
|
|
#define | RE | 0x10 |
|
|
#define | MPIE | 0x08 |
|
|
#define | TEIE | 0x04 |
|
|
#define | CK_INT | 0x00 |
|
|
#define | CK_INT_OUT | 0x01 |
|
|
#define | CK_EXT | 0x02 |
|
|
#define | IS_SCI_RDF |
| (SSR & 0x40) |
|
#define | CLEAR_SCI_RDF | SSR = (SSR & ~0x40) | ||
#define | IS_SCI_TX_FREE | (SSR & 0x80) |
| |
#define | V24_BRR(x) | ((unsigned char)(((CPU_CLK+16*x)/32/x) - 1)) | ||
void V24Init (u16 Baudrate) |
| |||
{ |
|
|
|
|
SCR3 = | 0x00; |
|
| // disable all |
SSR = 0x00; |
|
| // clear all errorbits | |
SMR = 0x00; |
|
| // 8N1 + /1 clock | |
BRR = V24_BRR(Baudrate); | // set baud | |||
PMR1 = 0x02; |
|
| // P22 = TxD Output | |
SCR3 = | (TERECK_INT); |
| // Ints und Data disabled, internal clock | |
} |
|
|
|
|
u8 V24NewChar(void) |
|
| // check for new char on V24 | |
{ |
|
|
|
|
if (IS_SCI_RDF) |
|
| // Receive buffer full? | |
{ |
|
|
|
|
return TRUE; |
|
|
| |
} |
|
|
|
|
return | FALSE; |
|
|
|
} |
|
|
|
|
u8 V24GetChar(u8* data) |
| // simple GetChar via V24 | ||
{ |
|
|
|
|
u8 idx; |
|
|
| |
if (IS_SCI_RDF) |
|
| // Receive buffer full? | |
{ |
|
|
|
|
*data | = RDR; |
|
| // yes, get data |
CLEAR_SCI_RDF; |
|
| // clear | |
|
|
|
|
|
Issue 0.2 | Page 39 | 07/2002 |