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

GetC stops working after ISR_RB0

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



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

GetC stops working after ISR_RB0
PostPosted: Mon Oct 08, 2007 4:41 pm     Reply with quote

Compiler PCWHD 4.058
I have the following program that has two loops depending on if you press RB0 or RB1. When it is running in the RB0 loop it is writing and reading information over the RS232. The data it reads it does a CRC-CCITT on and verifies. When i first start the program and go to RB0 it works fine. If i hit the RB1 it goes to that loop, and then i hit RB0 again it goes back but then it does not compute the correct CRC. It is as if the getc() is no longer working, because the crc value is then always the same. The rest of the program still runs fine. Does anyone have any thoughst on this?
Code:
#include <18F4520.h>
#device adc=10
#include <stdio.h>
#include <math.h>



#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV25                   //Brownout reset at 2.5V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                    //Extended set extension and Indexed Addressing mode enabled



#use delay(clock=4000000,RESTART_WDT)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,RESTART_WDT,ERRORS)

#define  LCD_POWER   PIN_D7

#include <Flex_LCD.C>

int   i,step,phase1,phase2;
char  reply;
int   byte1,byte2,byte3,byte4,byte5,byte6,byte7,byte8,byte9,byte10,byte11,byte12;
int   byte13,byte14,byte15,byte16,byte17,byte18,byte19,byte20;
int   rbyte1,rbyte2,rbyte3,rbyte4,rbyte5,rbyte6,rbyte7,rbyte8,rbyte9,rbyte10;
int   rbyte11,rbyte12,rbyte13,rbyte14,rbyte15,rbyte16,rbyte17,rbyte18,rbyte19,rbyte20;
long  crc_result,tempbyte,disbyte,mult;
int16 crc,r_crc;

////////////////////////////////////////////////////////////////////////////////
#int_ext1
void rb1_isr(void)
{
step=1;
}
////////////////////////////////////////////////////////////////////////////////
#int_ext
void rb0_isr (void)
{
step=2;
}
///////////////////////////////////////////////////////////////////////////////
int16 crc_1021(int16 old_crc, int8 data)
{
   //int16 crc;
   int16 x;
   
   x=make8(old_crc,1)^data;
   x^=x>>4;
   
   crc=(old_crc<<8) ^ (x<<12) ^ (x<<5) ^ x;
   
   crc&=0xffff;
   
   return crc;
}
////////////////////////////////////////////////////////////////////////////////

