sahr
Newbie level 2
Hi, i am starting a project useing pic18 , i'm at the beginnig.
I use in proximity sensor (GP2Y0A21YK0F).
I have this code:
I need add a few lines in the code, when i use RA0 (TRIS RA) as outpot and RA5 as input (RA5=sensor)
Which means, when the sensor is activated (PORT RA5=1) then input RA0=0 (PORT RA0) else RA0=1.
For example:
Someone can help me?
Thx.
I use in proximity sensor (GP2Y0A21YK0F).
I have this code:
Code:
#include <p18f8722.h>
#pragma config OSC=HS // high speed oscillator
#pragma config WDT=OFF // watch dog off
void main()
{
TRISA=0xff; // port A input
TRISD=0x00; // port D output
PORTD=0x00; // port lights off
PORTA=0x00;
MEMCONbits.EBDIS=1; // make port d digital
ADCON0=0b00001001;
// (00) unimplemented (0000) channel AN0 (0)don't start yet (1) turn on analog to digital module, see page 270
ADCON1=0b00000000;
// (00) unimplemented (00) using AVDD and AVSS (0000) A/D port bits, see page 271
ADCON2=0b1000000;
// (0) left justified (0) unimplemented (000) 0 TAD (010) FOSC/32, see page 272
while(1)
{
ADCON0bits.GO_DONE=1; // starts conversion
while(ADCON0bits.GO_DONE==1); // wait, it's converting
PORTD=ADRESH; // this is outise of the while loop
}
}
Which means, when the sensor is activated (PORT RA5=1) then input RA0=0 (PORT RA0) else RA0=1.
For example:
Code:
void main ()
{
TRISAbits.TRISA0 = 0; // PORTA IS OUTPUT
TRISBbits.TRISB0 = 1; // PORTB IS INPUT
while (1) // INFINITY WHILE
{
if (PORTBbits.RB0==1)
{
PORTAbits.RA0=0;
}
else
{
PORTAbits.RA0=1;
}
}
}
Thx.