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

interrupt by receiving byte while sending every 0.1s

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



Joined: 21 Nov 2012
Posts: 3

View user's profile Send private message

interrupt by receiving byte while sending every 0.1s
PostPosted: Wed Nov 21, 2012 10:32 am     Reply with quote

Code:

#include "16F877A.h"
#device ADC=10
#fuses HS,NOWDT
#use delay(clock=4000000)
#use rs232(uart1)
int overflow_count=0; // Global variables
int16 water_level; // water level in terms of integer

#int_TIMER1
TIMER1_isr()
{
   SET_TIMER1(53036);                  // Interrupt every 0.1s or 100ms
   water_level=read_adc();
   printf("%Lu\r\n",water_level);     //sending value to PC via UART   
   
}

void main()
{
     setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(ALL_ANALOG);
   set_adc_channel(0);
   setup_uart(9600);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   clear_interrupt(INT_TIMER1); 
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);                  // Initialization of Interrupt
    
    while(1)
   {;}                    // <--- try to put sleep here

}

I am trying to put sleep after initialization, but I don't know how to wake up from an external oscillator.

The program is waiting for user input with some value using through GUI(Visual Basic) while the water level is keep sending value every 100ms for data logging; is this okay?

I am trying execute the task when int_rda (receive byte interrupt) occur.
The input value is basically digital; and how can I put the string into array ?
Example: 200,300 a[0] =200, a[1] = 300; something like that.
I am a newbie. Sorry.
Appreciate any help. Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 21, 2012 1:50 pm     Reply with quote

Read the comments by Ttelmah in these threads on how to wake-up from
sleep and read incoming RS-232 characters:
http://www.ccsinfo.com/forum/viewtopic.php?t=36125
http://www.ccsinfo.com/forum/viewtopic.php?t=25990
wstay



Joined: 21 Nov 2012
Posts: 3

View user's profile Send private message

PostPosted: Thu Nov 22, 2012 10:50 am     Reply with quote

PCM programmer wrote:
Read the comments by Ttelmah in these threads on how to wake-up from
sleep and read incoming RS-232 characters:
http://www.ccsinfo.com/forum/viewtopic.php?t=36125
http://www.ccsinfo.com/forum/viewtopic.php?t=25990

Thanks for the guide i manage to get it wake up from int_rda.
But then how can I convert the input_val[] array string to
byte or hex so that i can put it at output_d() ?
Example: output_d(255)
The byte can be useful for other functions too. Heres my code
Code:

#include "16F877A.h"
#device ADC=10
#fuses HS,NOWDT
#use delay(clock=4000000)
#use rs232(uart1)
int overflow_count=0; // Global variables
int number;
int y;
char input_val[4];

int16 water_level; // water level in terms of 16 bit integer

#int_TIMER1
TIMER1_isr()
{
   SET_TIMER1(3036);
   water_level=read_adc();
   printf("%Lu\r\n",water_level);      
}

#int_rda
int SerialDataReceive()   
{

   
   gets(input_val);  // receiving string
   y=input_val;
   printf("Value Received %s\r\n", input_val);
   return y;
     
}
   
void main()
{
     setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(ALL_ANALOG);
   set_adc_channel(0);
   setup_uart(9600);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   clear_interrupt(INT_TIMER1); 
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

    
    while(1)
   {output_d(y);}

}
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Nov 22, 2012 11:33 am     Reply with quote

The best way is to open and read several of the fine examples CCS supplies in the 'examples' folder as well as reading the 'help file( press F11 when your project is open).

probably 99.44% of what you need to know is there !!
hth
jay
wstay



Joined: 21 Nov 2012
Posts: 3

View user's profile Send private message

PostPosted: Thu Nov 22, 2012 1:23 pm     Reply with quote

temtronic wrote:
The best way is to open and read several of the fine examples CCS supplies in the 'examples' folder as well as reading the 'help file( press F11 when your project is open).

probably 99.44% of what you need to know is there !!
hth
jay

Thanks
I manage it to get it using atoi function.
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