API UART
Aplikačné rozhranie bloku UART
- UART_Start Enable user module and set parity.
- UART_Stop Disable user module.
- UART_EnableInt Enable both RX and TX interrupts.
- UART_DisableInt Disable both RX and TX interrupts.
- UART_SetTxIntMode Set the source of the Tx interrupt.
- UART_SendData Send byte without checking TX status.
- UART_bReadTxStatus Return status of TX Status register.
- UART_bReadRxData Return data in RX Data register without checking status of character is valid.
- UART_bReadRxStatus Check status of RX Status register.
Príklady použitia
Zdrojový kód jednoduchého povelového interpreteru. Program prijíma znaky z UART a podľa ich významu vykonáva predvolené aktivity.
_main:
mov A,UART_PARITY_NONE ; inicializacia serioveho rozhrania
call UART_Start
M8C_EnableGInt
WaitForData: ; cakanie na prichod znaku
call UART_bReadRxStatus
and A, UART_RX_COMPLETE
jz WaitForData
call UART_bReadRxData ; nacitanie znaku
call UART_SendData ; echo znaku
cmp A,'x' ; skok na aktivitu 'x'
jz state_x
cmp A,'y' ; skok na aktivitu 'y'
jz state_y
jmp WaitForData ; navrat do slucky cakania na novy znak
state_x:
..... ; implementacia aktivity 'x'
jmp WaitForData
state_y:
..... ; implementacia aktivity 'y'
jmp WaitForData