My project is to determine the wind direction which are N,NE,E,SE,S,SW,W,NW by using 3 IR sensor,S,SI and SZ. The IR sensor is to check whether there are input or not. There are 3 LED, L,LI and LZ. When the IR detect input, the LED will on. The result will show in LCD.
The microcontroller im using is PIC16F877A with MPLAB IDE and hiTechC compiler.
Three sensor can work well at first. The second time when i compiled the code, the second sensor (SI) cannot function. LED light is also off. But when i connect the circuit to other pin it is functioning. Anyone can help me to check is it my code problem?
The microcontroller im using is PIC16F877A with MPLAB IDE and hiTechC compiler.
Three sensor can work well at first. The second time when i compiled the code, the second sensor (SI) cannot function. LED light is also off. But when i connect the circuit to other pin it is functioning. Anyone can help me to check is it my code problem?
Code:
#include <htc.h>
#define _XTAL_FREQ 8000000
__CONFIG(0x3F3A);
#include<pic.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<conio.h>
#define RS RC2
#define EN RC3
#define D4 RC4
#define D5 RC5
#define D6 RC6
#define D7 RC7
#define S RA0
#define SI RA1
#define SZ RA2
#define L RB0
#define LI RB1
#define LZ RB2
#include "lcd.h"
void main(){
PORTC = 0;
PORTA = 1;
PORTB = 0;
TRISC = 0b00000000;
TRISA = 0b00000111; //IR
TRISB = 0b00000000; //LED
S=1;
SI=1;
SZ=1;
L=0;
LI=0;
LZ=0;
ADCON0=0b10000000;
ADCON1=0b00000111;
CMCON=0x07;
Lcd4_Init();
Lcd4_Clear();
while(1){
Lcd4_Clear();
if((S==0) && (SI==0) && (SZ==0)){
Lcd4_Clear();
__delay_ms(100);
L=0;
LI=0;
LZ=0;
Lcd4_Set_Cursor(1,1);
Lcd4_Write_String("North");
__delay_ms(10);
}
else if((S==0) && (SI==0) && (SZ==1)){
Lcd4_Clear();
__delay_ms(100);
L=0;
LI=0;
LZ=1;
Lcd4_Set_Cursor(1,1);
Lcd4_Write_String("North East");
__delay_ms(10);
}
else if((S==0) && (SI==1) && (SZ==0)){
Lcd4_Clear();
__delay_ms(100);
L=0;
LI=1;
LZ=0;
Lcd4_Set_Cursor(1,1);
Lcd4_Write_String("East");
__delay_ms(10);
}
else if((S==0) && (SI==1) && (SZ==1)){
Lcd4_Clear();
__delay_ms(100);
L=0;
LI=1;
LZ=1;
Lcd4_Set_Cursor(1,1);
Lcd4_Write_String("South East");
__delay_ms(10);
}
else if((S==1) && (SI==0) && (SZ==0)){
Lcd4_Clear();
__delay_ms(100);
L=1;
LI=0;
LZ=0;
Lcd4_Set_Cursor(1,1);
Lcd4_Write_String("South");
__delay_ms(10);
}
else if((S==1) && (SI==0) && (SZ==1)){
Lcd4_Clear();
__delay_ms(100);
L=1;
LI=0;
LZ=1;
Lcd4_Set_Cursor(1,1);
Lcd4_Write_String("South West");
__delay_ms(10);
}
else if((S==1) && (SI==1) && (SZ==0)){
Lcd4_Clear();
__delay_ms(100);
L=1;
LI=1;
LZ=0;
Lcd4_Set_Cursor(1,1);
Lcd4_Write_String("West");
__delay_ms(10);
}
else if((S==1) && (SI==1) && (SZ==1)){
Lcd4_Clear();
__delay_ms(100);
L=1;
LI=1;
LZ=1;
Lcd4_Set_Cursor(1,1);
Lcd4_Write_String("North West");
__delay_ms(10);
}
}
}