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

digital inputs pic16f877a

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



Joined: 04 Mar 2009
Posts: 19

View user's profile Send private message

digital inputs pic16f877a
PostPosted: Wed Mar 04, 2009 2:06 pm     Reply with quote

hi there I'm new to this forums so just like to say hello to everyone.

I'm new to pic programming and would like some guidance.

I have a digital sensor, which has one output. I have connected it to a digital i/o pin on the PIC and then the PIC is connected to the max232 and then to the serial port of my computer. This is the code that I have for the PIC but it doesn't seem to work. What I want the code to do is to get the reading from the sensor and display it on the computer.
Code:

#include <16F877A.H>
#use delay (clock=4000000)
#use rs232(baud=2400,xmit=PIN_E0,rcv=PIN_E1)
unsigned int32 read1;
int8 sem;
//
// Define which timer to use and minor_cycle for RTOS
//
#use rtos(timer=1, minor_cycle=100ms)

// Declare TASK "Get_Reading" - called every 10ms

#task(rate=2s, max=100ms)
void Get_Reading()
{
rtos_wait(sem); // decrement semaphore
read1 = input(PIN_C0);
rtos_signal(sem); // increment semaphore
}
//
// Declare TASK "To_RS232" - called every millisecond
//
#task(rate=2s, max=100ms)
void To_RS232()
{
rtos_wait(sem); // Decrement semaphore
printf("Reading = %LumV\n\r",read1); // Send to RS232
rtos_signal(sem); // Increment semaphore
}
//
// Start of MAIN program
//
void main()
{
set_tris_c(0xFF); // PORT C all inputs
delay_us(10);
sem = 1; // Semaphore is 1
rtos_run(); // Start RTOS
}

thanks for your help
piire!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 04, 2009 2:47 pm     Reply with quote

I suggest that you start with a simple program that doesn't use the RTOS.
Make that program work first. Here's an example:
Code:
#include <16F877A.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=2400,xmit=PIN_E0,rcv=PIN_E1)

//===================================
void main()
{

while(1)
  {
   if(input(PIN_C0))    // Read the switch pin.
      putc('1');        // Display the state of the pin.           
   else
      putc('0');

   delay_ms(100);
  }

}

Make sure that pin C0 has a pull-up resistor on it. You can use 4.7K or
10K.
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Wed Mar 04, 2009 3:22 pm     Reply with quote

Agree with PCM, and you seem to be overlooking the fact that input(PIN_C0); is only ever going to return 0 or 1, what sensor is it?
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