??? 12/29/04 07:50 Modified: 12/29/04 07:55 Read: times |
#84021 - binary and defines Responding to: ???'s previous message |
hi,
Sam Sudonimm said:
I agree that the binary is harder to read, but it sure is tempting to use it, especially for those control SFRs made up of somewhat unrelated bits. Before start programming all the project, set and make defines for what bits of SFRs and their combinations mean. Something like that: ;SCON definitions ; bit 7 = "SM0" = Serial Port Mode bit 0 ; bit 6 = "SM1" = Serial Port Mode bit 1 UART_MODE_SHIFT EQU 0 ; shift register UART_MODE_8VAR EQU (1 SHL 6) ; 8-bit variable bitrate UART_MODE_9FIX EQU (2 SHL 6) ; 9-bit fixed bitrate UART_MODE_9VAR EQU (3 SHL 6) ; 9-bit variable bitrate ; bit 5 = "SM2" = Serial Port Mode bit 2 UART_MODE_MULTICOM EQU (1 SHL 5) ; bit 4 = "REN" = Reception Enable bit UART_RX_ENA EQU (1 SHL 4) ; bit 3 = "TB8" = Transmitter bit 8 UART_MARK_ADDRESS EQU (1 SHL 3) ; bit 2 = "RB8" = Receiver bit 8 UART_GOT_ADDRESS EQU (1 SHL 2) ; bit 1 = "TI" = Transmit Interrupt flag UART_SEND_DONE EQU (1 SHL 1) ; bit 0 = "RI" = Receive Interrupt flag UART_GET_NEW EQU 1Then you may easy manipulate with UART, like here: ; setup UART to 11-bit mode ; with multiprocessor communication and receiver enabled MOV SCON,#(UART_MODE_9VAR OR UART_MODE_MULTICOM OR UART_RX_ENA)Next example below may be very useful when SFRs is not bit addressable. SCON is bit addressable, anyway assume that it is not. Then we may do next: ;send master network address then data byte ORL SCON,#(UART_MARK_ADDRESS) ; setb TB8 MOV SBUF,#MASTER_ADDR WAIT_SEND1: ; jnb TI,$ MOV A,SCON ANL A,#(UART_SEND_DONE) JZ WAIT_SEND1 ; send data byte ANL SCON,#NOT(UART_MARK_ADDRESS OR UART_SEND_DONE) ; clr TB8 and clr TI MOV SBUF,#DATA_BYTE WAIT_SEND2: ; jnb TI,$ MOV A,SCON ANL A,#(UART_SEND_DONE) JZ WAIT_SEND2 ANL SCON,#NOT(UART_SEND_DONE) ; clr TIIndeed it requires some additional work to define these bits` combinations. But once it has been done you will be able to drop binary notations for most SFRs easy. And your code will be good readable even without huge comments. Regards, Oleg |
Topic | Author | Date |
Timer 2 baud generation problem | 01/01/70 00:00 | |
avoid binary, it is difficult to read | 01/01/70 00:00 | |
That was it! | 01/01/70 00:00 | |
how I used to use binary | 01/01/70 00:00 | |
Another approach | 01/01/70 00:00 | |
binary and defines | 01/01/70 00:00 | |
yet another![]() | 01/01/70 00:00 |