-
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules