qatar.engineer
Junior Member level 1
portbbits.rb0
hi
i write this program to read from sensor and display output on lid but when i programed my pic and but it in the circuit it is either always on or it is off so what should i do here is my program
#include <p18f4520.h>
#include <stdio.h>
#include <delays.h>
#pragma config WDT = OFF
void delay_ms(long t);
//unsigned int count;
int count1;
void main (void)
{
TRISD=0;
TRISC=1; is input and output from sensor is connected to it
TRISA=0;
//PORTC=0;
//LATA=0;
while(1)
{
//PORTBbits.RB0= 0; //portb0 is input
PORTDbits.RD0=0; portd is output and intput to sensor
//LATC=1; //porta0 is output
Delay1KTCYx(1); //wait for 1ms
//PORTBbits.RB0 =1;
PORTDbits.RD0=1;
Delay1KTCYx(1); //wait for 1ms
PORTDbits.RD0=0;
//PORTBbits.RB0 =0;
while(LATC==1)
{
//if(LATA==0)
// printf("error\n");
//else
//{
count1++;
// PORTC=count1;
PORTA=0xFF;
//printf("correct\n");
//}
while(LATC==1)
{
if(LATC==1)
{
count1++;
// PORTC=count1;
PORTA=0xFF;
//printf("correct again\n");
}
}
}
if(LATC==0)
{
//PORTC=0;
PORTA=0x00;
//printf("end\n");
}
}
}
hi
i write this program to read from sensor and display output on lid but when i programed my pic and but it in the circuit it is either always on or it is off so what should i do here is my program
#include <p18f4520.h>
#include <stdio.h>
#include <delays.h>
#pragma config WDT = OFF
void delay_ms(long t);
//unsigned int count;
int count1;
void main (void)
{
TRISD=0;
TRISC=1; is input and output from sensor is connected to it
TRISA=0;
//PORTC=0;
//LATA=0;
while(1)
{
//PORTBbits.RB0= 0; //portb0 is input
PORTDbits.RD0=0; portd is output and intput to sensor
//LATC=1; //porta0 is output
Delay1KTCYx(1); //wait for 1ms
//PORTBbits.RB0 =1;
PORTDbits.RD0=1;
Delay1KTCYx(1); //wait for 1ms
PORTDbits.RD0=0;
//PORTBbits.RB0 =0;
while(LATC==1)
{
//if(LATA==0)
// printf("error\n");
//else
//{
count1++;
// PORTC=count1;
PORTA=0xFF;
//printf("correct\n");
//}
while(LATC==1)
{
if(LATC==1)
{
count1++;
// PORTC=count1;
PORTA=0xFF;
//printf("correct again\n");
}
}
}
if(LATC==0)
{
//PORTC=0;
PORTA=0x00;
//printf("end\n");
}
}
}