void main()
{

   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
   ext_int_edge(0,H_TO_L);
   ext_int_edge(1,H_TO_L);
   enable_interrupts(global);
   output_high(LCD_POWER);
   output_low(LCD_RW);
   output_low(PIN_B5);
   lcd_init();
   set_tris_a(0b00000001);
   set_tris_b(0b00000011);
   byte1=0x55;
   byte2=0x55;
   byte3=0x55;
   byte4=0x54;
   byte5=0xF1;
   byte6=0x44;
   byte7=0x10;  //0x10
   byte8=0x00;
   byte9=0x05;  //0x05
   byte10=0x00;
   byte11=0x00;
   byte12=0x04;
   byte14=0x00;
   byte15=0x03;
   byte16=0xE8;
   byte19=0xFF;
   byte20=0xFF;
   step=0;
   i=0;
   set_adc_channel(0);
   while (true)
   {
      while (step==0)
      {
         delay_ms(100);
         printf(lcd_putc,"\f Rawson Control\n");
         printf(lcd_putc,"  Accurate II");
         delay_ms(100);
         phase1=1;
         phase2=1;
      }
      while (step==1)
      {
         while (phase1==1)
         {
            //output_high(PIN_B5);
            crc=0;
            crc_1021(crc,byte5);
            crc_1021(crc,byte6);
            crc_1021(crc,byte7);
            crc_1021(crc,byte8);
            crc_1021(crc,byte9);
            crc_1021(crc,byte10);
            crc_1021(crc,byte11);
            crc_1021(crc,byte12);
            byte13=0xC0;
            crc_1021(crc,byte13);
            crc_1021(crc,byte14);
            crc_1021(crc,byte15);
            crc_1021(crc,byte16);
            byte17=make8(crc,1);
            byte18=make8(crc,0);
            output_high(PIN_C5);
            //delay_us(20);
            printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",byte1,byte2,byte3,
            byte4,byte5,byte6,byte7,byte8,byte9,byte10,byte11,byte12,byte13,
            byte14,byte15,byte16,byte17,byte18,byte19,byte20);
            phase1=0;
            output_low(PIN_C5);
         }
         //output_low(PIN_B5);
         rbyte1=getc();
         rbyte2=getc();
         rbyte3=getc();
         rbyte4=getc();
         crc=0;
         rbyte5=getc();
         crc_1021(crc,rbyte5);
         rbyte6=getc();
         crc_1021(crc,rbyte6);
         rbyte7=getc();
         crc_1021(crc,rbyte7);
         rbyte8=getc();
         crc_1021(crc,rbyte8);
         rbyte9=getc();
         crc_1021(crc,rbyte9);
         rbyte10=getc();
         crc_1021(crc,rbyte10);
         rbyte11=getc();
         crc_1021(crc,rbyte11);
         rbyte12=getc();
         crc_1021(crc,rbyte12);
         rbyte13=getc();
         crc_1021(crc,rbyte13);
         rbyte14=getc();
         crc_1021(crc,rbyte14);
         rbyte15=getc();
         crc_1021(crc,rbyte15);
         rbyte16=getc();
         crc_1021(crc,rbyte16);
         rbyte17=getc();
         rbyte18=getc();
         r_crc=make16(rbyte17,rbyte18);
         if(crc==r_crc)
            {
            output_high(PIN_B5);
            delay_ms(100);
            output_low(PIN_B5);
            }
         else
            output_high(PIN_B5);
         mult=read_adc();
         tempbyte=make16(byte15,byte16);
         disbyte=tempbyte/1000;
         printf(lcd_putc,"\f Speed=%LuRPM\n",disbyte);
         printf(lcd_putc,"%LX",crc);
         //printf(lcd_putc,"   clockwise   ");
         for (i=0;i<=1;i++)
            delay_ms(500);
         phase2=1;
         phase1=1;
         tempbyte=(mult/20)*1000;
         byte15=make8(tempbyte,1);
         byte16=make8(tempbyte,0);
      }
      while (step==2)
      {
         while (phase2==1)
         {
            crc=0;
            crc_1021(crc,byte5);
            crc_1021(crc,byte6);
            crc_1021(crc,byte7);
            crc_1021(crc,byte8);
            crc_1021(crc,byte9);
            crc_1021(crc,byte10);
            crc_1021(crc,byte11);
            crc_1021(crc,byte12);
            byte13=0x80;
            crc_1021(crc,byte13);
            byte14=0x00;
            crc_1021(crc,byte14);
            byte15=0x00;
            crc_1021(crc,byte15);
            byte16=0x00;
            crc_1021(crc,byte16);
            byte17=make8(crc,1);
            byte18=make8(crc,0);
            output_high(PIN_C5);
            //delay_us(20);
            printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",byte1,byte2,byte3,
            byte4,byte5,byte6,byte7,byte8,byte9,byte10,byte11,byte12,byte13,
            byte14,byte15,byte16,byte17,byte18,byte19,byte20);
            phase2=0;
            output_low(PIN_C5);
         }
         printf(lcd_putc,"\f   Speed=0RPM\n");
         printf(lcd_putc,"     stopped");
         for (i=0;i<=10;i++)
            delay_ms(100);
         phase1=1;
         phase2=1;
      }
     
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 09, 2007 6:32 pm     Reply with quote

My advice is to cut out large sections of the code and see if you still
have the problem. If you do, getting rid of all the excess code will
make it easier to see the problem.
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