CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Need help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ycho87



Joined: 11 Mar 2011
Posts: 7

View user's profile Send private message

Need help
PostPosted: Thu Mar 17, 2011 5:38 am     Reply with quote

Hi

I am doing a project called automatic room light controller. A pair of transmitter and receiver will be place at each side of door to detect people in. The transmitter will generate a square wave signal and received by Tsop4838(receiver). After that, the TSOP output will be connect to a missing pulse generator. The missing pulse detector will be connect to pin2(RA0) of a PIC16f877a.
Basically the missing pulse detector will always given high output when the TSOP received square wave signal from the transmitter, and change to low output if sense missing pulse(when people pass through,no square wave).It will change back to high after a short period. I need to write a program when the output change to low, the LCD will display number = 1. And the number will increase by one every time the output change to low. Below is the program i wrote, but it doesn't work.



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

void main()
{
   int interrupt = 0;
    lcd_init();

     {
   if (input(IR1) == True)  /this code is used for check H or L using a LED
     output_high(PWR_LED);
     else
     output_low(PWR_LED);
     
      lcd_putc("\fAutomatic Room");
      lcd_putc("\nLight Controller");
      delay_ms(5000);
      lcd_putc("\f");
     
     
      lcd_gotoxy(1,1);
      lcd_putc("People in = \n");
     
      if(input(IR1)==0)   / if the input is low
      {
         interrupt+=1;         increment by one
         lcd_gotoxy(13,1);   display on first row,13th column
         lcd_putc(interrupt);
      }
   }while(1);
}

Should i include
  SETUP_ADC_PORTS(NO_ANALOGS); no analog,only digital
  setup_adc(adc_off); off ADC


Code:

if (input(IR1) == True) /this code is used for check High or Low using a LED
output_high(PWR_LED);
else
output_low(PWR_LED);


the problem i facing is the above code couldn't work if combine with the LCD code. It could work if the code compile separately. below show the independent code that worked fine.
Code:

#include <16F877a.h>
#use delay(clock=20000000)
#fuses HS, NOWDT, NOPROTECT, NOPUT, NOLVP


#define PWR_LED Pin_A5
#define IR1 Pin_A0

void main()
{


   While(1)
   {
     if (input(IR1) == True)
     output_high(PWR_LED);
    else
     output_low(PWR_LED);
   }
     
}


the next problem is below code didn't show any response in the LCD. i am trying to write the code that when the input is low, lcd on 1st row,13th digit will increase by one everytime the input change to low. Please figure out the problem for me.
Code:

if(input(IR1)==0) / if the input is low
{
interrupt+=1; increment by one
lcd_gotoxy(13,1); display on first row,13th column
lcd_putc(interrupt);
}
}while(1);



Thanks for the help, really appreciate
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Mar 17, 2011 7:56 am     Reply with quote

Not being an expert with the LCD driver, I may not be seeing all the problems - but I can see a couple of obvious things. For one thing... your variable interrupt is a binary value, so it's not going to display properly. You will want to display the ASCII value:
Code:
printf(lcd_putc,"%3u",interrupt);

Another issue you're going to run into... if you're using one sensor, and you increment the count every time the IR beam is broken, what happens when people leave the room? The count increases. You need two beams. One can be used to increment or decrement the count, the other provides the direction of travel.

Let's say you have two IR beams, IR1 toward the outside of the doorway and IR2 toward the inside.
Code:

if(input(IR1)==0) {   // if the input is low
    if(input(IR2)) {     // Second beam is not broken
        interrupt++;    // Person is entering the room
    } else {               // Second beam is broken
        interrupt--;      // Person is leaving the room
    }
    lcd_gotoxy(13,1); // display on first row,13th column
    printf(lcd_putc,"%3u",interrupt);
}


And lastly, when asking for help with something like this, it's always best to copy & paste your actual code, including defines, declarations, and your compiler version. There may be other problems we can't see if we don't see the whole picture. In your post there are typos that would keep the code from even compiling.

Hope this helps.
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Mar 17, 2011 10:28 am     Reply with quote

Oh... one more thing that might cause you problems.
Code:

void main()
{
...
     {
...
        {
...
      }
   }while(1);
}


Do you see a problem here? You'll make one pass through part of your program... then what do you think a "while(1);" statement will do? Hint: Take a look at the ASM output.

I did get your PM. Plenty of people will probably help out, IF you provide complete information and are willing to be patient. It's a great bunch of very helpful and very competent people, but we see a LOT of posts from students looking to have someone else do their homework for them. Also bear in mind that this forum is for help with the CCS C compiler, not general "how do I write programs in C" type stuff. For that there is the manual as well as many good C programming books.
ycho87



Joined: 11 Mar 2011
Posts: 7

View user's profile Send private message

PostPosted: Mon Mar 21, 2011 3:29 am     Reply with quote

Hi

i had changed from
Code:

lcd_putc(interrupt);

to
Code:

printf(lcd_putc,"%3u",interrupt);


but the number can only count up to 255.
Can you tell me how to count more than 255?
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 21, 2011 5:30 am     Reply with quote

You've defined your variable 'interrupt' as a type int.
In CCS integers are 8 bits, unsigned, they go from 0 to 255.
Unlike other C's , CCS chose to make integers 8 bits, probably to conform to the ALU width.

Please press F11,the help file for CCS will come up. It is super handy to use and faster than the hardcopy version!
It will probably answer 9 out of 10 questions you have, especially details like formatting data, serial examples, etc.

ps. you may want to change the name of your variable.Calling it 'interrupt' may confuse the compiler if it thinks it's a 'reserved word', maybe counter, people_counter, or somethine tht better describes what it is used for.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group