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

I just can't breath life into my program...

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







I just can't breath life into my program...
PostPosted: Sat Nov 27, 2004 2:13 pm     Reply with quote

I just can't seem to get this program to work. The output on the RS232 terminal window displays a loop of the first four characters repeatedly.
ie: BCDEBCDEBCDE...
It looks like my program keeps looping back to main after issuing the fourth command in the program listing below.
Code:

//******************************************************************
//******************************************************************
#include <16f877.h>
#include </home/guests/CP_401/F877.h>
#use delay(clock=20000000)
#fuses HS,NOWRT,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)

#use fast_io(A)

//******************************************************************
//*   FUNCTION PROTOTYPES
//******************************************************************
int8 GetData(void);
void DisplayTemp(int8);

//******************************************************************
//*   GLOBAL VARIABLES
//******************************************************************

int8 data;

//******************************************************************
//*   DEFINES
//******************************************************************
#define     dataport    PORTD
#define     addrport    PORTB
#define     cntlport    PORTE

#define    RXDATA      PIN_A3
#define      IOR         PIN_E0
#define      IOW         PIN_E1
#define      RESET         PIN_E2
#define      AEN         PIN_B4
#define     LE           PIN_C1

#define     clr_reset      output_low(RESET)
#define     clr_ior        output_low(IOR)
#define     clr_iow        output_low(IOW)
#define     clr_aen        output_low(AEN)
#define     set_reset      output_high(RESET)
#define     set_ior        output_high(IOR)
#define     set_iow        output_high(IOW)
#define     set_aen        output_high(AEN)

//******************************************************************
//*   FUNCTIONS
//*/****************************************************************

GetData(void)
{
   int16 counter;
   int8 bits = 8;
   int8 data;

   //save timer state for return
   int16 tmrcopy;
   tmrcopy = get_timer1();   
   printf("Inside getdata\n\r");
   
   while (!input(PIN_A3)){
      delay_us(150);   /* 1/2 bit time */
   }
// high level detected - may be preamble
   printf("Fell through\n\r");
   delay_ms(10);         /* skip over possible preamble */
   set_timer1(0);        /* 0.2us per tick */
   while (!input(PIN_A3)){
      delay_us(150);      /* wait for bits */
   }
   counter = get_timer1();
   printf("\n\rCounter: %2X \n\r",counter);

   if (counter<10000||counter>16000){
      set_timer1(tmrcopy);
      printf("Bad Header\n\r");
      return 0;         /* not a valid header */
   }
   set_timer1(0);
   while(bits>0){
      delay_us(300);      /* Starting on leading edge of data, time bits */
      if (!(input(PIN_A3))){
         printf("received 1\n\r");
         output_bit(PIN_A1,1);
         bit_set(data,0);      /* set lsb of data */
         rotate_left(&data,1);   /* shift it to the left */
         output_bit(PIN_A1,0);
      } else {
         printf("received 0\n\r");
         output_bit(PIN_A2,1);
         bit_clear(data,0);      /* set lsb of data */
         rotate_left(&data,1);   /* shift it to the left */
         output_bit(PIN_A2,0);
      }
      bits--;
      delay_us(600);
   }   
   set_timer1(tmrcopy);   
   return data;
}

void DisplayTemp(int8 data)
{
   printf("In display temp\r\n");
   putc(data);
}

//******************************************************************
//*   Start Point
//******************************************************************
void main() {
   setup_adc_ports(NO_ANALOGS);
   putc(0x42);      
   setup_adc(ADC_OFF);
   putc(0x43);
      setup_psp(PSP_DISABLED);
   putc(0x44);
      setup_spi(FALSE);
   putc(0x45);
        setup_counters(RTCC_INTERNAL,WDT_18MS);
   putc(0x46);
      setup_timer_1(T1_INTERNAL | T1_DIV_BY_4);   /* 20MHz/4 = (5MHz/8)^-1 = 1 count per 1.6us */
   putc(0x47);
      setup_timer_2(T2_DISABLED,0,1);
   
   
   set_tris_a(0x08);
   clr_reset;
     set_ior;
      set_iow;
      set_aen;

loop1:
   putc(0x0D);
   putc(0x0A);
   printf("Starting Main\n\r");
   delay_us(150);      //wait for bits every 150us
   data=0;
   while(!data)
   {
      printf("Getting data\n\r");
      data = GetData();   //loop until a valid data
      printf("Got data \n\r");
      printf(data);
   }
   DisplayTemp(data);
goto loop1;
}


