??? 04/03/04 11:51 Read: times |
#67863 - RE: caliper interface int0 routine Responding to: ???'s previous message |
I have worked on a couple of projects where I had to accumulate a stream of raw serial bits through an interrupt routine into a buffer. Here is some handy code that can manage a "bit buffer" in the internal RAM for up to 256 bits in length. The buffer can be in the indirectly addressed part of the RAM above address 127. These routines are not the most compact and speedy but instead designed for modularity and re-usability.
;-=-=-=-=-=-=-= ; BITS_SEG SEGMENT BIT BUFF_SEG SEGMENT IDATA CODE_SEG SEGMENT CODE ; ;-=-=-=-=-=-=-= ; RSEG BITS_SEG RAW_BIT: DBIT 1 ; raw handling bit ; ;-=-=-=-=-=-=-= ; RSEG BUFF_SEG BIT_BUF: DS 32 ; raw bit buffer ; ;-=-=-=-=-=-=-= ; RSEG CODE_SEG ;-=-=-=-=-=-=-= ;NAME: GET_BIT ; Used to fetch a bit from the raw bit buffer ; into the BIT_RAW bit. Entry R0 is the bit number ; that is preserved. ;-=-=-=-=-=-=-= GET_BIT: MOV A, R0 ; save R0 on stack PUSH ACC ; save entry bit number ; RR A ; make byte offset number RR A RR A ANL A, #01FH ; mask the byte number ADD A, #BIT_BUF ; make pointer to byte MOV R0, A ; save buffer offset into R0 POP ACC ; get copy of bit number PUSH ACC ANL A, #007H ; isolate 0-7 number CALL BIT_MSK ; convert bit # to a mask ANL A, @R0 ; get current bit state JNZ GET_BIT1 ; for return of a 1 bit GET_BIT0: CLR RAW_BIT ; clear RAW_BIT for 0 bit state JMP GET_BIT2 ; GET_BIT1: SETB RAW_BIT ; set RAW_BIT for 1 bit state GET_BIT2: POP ACC ; restore entry R0 MOV R0, A RET ; exit with RAW_BIT as bit state ;-=-=-=-=-=-=-= ;NAME: PUT_BIT ; Used to put a bit into the raw bit buffer ; from the RAW_BIT bit. Entry R0 is the bit number ; that is preserved. ;-=-=-=-=-=-=-= PUT_BIT: MOV A, R0 PUSH ACC ; save entry bit number ; RR A ; make byte offset number RR A RR A ANL A, #01FH ; mask the byte number ADD A, #BIT_BUF ; make pointer to byte MOV R0, A ; save buffer offset into R0 POP ACC ; get copy of bit number PUSH ACC ANL A, #007H ; isolate 0-7 number CALL BIT_MSK ; convert bit # to a mask JB RAW_BIT, PUT_BIT1 ; save a "1" bit ; PUT_BIT0: CPL A ; make the NOT of the bit mask ANL A, @R0 ; clear bit in buffer byte JMP PUT_BIT2 ; PUT_BIT1: ORL A, @R0 ; set bit in buffer byte PUT_BIT2: MOV @R0, A ; store new bit value to buffer ; POP ACC MOV R0, A ; restore entry R0 RET ; exit with bit set ;-=-=-=-=-=-=-= ;NAME: BIT_MSK ; Used to convert a bit number to a byte mask ; Entry A is the 0-7 bit number ; Exit A is the bit mask ;-=-=-=-=-=-=-= BIT_MSK: INC A MOVC A, @A+PC RET ; DB 00000001B ; Bit 0 <- 0 DB 00000010B ; Bit 1 <- 1 DB 00000100B ; Bit 2 <- 2 DB 00001000B ; Bit 3 <- 3 DB 00010000B ; Bit 4 <- 4 DB 00100000B ; Bit 5 <- 5 DB 01000000B ; Bit 6 <- 6 DB 10000000B ; Bit 7 <- 7 Note I also have some similar routines that can manage a bit buffer in XRAM for up to 64K bits (a 8K byte XRAM buffer). Please contact if interested. Michael Karas |
Topic | Author | Date |
caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper Edgar: | 01/01/70 00:00 | |
RE: caliper Edgar: | 01/01/70 00:00 | |
RE: caliper Edgar: | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface int0 routine | 01/01/70 00:00 | |
RE: caliper interface working![]() | 01/01/70 00:00 |