ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 12.06.2025
Просмотров: 8257
Скачиваний: 1
© MCS Electronics, 1995-2007
as the number of bytes in the receive buffer, the receiver will make RTS '1' to signal to the sender, that the buffer is full. The sender will stop sending data. And will continue when the RTS is made '0' again.
The receiver can send data to the sender and it will check the CTS pin to see if it may send data.
In order to work with CTS-RTS, you need both a serial input buffer, and a serialoutput buffer. So use both CONFIG SERIALIN1 and CONFIG SERIALOUT1 to specify the buffers. The CTS-RTS can only be configured with the CONFIG SERIALIN1 statement.
The thresholds are needed for high baud rates where it will take some time to react on a CTS-RTS.
You need to experiment with the thresholds but good start values are 80%full, and 20% empty.
ASM
Routines called from MCS.LIB :
_GotChar1. This is an ISR that gets called when ever a character is received. When there is no room for the data it will not be stored.
So the buffer must be emptied periodic by reading from the serial port using the normal statements like INKEY() and INPUT.
Since URXC1 interrupt is used by _GotChar1, you can not use this interrupt anymore. Unless you modify the _gotchar1 routine of course.
See also
CONFIG SERIALOUT1 , ISCHARWAITING , CLEAR
Example
'----------------------------------------------------------------------------- |
|
------------ |
: rs232buffer1.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: shows the difference between normal and buffered |
' |
serial INPUT |
'micro |
: Mega161 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'-----------------------------------------------------------------------------
------------
$regfile = "m161def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 4000000 |
|
frequency |
' use baud rate |
$baud = 6900 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
' Works only for chips with 2 UARTS
'first compile and run this program with the line below remarked
page -376-
© MCS Electronics, 1995-2007
Config Serialin1 = Buffered , Size = 20
'dim a variable
Dim Na As String * 10
Open "com1:" For Binary As #1
'the enabling of interrupts is not needed for the normal serial mode 'So the line below must be remarked to for the first test
Enable Interrupts
Print "Start" |
||
Do |
'was there a char? |
|
If Ischarwaiting(#1) = 1 Then |
||
na$ = Waitkey(#1) |
'print it |
|
Print #1 , Na |
||
End If |
||
Wait 1 |
'wait 1 |
second |
Loop |
||
Close #1 |
||
'You will see that when you slowly enter characters in the terminal emulator 'they will be received/displayed.
'When you enter them fast you will see that you loose some chars
'NOW remove the remarks from line 11 and 18 'and compile and program and run again
'This time the chars are received by an interrupt routine and are
'stored in a buffer. This way you will not loose characters providing that 'you empty the buffer
'So when you fast type abcdefg, they will be printed after each other with the '1 second delay
'Using the CONFIG SERIAL1=BUFFERED, SIZE = 10 for example will 'use some SRAM memory
'The following internal variables will be generated :
'_Rs_head_ptr1 |
BYTE , a pointer to the location |
of the start of the buffer |
'_Rs_tail_ptr1 |
BYTE , a pointer to the location |
of tail of the buffer |
'_RS232INBUF1 BYTE ARRAY , the actual buffer with |
the size of SIZE |
|
CONFIG SERIALOUT
Action
Configures the hardware UART to use a buffer for output
Syntax
CONFIG SERIALOUT = BUFFERED , SIZE = size
Remarks
size |
A numeric constant that specifies how large the output buffer should be. |
The space is taken from the SRAM. |
|
The following internal variables will be used when you use CONFIG SERIALOUT
_RS_HEAD_PTRW0 , byte that stores the head of the buffer _RS_TAIL_PTRW0 , byte that stores the tail of the buffer
page -377-