PDA

View Full Version : Insfr and outsfr sample code in C


Philip
11-20-07, 01:52 AM
I will be grateful if you give me a sample code to desmostrate
the use of insfr and outsfr command using Port 4 and Port 5 of
NMIX0016 in c. Thanks

nmitech
11-20-07, 09:03 AM
Use the predefined peek(adr) and poke(adr,data) functions provided in the \CLIB\PEEKPOKE.C library.


#include clib\common51.c
#include clib\syslib51.c
#include clib\peekpoke.c
...
...

#define PORT4 0xE8 /* port 4 */
#define PORT5 0xF8 /* port 5 */

main()
{

/* PEEK(adr) -- read a 16-bit value from address */
peek(adr) unsigned int *adr; { *adr; }

/* POKE(adr,dta) -- write a 16-bit value to address */
poke(adr,dta) unsigned int *adr,dta; { *adr=dta; }

}

Philip
11-20-07, 09:18 AM
Thanks for your reply, but how to write or read, say bit one of port 4 or Port 5, using the peek and poke function or any other function
in C.

Thanks

nmitech
11-20-07, 10:12 AM
how to write or read, say bit one of port 4 or Port 5, using the peek and poke function or any other function



/* PEEKB(0xE8) -- read a 8-bit value from PORT4 */
unsigned int P4.0;
P4.0 = peekb(0xE8) & 0x01; /* return high or low on P4 bit 0 */

/* POKEB(0xF8,0xAA) -- write one's on odd bit of P5 */
pokeb(0xF8,0xAA);


Sorry, PEEKB and POKEB functions are used for read and write 8-bit respectively. Where PEEK & POKE are for 16-bit read & write. For information how to use the function, please see the /* comment lines */ of each function provided in the \CLIB librabry.