| ??? 06/01/06 13:55 Modified: 06/01/06 14:34 Read: times |
#117505 - formatted Responding to: ???'s previous message |
It is also a good practice to use symbols - just as constants in high level language (HLL - e.g. C).
Also it is a good idea to preserve the register area (at least 0-7 for register bank 0) for future use. Also, address 8 is the first byte which would be A hardware problem: you write your output value into P3 where you read from your input value, that would collide. You also need some strobe to let the PC know the output value is written. Anyway, I'd recommend you later to connect the PC via serial port. You also made the (common) error of forgetting the '#' several times (underlined). Some of the changes, highlighted. Not tested nor comments corrected, that's up to you. Do you have a '51 simulator?
DSEG AT 30h ;this tells the compiler to start placing data from 30h
NrValues EQU 8 ;const nrvalues=8;
OldValues: DS NrValues ;reserve space for OldValues
RPin: DS 1 ;reserve space for RPin (a counter)
AStore: DS 1 ;reserve space where A will be stored temporarily
CSEG ;now we tell the compiler that we are going to write code
ORG 0
MOV P3,#255 ;Making P3 Output Port
MOV OldValues+0,#255 ;Initilising memory locations for storing output
MOV OldValues+1,#255 ;from the 8 latches
MOV OldValues+2,#255 ;and loading them with initial values
MOV OldValues+3,#255 ;which indicate all signals are low
MOV OldValues+4,#255
MOV OldValues+5,#255
MOV OldValues+6,#255
MOV OldValues+7,#255
;three nested loops needed: one for the bits, one for the 8 bytes, one which repeats the all infinitely
LOOP:
MOV R0,#OldValues+7 ;location R0 is Rlatch
POLL:
MOV A,R0
ADD A,#-OldValues ;calculate latch Nr
MOV P1,A ;set the latch Nr for the decoder
MOV RPin,#8 ;there are 8 bits in a byte
MOV A,P3
ANL A,@R0 ;ANDing A with the locations 8 to 1 which will store CPL of P3
CHKPIN: RLC A ;Get the Pins thatwent form LOW to HIGH
JC WRITE
GETBAK: DJNZ RPin,CHKPIN
MOV A,P3 ;Since the output is latched, it has not changed since last time
CPL A
MOV @R0,A ;Moving the data of the respective latches to the respective registers
; following line not needed if it is initialised at the beginning of the loop
; MOV 10,#8 ;ReInitialising Rpin value as 8 for next loop
;following line replaced by 2 lines as R0 won't point into 1..8 any more
; DJNZ R0,POLL
DEC R0
CJNE R0,#OldValues-1,POLL
;again no need
; MOV R0,#8 ;ReInitilising value of Rlatch as 8 for next loop
JMP LOOP ;repeat infinitely this loop
WRITE:
MOV AStore,A ;storing the value of A in 20 for further use
MOV A,R0
ADD A,R0 ;Adding contents of R0 to A seven more times
ADD A,R0 ;I read that using MUL always clears the flag
ADD A,R0 ;And I dont want to do that
ADD A,R0
ADD A,R0
ADD A,R0
ADD A,R0
ADD A,10
MOV P3,A
MOV A,AStore ;Returning A its original Value
JMP GETBAK
END
JW |
| Topic | Author | Date |
| Another standard problm in Assembly Lang | 01/01/70 00:00 | |
| many ways | 01/01/70 00:00 | |
| lookup table? | 01/01/70 00:00 | |
| yup | 01/01/70 00:00 | |
| hummmm | 01/01/70 00:00 | |
| algorithm! | 01/01/70 00:00 | |
| OK | 01/01/70 00:00 | |
| forget the lookup table | 01/01/70 00:00 | |
| no language dependency | 01/01/70 00:00 | |
| abstraction | 01/01/70 00:00 | |
| Direct Test | 01/01/70 00:00 | |
| did you take it at Grossmont? | 01/01/70 00:00 | |
| Wrong mark | 01/01/70 00:00 | |
| just wonder | 01/01/70 00:00 | |
| homework | 01/01/70 00:00 | |
| No not homework | 01/01/70 00:00 | |
| Bit 3? | 01/01/70 00:00 | |
| Depends | 01/01/70 00:00 | |
| reverse bit numbering | 01/01/70 00:00 | |
| reverse bit numbering: mirror | 01/01/70 00:00 | |
| It's logical... | 01/01/70 00:00 | |
| Thks | 01/01/70 00:00 | |
| Unconventional | 01/01/70 00:00 | |
| Yes, now I know | 01/01/70 00:00 | |
| oops | 01/01/70 00:00 | |
| Radix notation | 01/01/70 00:00 | |
| Why "Standard"? | 01/01/70 00:00 | |
| give it in C | 01/01/70 00:00 | |
| Finally Some Code | 01/01/70 00:00 | |
| formatted | 01/01/70 00:00 | |
| Much nicer | 01/01/70 00:00 | |
| OH boy | 01/01/70 00:00 | |
| No I havent | 01/01/70 00:00 | |
| edited | 01/01/70 00:00 | |
| No Prob | 01/01/70 00:00 | |
| Yes. | 01/01/70 00:00 | |
| try & ask | 01/01/70 00:00 | |
| OK | 01/01/70 00:00 | |
| Many Questions | 01/01/70 00:00 | |
| Q&A | 01/01/70 00:00 | |
| Man! That just made my day! | 01/01/70 00:00 | |
| Revised Code | 01/01/70 00:00 | |
hi abhishek!!! | 01/01/70 00:00 |



