??? 08/05/04 14:43 Read: times |
#75478 - RE: Memory mapped I/O hassle Responding to: ???'s previous message |
There's a few solutions you may wish to consider: 1/ Use a device like a 74hc259 which is a addressable latch. what you end up with is 1 bit per byte for your outputs. Assuming you put AD0 to the data bit of the 74hc259 and A0..2 to the address pins of the 74hc259 you will get this: org 8000h ;assuming you put the i/o here... output1 ds 1 output2 ds 1 output3 ds 1 ... ... ; ; set a bit in the memory mapped i/o ; A has the output# to set set_memio_bit: mov dptr,#output1 add a,dpl mov dpl,a mov a,0 addc a,dph mov dph,a mov a,#1 ;make this value 0 to reset it movx @dptr,a ret I normally like to stay away from memory mapped i/o as it means I have to use ports pins for the bus (most micros I use have inbuilt flash). So I use latched shift registers (74HC595) and use port pins to shift data from memory out. This is not a fast as the mem mapped i/o as you have to refresh the HC595 each time you want to update the outputs - in practice this may not be an issue as you can update at the end of your logic solving. ie: (read inputs->process control logic->update outputs) this is the way most industrial PLCs operate. My last suggestion is to write bit set/clear routines that operate on ram memory that gets copied to the outputs. bit_mask: db 1,2,4,8,16,32,64,128 ; ; bit to set is in A ; set_bit: push a anl a,#07h ;get bit# 0..7 mov dptr,#bit_mask movc a,@a+dptr ;get the bit mask mov b,a ;into B pop a rr a rr a rr a ;get rid of the bit offset anl a,#1fh ;mask byte offset mov r0,#io_buff add a,r0 mov r0,a ;r0->io_buff[byte offset] mov a,@r0 ;read the current value orl a,b ;set the required bit mov @r0,a ret ; ; copy the io_buff to the io registers ; ...... You also have a matching bit_reset routine! As your mem mapped i/o registers are usually write only, you must keep a copy in ram so you can set/reset individual bits. This may seem like a lot of hard work but decoupling the control of the i/o from your other code means you can choose different output options without having to do changes throughout your code. The code ends up like this: MOTOR1 equ 0 MOTOR2 equ 1 LAMP1 equ 2 LAMP2 equ 3 ; ; turn the alert lamp on ; mov a,#LAMP2 call set_bit ; ; stop the pump ; mov a,#MOTOR1 call reset_bit My personal choice is to use the HC595 shift registers and I use C for most of my projects nowadays - it saves a hell of a lot of time in development. |
Topic | Author | Date |
Memory mapped I/O hassle | 01/01/70 00:00 | |
RE: Memory mapped I/O hassle | 01/01/70 00:00 | |
Problem defenition - Erik | 01/01/70 00:00 | |
RE: Memory mapped I/O hassle | 01/01/70 00:00 | |
Automatic up I/O update - Russell | 01/01/70 00:00 | |
RE: Memory mapped I/O hassle | 01/01/70 00:00 | |
RE: Memory mapped I/O hassle | 01/01/70 00:00 | |
RE: Memory mapped I/O hassle | 01/01/70 00:00 | |
RE: Memory mapped I/O hassle | 01/01/70 00:00 | |
RE: Memory mapped I/O hassle | 01/01/70 00:00 | |
Syntax - Anders, Rob, Charles | 01/01/70 00:00 | |
RE: Syntax - Anders, Rob, Charles | 01/01/70 00:00 | |
Problem solved - Russell | 01/01/70 00:00 | |
RE: Syntax - Anders, Rob, Charles | 01/01/70 00:00 | |
RE: Syntax - Anders, Rob, Charles | 01/01/70 00:00 | |
RE: Memory mapped I/O hassle | 01/01/70 00:00 | |
Thread can close happily![]() | 01/01/70 00:00 |