Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hitech C - controlling one output pin (easy question)!

Status
Not open for further replies.

cowana

New Member
I'm programming a PIC16F722 using the Hitech C compilers.

I am trying to control the output pins on the PIC seperatly - ie not using PORTA = ....

However, while RA0=1 will turn the first output on, sending RA1=1 will turn 0 off, and 1 on. Is it possible to have both outputs on at one time?

I'm sure I'm overlooking something simple.

Thanks

Andrew
 
The PIC will always write a byte at a time. It is up to you or the compiler to fake the bit write.
You can do it with any compiler by keeping a shadow copy of the PORT/LAT register. Make the change to the desired bit in the shadow copy and write it to the PORT.

A bit less portable but you can use bit fields for the shadow register for some compilers including HiTech.

Code:
[FONT=Verdana]
struct 
{ 
// MSB 
unsigned data : 4; 
unsigned rw : 1; 
unsigned enable : 1; 
unsigned cmd :1;
unsigned unused : 1;
// LSB 
} lcdShadow; [/FONT]

With C18 a union can be used to do a similar thing but directly on the port itself. No shadow.
 
Last edited:
I'm programming a PIC16F722 using the Hitech C compilers.

I am trying to control the output pins on the PIC seperatly - ie not using PORTA = ....

However, while RA0=1 will turn the first output on, sending RA1=1 will turn 0 off, and 1 on. Is it possible to have both outputs on at one time?

I'm sure I'm overlooking something simple.

Thanks

Andrew

Make sure that you have configured RA0, RA1 as digital pins in the ANSELx registers.
Pins configured as analog inputs will read as '0'. When you set RA1, the PORTA register is read first and RA1 is then set. If you haven't configured RA0 as digital pin, it reads as '0'. As a consequence, when you set RA1, RA0 will be cleared - as you described.
 
  • Like
Reactions: 3v0
Status
Not open for further replies.

Latest threads

Back
Top