View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 21, 2011 12:50 pm |
|
|
Quote: | #define IR1 Pin_A0
if (!IR1 & IR2)
|
That is not the correct method to read and test a pin.
Download the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Go to this section:
Quote: | BUILT-IN-FUNCTIONS |
Then look in this sub-section:
You will see a list of all functions for doing i/o operations on PIC pins.
To read a pin, use the input() function. Look in the CCS manual before
doing anything. There will be a function specifically for it.
There is one more problem (in that area of your code). You are using
"bitwise" operators. If you want to do logical testing, then you should use
logical operators. |
|
![](templates/subSilver/images/spacer.gif) |
ycho87
Joined: 11 Mar 2011 Posts: 7
|
|
Posted: Tue Mar 22, 2011 3:44 am |
|
|
Hi PCM Programmer,
Thanks for your reply
Below is the modified code.
Code: |
#include <16f877a.h>
#use delay(clock=20000000)
#fuses hs,noprotect,nowdt,nolvp
#define use_portb_lcd TRUE
#include <lcd.c>
#define PWR_LED Pin_A5
#define IR1 Pin_A0
#define PWR_LED1 PIN_E0
#define IR2 Pin_A1
void main()
{
int interrupt = 0;
int interrupt1 = 0;
set_tris_a(0b00000011);
lcd_init();
lcd_putc("\fAutomatic Room");
lcd_putc("\nLight Controller");
delay_ms(5000);
lcd_putc("\f");
lcd_gotoxy(1,1);
lcd_putc("People in = 0\n");
lcd_putc("People out = 0\n");
do{
if (input(IR1)==0 && input(IR2==1))
{
while(input(IR1)==1 ^ input(IR2)==1);
if (input(IR1)==0 && input(IR2)==0)
{
while(input(IR1)==0 && input(IR2)==0);
if (input(IR1)==1 & input(IR2)==0)
{
interrupt += 1;
lcd_gotoxy(14,1);
printf(lcd_putc,"%3u",interrupt);
}
while(input(IR1)==1 ^ input(IR2)==1);
}
}
}while(1);
}
; |
The LCD show the counting now, but it only can count up to 1.
What is the problem?
thank you |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Mar 23, 2011 10:28 am |
|
|
As a suggestion: You will get better and quicker responses when you make sure the program you post is well formatted. The indentation in your program is now jumping left and right which makes it very difficult to read.
Code: | if (input(IR1)==0 && input(IR2==1)) | I am surprised this line did compile without warning or error code. Fix the bad placed ')' character.
Code: | if (input(IR1)==1 & input(IR2)==0) | Here, again, you should replace the 'binary AND' by a 'logical AND' . Personally I like to add a few more braces to clarify the operators belonging together: Code: | if ((input(IR1)==1) && (input(IR2)==0)) |
|
|
![](templates/subSilver/images/spacer.gif) |
|