The program seems to repeat before/during the setup_counters(RTCC_INTERNAL,WDT_18MS);
command.

I am using a pic16f877 with the ccsc compiler version 3.072 on linux. I can run sample programs on the hardware, so I have verified the hardware. Do I have to put my function prototypes after main... I don't think that should matter.... I have tried commenting out the line that starts the counter, but it doesn't seem to matter. I will look into the .lst file as a last resort.
Can anybody help me out/suggestions?
Thanks!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 27, 2004 3:07 pm     Reply with quote

Well, the first thing I would normally ask is, are you sure that
the Watchdog Timer is really being disabled when you program
your PIC ? I would ask what programmer you are using.

But, you mentioned you have vs. 3.072 of the Linux version of the
compiler.

Here is a thread where the guy was using Linux and he started
at vs. 3.112 (way beyond your version) and he reports 20+ bugs.
http://www.ccsinfo.com/forum/viewtopic.php?t=18884

So at that point, I would stop wondering about WDT and just
tell you to switch to the Windows version.
Guessed
Guest







PostPosted: Sat Nov 27, 2004 5:08 pm     Reply with quote

I actually bought the windows version but it will not work due to some .crg related file issues. Anyway...
I have reduced the code to:
Code:

//******************************************************************
#include <16f877.h>
#use delay(clock=20000000)
#fuses HS,NOWRT,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)


//******************************************************************
//*   FUNCTION PROTOTYPES
//******************************************************************
int8 GetData(void);
void DisplayTemp(int8);

//******************************************************************
//*   GLOBAL VARIABLES
//******************************************************************

int8 data;

//******************************************************************
//*   DEFINES
//******************************************************************
#define     dataport    PORTD
#define     addrport    PORTB
#define     cntlport    PORTE

#define    RXDATA      PIN_A3
#define      IOR         PIN_E0
#define      IOW         PIN_E1
#define      RESET         PIN_E2
#define      AEN         PIN_B4
#define     LE           PIN_C1

#define     clr_reset      output_low(RESET)
#define     clr_ior        output_low(IOR)
#define     clr_iow        output_low(IOW)
#define     clr_aen        output_low(AEN)
#define     set_reset      output_high(RESET)
#define     set_ior        output_high(IOR)
#define     set_iow        output_high(IOW)
#define     set_aen        output_high(AEN)

//******************************************************************
//*   FUNCTIONS
//*****************************************************************


//******************************************************************
//*   Absolute Start Point
//******************************************************************
void main() {
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_counters(RTCC_INTERNAL,WDT_18MS);
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_4);   /* 20MHz/4 = (5MHz/8)^-1 = 1 count per 1.6us */
   setup_timer_2(T2_DISABLED,0,1);
   
   putc(0x47);
}

The program never gets to the character. It's kinda shocking that both the older versions that were purchased previously just plain don't work. These versions were bought with real(not beta) funds, so you'd expect to get a real (not beta) product... Just my two cents Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 27, 2004 5:36 pm     Reply with quote

There's a problem with your test. The compiler puts a hidden Sleep
instruction at the end of main(). So your putc() statement will load
the UART with 0x47, but the PIC will be shut down before that character
ever gets sent out.

To fix this, put a while(1) statement right before the end of main().
Example:

void main()
{

putc(0x47);

while(1);
}

Also, instead of using hex codes for ASCII characters, you can just
do it with single quotes, like this:

putc('G');
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