Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I was trying to do Coding the vehicle to detect and count markers by PIC18F4550. The sensing using a Photo-Reflective Optical sensor mounted at an appropriate position underneath the vehicle. Markers implemented by using strips of black tape. These markers are placed at random intervals along the path. The counter of the 7-segment during the forward path (up count) and reverse path (down count) will be counted. Upon reaching zero it will stop the vehicle.

But it's doesn't work. what should I fix and do.

Thank you so much.

What I have tried:

#include <xc.h>
#include <stdlib.h>
#include <pic18f4550.h>

#define Digit PORTBbits.RB1 //variable to sink current to PNP base
#define SENSER PORTBbits.RB2 //variable to sink current to PNP base
#define LED1 PORTDbits.RD4
#define PROX_SENSOR PORTBbits.RB3
#define Senfwd 1 //pressed is high
#define Senbwd 1 //pressed is high
#define LEDPin LATDbits.LATD0       	// Define LEDPin as PORT D Pin 0
#define LEDTris TRISDbits.TRISD0    	// Define LEDTris as TRISD Pin 0 as output mode
#define _XTAL_FREQ 8000000              // for __delay_ms() function

#pragma config FOSC = INTOSC_HS  	// Internal oscillator, HS used by USB.
#pragma config FOSC = INTOSCIO_EC   	// Internal oscillator, port function on RA6, EC used by USB. 
#pragma config WDT = OFF   
// Disable watchdog timer

void initialize();
void segment (void);
void Sensor(void);
void delay_ms(unsigned int);
unsigned char count=0;

void main(void){
  initialize();
  Digit = 0;
  while(1){
  Sensor();  
  segment();
  Digit = 1;
 
    return;
    }
}

void segment()
{
     static const unsigned char segArray[]= {0b11000000, 0b11111001, 0b00100100, 0b00110000, 0b00011001,
     0b00010010, 0b00000010, 0b11111000, 0b00000000, 0b00011000
     };
     TRISC = 0; //PortC all OUTPUT
     PORTC = 0xFF; //PortC all HIGH = IDLE = LED_OFF

     TRISBbits.TRISB0 = 0; //Output unused
     TRISBbits.TRISB1 = 0; //Output Digit1
     TRISBbits.TRISB2 = 0; //Output Digit2
     TRISBbits.TRISB4 = 1; //Input: Switch PLUS
     TRISBbits.TRISB3 = 1; //Input: Switch MINUS 

     PORTB = 0x00;
     unsigned char count=0;
     for(;;)
     {
        //Handle buttons
        if (Senfwd && count<9) 
        {
           ++count;
           delay_ms(100);
        }
        if (Senbwd && count > 0) 
        {
           --count;
           delay_ms(100);
        }
        else if (Senbwd && count <= 0)
        {
           break;
        }

        //Write low digit
        PORTC = segArray[count%10];  
        Digit = 0;
        delay_ms(10); // Delay for 10 ms
        Digit = 1;
   }
}
 
 void buzzerled(void) {
    LATD = 0x00; // send 0x00 to port D.
    TRISD = 0x00;
    TRISB = 0XFF;
while (1) {
 LED1 = PROX_SENSOR;
    }
}
Posted
Comments
Patrice T 16-Apr-21 6:12am    
And you plan to tell the error message ?
OriginalGriff 16-Apr-21 7:23am    
Aww! Where's the fun in knowing what the problem is? :laugh:
Patrice T 16-Apr-21 7:27am    
lol
Richard MacCutchan 16-Apr-21 9:19am    
"But it's doesn't work. what should I fix and do."
Fix the bit that doesn't work.
Rick York 16-Apr-21 12:36pm    
I hope you never call buzzerled. It has infinite loop.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900