Уважаемые! Объясните пжалста, как сделать программный СОМ на произвольные ноги?
Ну или хотя бы сцылку в меня киньте штоле))
COM порт
Сообщений 1 страница 5 из 5
Поделиться12012-02-27 00:24:53
Поделиться22012-02-27 06:23:02
Bascom
F1
SOFTWARE UART
получаем:
Using the UART: SOFTWARE UART
The previous examples used the hardware UART. That means the compiler uses the internal UART registers and internal hardware (RxD(0) and TxD(0)) of the AVR. If you don’t have a hardware UART you can also use a software UART.
The Bascom compiler makes it easy to “create” additional UART’s. Bascom creates software UART’s on virtually every port pin.
Remember that a software UART is not as robust as a hardware UART, thus you can get timing problems if you have lots of interrupts in your program.
For this example we use micro controller pins portc.1 and portc.2.
Connect portc.1 to TxD and portc.2 to RxD see the schematic above.
Change the $regfile and program this example:
$regfile = "m88def.dat"
$crystal = 8000000
$baud = 19200
Dim B As Byte
Waitms 100
'Open a TRANSMIT channel for output
Open "comc.1:19200,8,n,1" For Output As #1
Print #1 , "serial output"
'Now open a RECEIVE channel for input
Open "comc.2:19200,8,n,1" For Input As #2
'Since there is no relation between the input and output pin
'there is NO ECHO while keys are typed
Print #1 , "Press any alpha numerical key"
'With INKEY() we can check if there is data available
'To use it with the software UART you must provide the channel
Do
'Store in byte
B = Inkey(#2)
'When the value > 0 we got something
If B > 0 Then
Print #1 , Chr(b) 'Print the character
End If
Loop
Close #2 'Close the channels
Close #1
End
After you have programmed the controller and you connected the serial cable, open the terminal emulator by clicking on in Bascom.
You should see the program asking for an alphanumerical input, and it should print the input back to the terminal.Поделиться32014-02-09 21:29:50
Доброго времени суток!
Ситуация: использую программный уарт. мастер отправляет запрос printbin'ом слейвам по очереди, у каждого слейва (4шт) - свой идентификатор, на который он откликается.
Ответ читаю inputbin'ом. Проблема в том, что, если слейв отключен, то программа мастера висит на inputbin'е и не реагирует на прерывание таймера0, который должен перевести программу на нужную метку для опроса следующего слейва (этакий таймаут)
Естественно, прерывания разрешены.
Поделиться42014-02-09 21:46:12
"$timeout = 1000" команда (к примеру) не помогает?
Поделиться52014-02-09 22:17:59
Да-да-да, как раз хотел отписаться, что победил именно с помощью $timeout = 10000
Я читал про нее в справке изначально, но смутило описание:
Enable timeout on the hardware UART 0 and UART1.
Потому и начал городить огород с таймером, думал, на софтовом уарте не работает, ан нет, работает!)
RDW, спасибо!