View previous topic :: View next topic |
Author |
Message |
wstay
Joined: 21 Nov 2012 Posts: 3
|
interrupt by receiving byte while sending every 0.1s |
Posted: Wed Nov 21, 2012 10:32 am |
|
|
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
|
|
|
wstay
Joined: 21 Nov 2012 Posts: 3
|
|
Posted: Thu Nov 22, 2012 10:50 am |
|
|
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
|
|
Posted: Thu Nov 22, 2012 11:33 am |
|
|
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
|
|
Posted: Thu Nov 22, 2012 1:23 pm |
|
|
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. |
|
|
|