pic c programming help!

Discussion in 'Programmer's Corner' started by purejoker, Mar 1, 2009.

  1. purejoker

    Thread Starter New Member

    Feb 15, 2009
    3
    0
    hi there, im a bit stuck on a project im working on. What the project has to get reading from 4 digital temperature sensors and output them on hyperterminal. so this is the code that i have come up with, but it does not seem to work, can someone please guide me as were im am going wrong?
    Im using a pic16f877a with a max233cpp chip and a 4mhz crystal resonator.

    Thanks for your help
    Pure!
    Code ( (Unknown Language)):
    1. #include <16F877A.H>
    2. #use delay (clock=4000000)
    3. #use rs232(baud=2400,xmit=PIN_E0,rcv=PIN_E1)
    4. unsigned int32 read1;
    5. unsigned int32 read2;
    6. unsigned int32 read3;
    7. unsigned int32 read4;
    8. int8 sem;
    9. //
    10. // Define which timer to use and minor_cycle for RTOS
    11. //
    12. #use rtos(timer=1, minor_cycle=100ms)
    13.  
    14. // Declare TASK "Get_Reading" - called every 10ms
    15.  
    16. #task(rate=2s, max=100ms)
    17. void Get_Reading()
    18. {
    19. rtos_wait(sem); // decrement semaphore
    20. read1 = input(PIN_C0);
    21. read2 = input(PIN_C1);
    22. read3 = input(PIN_C2);
    23. read4 = input(PIN_C3);
    24. rtos_signal(sem); // increment semaphore
    25. }
    26. //
    27. // Declare TASK "To_RS232" - called every millisecond
    28. //
    29. #task(rate=2s, max=100ms)
    30. void To_RS232()
    31. {
    32. rtos_wait(sem); // Decrement semaphore
    33. printf("Reading = %LumV\n\r",read1); // Send to RS232
    34. printf("Reading = %LumV\n\r",read2); // Send to RS232
    35. printf("Reading = %LumV\n\r",read3); // Send to RS232
    36. printf("Reading = %LumV\n\r",read4); // Send to RS232
    37. rtos_signal(sem); // Increment semaphore
    38. }
    39. //
    40. // Start of MAIN program
    41. //
    42. void main()
    43. {
    44. set_tris_c(0xFF); // PORT C all inputs
    45. delay_us(10);
    46. sem = 1; // Semaphore is 1
    47. rtos_run(); // Start RTOS
    48. }
     
Loading...