#define _TOTAL_LIGHTS 5
for(i=0; i<_TOTAL_LIGHTS; i++)
{
if (PORTD.[i] == 1)
{
PORTC.[i] = 1;
}
else
{
PORTC.[i] = 0;
}
}
unsigned char BitMask[]= {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
define _TOTAL_LIGHTS 5
for(i=0; i<_TOTAL_LIGHTS; i++)
{
if ( (PORTD & BitMask[i]) >= 1) // Check if bit i is set
{
PORTC|= BitMask[i]; // Set bit i
}
else
{
PORTC&= ~BitMask[i]; // Clear bit i
}
}
}
Try this.How can i access port bits using loop like the below ?
Code:#define _TOTAL_LIGHTS 5 for(i=0; i<_TOTAL_LIGHTS; i++) { if ((PORTD&(1<<i) )!= 0) { PORTC| = (1<<i); } else { PORTC&(~(1<<i)); } }
But in mikroC , its not workingTry this.
Should work.
PORTC| = (1<<i);
invalid expression
PORTC |= (1<<i);
void main() {
#define _TOTAL_LIGHTS 5
int i;
for(i=0; i<_TOTAL_LIGHTS; i++)
{
if (PORTD&(1<<i))
{
PORTC |= (1<<i);
}
else
{
PORTC &= (~(1<<i));
}
}
}
void main() {
TRISE = 0;
TRISD=0;
TRISC=0;
PORTD=1;
PORTC=0;
for(i=0; i<_TOTAL_LIGHTS; i++)
{
if (PORTD&(1<<i))
{
PORTC |= (1<<i);
}
else
{
PORTC &= (~(1<<i));
}
}
}
Here is my projectAttach your project, please. I'm using the same compiler.
Try PORTC=PORTC|(1<<i);
after BIGDOG pointed out the mistake in code , i corrected it , now its compiling but its not working in proteusBut it is compiling well. Whats the problem?
TRISD=0;
TRISC=0;
In the attached code, both ports are initialised with 0!
Write TRISC=1 to make PORTC input
using 40pin DIPAnother thing to note : - PORTD is not present on 28pin version of 16F876A. It is present on 40 pin version
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?