Set/Clear one single portpin
Hi Florian,
you can set/clear the data lines this way:
(with bitnum from 0 to 7)
void set_pin(unsigned char bitnum)
{
unsigned char port_val, port_mask = 0x01;
port_val = parport_read_data(base); // read the portlines to port_val
port_val |= (port_mask << bitnum); // set the bit in port_val
parport_write_data(port_val, base); // write back port_val
}
void clear_pin(unsigned char bitnumber)
{
unsigned char port_val, port_mask =0x01;
port_val = parport_read_data(base); // read the portlines to port_val
port_val &= ~(mask << bitnum); // clear the bit in port_val to 1
parport_write_data(port_val, base); // write back port_val
}
Or the same in one line:
Set portline:
parport_write_data(parport_read_data(base)|=(0x1<< bitnum),base);
Clear portline:
parport_write_data(parport_read_data(base)&= ~(0x1<<bitnum),base);
Martin
"base" has to point to the memory maped parallel port
Hi Florian,
make sure that you have initialized the pointer "base" ( base = oleg_fn() ) before you use it.
Check your programm for the correct use of pointers and dereferenced pointers.
Martin