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

gets to be verified

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



Joined: 07 Nov 2008
Posts: 60

View user's profile Send private message

gets to be verified
PostPosted: Wed Feb 11, 2009 11:52 am     Reply with quote

Please could someone check why the following gets not appear to work properly?
Thanks

Code:
#include <24FJ16GA002.h>
#include <string.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES ICS3                     //ICD communication channel 3
#FUSES IOL1WAY                  //Allows only one reconfiguration of peripheral pins
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
#FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FRC                      //Internal Fast RC Oscillator
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO                  //OSC2 is general purpose output
#FUSES NOPR                     //Primary oscillaotr disabled
#FUSES I2C1SELD             
#use delay(clock=8000000)

#pin_select OC1=PIN_B0    //OUTPUT OF PWM PIN 4
#pin_select OC2=PIN_B1    //OUTPUT OF PWM PIN 5
#pin_select U1TX=PIN_B10  //RS-232 TX PIN 21
#pin_select U1RX=PIN_B11  //RS-232 RX PIN 22
#use rs232(UART1,baud=9600,parity=N,bits=8,stop=1)
#BYTE U1RXREG = 0x226

char cmd_board[12];

#int_rda
void Serial_isr()
   {
      gets(cmd_board);
      output_high(PIN_B7);
   }

void main()

   long an_1;
   long an_2;
   long an_3;

   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);
   setup_wdt(WDT_ON);
   setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
   enable_interrupts(INT_RDA);
   enable_interrupts(intr_global);
   
   setup_timer2(TMR_INTERNAL | TMR_DIV_BY_8,10000 );
   setup_compare(1,COMPARE_PWM | COMPARE_TIMER2 );
   setup_compare(2,COMPARE_PWM | COMPARE_TIMER2 );
   setup_adc_ports( sAN9 | sAN10 | sAN11 );
   setup_adc(ADC_CLOCK_INTERNAL );
   
   set_pwm_duty(1,1000);  // 2ms on status
   set_pwm_duty(2,1000);  // 2ms on status
   
   output_low(PIN_B8); //common pin for led
   output_low(PIN_B6); //led off
   output_low(PIN_B7); //led off

do
{
   set_adc_channel( 9 );
   an_1 = read_adc();
   set_adc_channel( 10 );
   an_2 = read_adc();
   set_adc_channel( 11 );
   an_3 = read_adc();
   output_high(PIN_B6);
   printf("%Lu%c%Lu%c%Lu%c%c",an_1,10,an_2,10,an_3,10,13);
   printf("%s", cmd_board);           // Display string receieved
} while(true);   
}
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Feb 11, 2009 12:09 pm     Reply with quote

You're not using your int_rda() quite right. gets() will wait until a 'return' is detected. The best way to set things up is to use getc() to capture one character at a time, stuff each character in a buffer array and then when a character, like 'return', is detected set a flag and have the array manipulated some how in the main body of your code.

ISRs are meant to be short and sweet, detect that a character has entered the receive buffer, enter the ISR, put the character some where and get out so your PIC can be doing other things while it waits for the next character to show up.

With using gets() your PIC will stay inside the ISR until a 'return' is seen which will kill all other functions you might want to be doing. Use getc() and see how it works.

Plus, you should have placed this post in your original thread instead of starting a new one.

Ronald
nicotec



Joined: 07 Nov 2008
Posts: 60

View user's profile Send private message

PostPosted: Wed Feb 11, 2009 12:25 pm     Reply with quote

Thanks but I send only command like "55,61" or similar always followed by LF and CR using visual basic; do you think it works correctly?
Thanks
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