API UART: Rozdiel medzi revíziami
Riadok 5: | Riadok 5: | ||
== Aplikačné rozhranie bloku UART == | == Aplikačné rozhranie bloku UART == | ||
− | + | void UART_Start(BYTE bParity) Enable user module and set parity. | |
− | + | void UART_Stop(void) Disable user module. | |
− | + | void UART_EnableInt(void) Enable both RX and TX interrupts. | |
− | + | void UART_DisableInt(void) Disable both RX and TX interrupts. | |
− | + | void UART_SetTxIntMode(BYTE bTxIntMode) Set the source of the Tx interrupt. | |
+ | void UART_SendData(BYTE bTxData) Send byte without checking TX status. | ||
+ | BYTE UART_bReadTxStatus(void) Return status of TX Status register. | ||
+ | BYTE UART_bReadRxData(void) Return data in RX Data register without checking status of character is valid. | ||
+ | BYTE UART_bReadRxStatus(void) Check status of RX Status register. | ||
== Príklady použitia == | == Príklady použitia == |
Verzia zo dňa a času 23:39, 27. máj 2010
Aplikačné rozhranie bloku UART
void UART_Start(BYTE bParity) Enable user module and set parity. void UART_Stop(void) Disable user module. void UART_EnableInt(void) Enable both RX and TX interrupts. void UART_DisableInt(void) Disable both RX and TX interrupts. void UART_SetTxIntMode(BYTE bTxIntMode) Set the source of the Tx interrupt. void UART_SendData(BYTE bTxData) Send byte without checking TX status. BYTE UART_bReadTxStatus(void) Return status of TX Status register. BYTE UART_bReadRxData(void) Return data in RX Data register without checking status of character is valid. BYTE UART_bReadRxStatus(void) 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