Сообщение от
Anykey
Еще вопрос, как к портам IO обращаться?
Можно ли как в PIC микроконтроллерах (или архитектуры разные)?
sdcc calls i/o ports "special function registers". You can assign an sfr to each i/o port you need and then write or read from them as if they are regular variables:
Код:
__sfr __at 0x1f IO8; // 8-bit i/o port at 0x1f
__sfr __banked __at 0xfbfe IO16; // 16-bit i/o port at 0xfefe
void main(void)
{
volatile unsigned char a;
a = IO8; // read port IO8
IO8 = 100; // write port IO8
a = IO16; // read port IO16
IO16 = 200; // write port IO16
}
The translated asm "zcc +zx -vn -a -SO3 -clib=sdcc_iy --max-allocs-per-node200000 zzzz.c --c-code-in-asm"
(An issue was fixed today that affects this code; make sure you are running a nightly build from May 24 or later)
Код:
;zzzz.c:9: a = IO8; // read port IO8
in a,(_IO8)
ld (ix-1),a
;zzzz.c:10: IO8 = 100; // write port IO8
ld a,0x64
out (_IO8),a
;zzzz.c:12: a = IO16; // read port IO16
ld a,+((_IO16) / 256)
in a,(((_IO16) & 0xFF))
ld (ix-1),a
;zzzz.c:13: IO16 = 200; // write port IO16
ld a,0xc8
ld bc,_IO16
out (c),a
Unfortunately sdcc has a known bug when reading i/o ports into a global variable.
This:
Код:
__sfr __at 0x1f IO8; // 8-bit i/o port at 0x1f
volatile unsigned char a;
void main(void)
{
a = IO8; // read port IO8
}
Leads to a fatal compiler error. To read into a global variable you must read into a local first and then copy that local to the global.
You can also do port i/o through function calls, see z80.h. All port i/o done through these function calls is 16-bit.
The z80 i/o space is 16-bits but usually the bottom 8-bits select a device and most devices operate decoding the bottom 8-bits only. However some devices will use the bottom 8 bits to identify themselves as i/o target and then the top 8 bits to select a particular register. The z80's 16-bit i/o instructions (inir, indr, otir, otdr) support that view.
Можно ли произвольно задавать адрес и биты интерфейса SD-card?
You can, but if you are making this for the zx you have to consider ports taken by the zx itself and its common peripherals. The basic zx spectrum has the ULA mapped to all even port addresses so you must avoid those for your device. Kempston joystick is at 0x1f, the sound chip at other address (0xbffd, 0xfffd) and the russian machines will have their own ports too. So you really have to try to pick i/o addresses that will not interfere with ones already used.