Mikroelektronika MIKROE-724 データシート

ページ / 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
629
Library Example
This example demonstrates simple data exchange via UART. If MCU is connected to the PC, you can test the example 
from the mikroBasic PRO for dsPIC30/33 and PIC24 USART communication terminal, launch it from the drop-down 
menu 
Tools › USART Terminal or simply click the USART Terminal Icon 
.
Copy Code To Clipboard 
program UART1
dim uart_rd as byte
main:
  ADPCFG = 0xFFFF                         ‘ Configure AN pins as digital
  UART1_Init(9600)                        ‘ Initialize UART module at 9600 bps
  Delay_ms(100)                           ‘ Wait for UART module to stabilize
  
‘    U1MODE.ALTIO  =  1        ‘  un-comment  this  line  to  have  Rx  and  Tx  pins  on  their 
alternate
      ‘ locations. This is used to free the pins for other module, namely the SPI.
  UART1_Write_Text(“Start”)
  UART1_Write(10)
  UART1_Write(13)
  while TRUE                              ‘ Endless loop
    if (UART1_Data_Ready() <> 0) then     ‘ If data is received,
      uart_rd = UART1_Read()              ‘   read the received data,
      UART1_Write(uart_rd)                ‘   and send data via UART
    end if
  wend
end.