📄 usart_tx_irda2.pbas
字号:
'*******************************************************************************
' Microcontroller:
' P16F877A
'
' Project name:
' USART_Tx_IrDA2 (Transmit-side code for IrDA2 module test)
'
' Done by:
' Vladimir Petrovic
'
' Description:
' This project is designed to work with PIC 16F877A; with minor adjustments,
' it should work with any other PIC MCU that has the USART device.
'
' In this example a IR wirless connection between two PIC MCUs is demonstrated.
' For this purpose, the mikroElektronika's IrDA2 board with Microchip's MCP2120
' IrDA decoder /encoder device is used. One MCU acts as sender, the other one
' beging the receiver device.
'
' Please note that MCP2120 is only an decoder /encoder device which is
' IrDA-compatible on hardware level. Therefore, the IrDA2 module can only be
' used for an inter-connection between two MCUs and NOT with IrDA port on
' the PC (for this purpose, the IrDA module with MCP2155 chip can be used).
'
' Take care about the baud rate settings for the IrDA2 module! In this example,
' a 3.6864 MHz crystal oscillator is used on IrDA2 module, and the baudrate is
' set for 19200 Bps with jumpers B0 and B2 connected, and jumper B1
' disconnected.
'
' Test configuration:
' P16F877A @ 04.0000MHz
' IrDA2 module @ 3.6864MHz
'*******************************************************************************
program USART_Tx
dim outTxt as char[17]
dim ind as byte
dim rxIndex as byte
' Global init procedure
sub procedure initAll
ind = 0
rxIndex = 1
outTxt = "mikroelektronika"
TRISB = 0
Lcd_Init(PORTB) ' Init LCD
Lcd_Cmd(LCD_CLEAR)
Lcd_Cmd(LCD_CURSOR_OFF)
USART_init(19200) ' Init USART
end sub
' Change outTxt to see if transmit is OK
sub procedure shiftOut
select case ind
case 0
outTxt = "aaaa@#"
inc(ind)
case 1
outTxt = "bbbb@#"
inc(ind)
case 2
outTxt = "cccc@#"
inc(ind)
case 3
outTxt = "dddd@#"
inc(ind)
case else
outTxt = "eeee@#"
ind = 0
end select
end sub
' Transmit txOut array through USART
sub procedure txOut
rxIndex=1
while (byte(outTxt[rxIndex])<>35) ' ASC(35) = "#" is used
USART_Write(outTxt[rxIndex]) ' as termination char
inc(rxIndex)
wend
end sub
' Update LCD to see what's being sent
sub procedure updateLcd_Tx
LCD_Out(1,1,"Sent:")
LCD_Out(2,1,outTxt)
end sub
' *****************************************************************************
main:
initAll
while true
shiftOut
txOut
updateLcd_Tx
Delay_ms(333)
wend
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -