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 CCS Technical Support

PORTD problem

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



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

PORTD problem
PostPosted: Thu Jan 10, 2013 11:20 pm     Reply with quote

Hi Gents,
I'm having issues with PORTD. It is configured for all output. Everything works as expected except for RD3, RD4, and RD5. Below is my code which currently. I'm using proteus for simulation. Can anyone kindly advise what the problem is. Thanks in advance.


Code:
  #include <16f877A.h>
  #include <float.h>
  #include <math.h>
  #include <stdio.h>
  #include <string.h>

  #fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD /* Use XT mode, No Watch Dog, No Code Protect, No Power-up Timer */
#use delay (clock=20000000)
#use rs232 (baud=9600, xmit=pin_c6, rcv=pin_c7, parity=N, stop=1, bits=8)
#define SC_CURR_PIN PIN_E0  //to measure short circuit current
#define LED PIN_E2
#define DELAY 250


void main()
{
   int value = 85;
   char ch;
   char string[64];
   
   setup_adc_ports(No_ANALOGS);
   set_tris_b(0); /* set port_b to be outputs */
   set_tris_d(0); /* set port_b to be outputs */
   set_tris_e(0); /* set port_b to be outputs */
   
   /* echo demo: PIC receives data and sends it back. */
   /* If ENTER key is received, this demo exits. */
   puts("Type on the keyboard, PIC will echo back the characters:");
   output_low(SC_CURR_PIN);
   output_b(0x00);
   output_d(0x00);
   
   //Example blinking LED program
   while(true)
   {
      output_low(LED);
      delay_ms(DELAY);
      output_high(LED);
      delay_ms(DELAY);
    if(kbhit())
   {
      ch = getc();/* read a single character */

      switch (ch)
      {
      case 'R':
        putc(ch);
        putc('\n');
        putc('\r');
        output_b(0b00000000);
        output_d(0b00000000);
        output_high(SC_CURR_PIN);
        break;
     
      case 'B':
        putc(ch);
        putc('\n');
        putc('\r');
        output_low(SC_CURR_PIN);
        output_d(0b00000000);
        output_b(0b11111111);
        break;
     
      case 'D':
        putc(ch);
        putc('\n');
        putc('\r');
        output_low(SC_CURR_PIN);
        output_b(0b00000000);
        output_d(11111111);
        break;
       
        default:
        output_low(SC_CURR_PIN);
        output_b(0b00000000);
        output_d(0b00000000);
        puts("Select Key to test port");
      }
     }
   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 10, 2013 11:33 pm     Reply with quote

Look closely at the numbers you are outputting to PortD. You have a
bug in one line, involving the radix.
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

PostPosted: Fri Jan 11, 2013 12:33 am     Reply with quote

Thank you so much PCM Programmer.
Regards
kein



Joined: 23 Jul 2007
Posts: 103

View user's profile Send private message

What Am I doing wrong
PostPosted: Fri Jan 11, 2013 8:17 am     Reply with quote

Gents,
I've declared const unsigned int16 array to store binary switch positions as below. The problem is, the compiler gives errors when I compile the code.

Quote:
i.e. ***Error 103" main.c" Line 20(1,17): constant out of the valid range
***Error 27" main.c" Line 20(1,18):Expression must evaluate to a constant
***Error 43" main.c" Line 20(1,17): Expecting a declaration
etc.etc.



Code:
#include <16f877A.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD /* Use XT mode, No Watch Dog, No Code Protect, No Power-up Timer */
#use delay (clock=20000000)
#use rs232 (baud=9600, xmit=pin_c6, rcv=pin_c7, parity=N, stop=1, bits=8)
#define SC_CURR_PIN PIN_E0  //to measure short circuit current
#define LED PIN_E2
#define DELAY 250
const unsigned int16 PV_TT_Array[39]={
0000000000000001,
0000000000110100,
0000001010001000,
0000000101110000,
0000011110110000,
0000001010110000,
0000010000110000,
0000001110010000,
0000001101010000,
0000000001010000,
0000000110010000,
0000001100010000,
0000110111100000,
0000001011100000,
0000110101100000,
0010001110100000,
0000010010100000,
0001000100100000,
0000110111000000,
0001010011000000,
0010110101000000,
0010110001000000,
0000100001000000,
0010111110000000,
0000001110000000,
0101010110000000,
0010010110000000,
0010111010000000,
0101011010000000,
1111110010000000,
0010100010000000,
0000000010000000,
0000011100000000,
0001010100000000,
0000000100000000,
0000001000000000,
0000010000000000,
0010000000000000,
1000000000000000
};

void main()
{
   int value = 85;
   char ch;
   char string[64];
   
   setup_adc_ports(No_ANALOGS);
   set_tris_b(0); /* set port_b to be outputs */
   set_tris_d(0); /* set port_d to be outputs */
   set_tris_e(0); /* set port_e to be outputs */
   
   /* echo demo: PIC receives data and sends it back. */
   /* If ENTER key is received, this demo exits. */
   puts("Type on the keyboard, PIC will echo back the characters:");
   output_low(SC_CURR_PIN);
   output_b(0x00);
   output_d(0x00);
   
   //Example blinking LED program
   while(true)
   {
      output_low(LED);
      delay_ms(DELAY);
      output_high(LED);
      delay_ms(DELAY);
    }
}
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Jan 11, 2013 10:16 am     Reply with quote

Code:
const unsigned int16 PV_TT_Array[39]={
0000000000000001,
0000000000110100,


...and exactly what type of number are these 1's and 0's?

Binary?
Hex?
decimal?

.... you should probably tell that to the compiler.

g.
_________________
CCS PCM 5.078 & CCS PCH 5.093
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