|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 17, 2007 11:43 am |
|
|
Quote: | int x=0, i=3, value;
int count=3;
int codin [] = {0,0,0,1,1,1,1,0,0,0}; // simplified for test
int codout[] = {}; // empty array |
The line in bold is wrong.
You must declare the array size, either by initializing it as you have
done with 'codin' or by putting a value inside the brackets.
Example:
Your current code is over-writing other variables. Look at the .SYM
file in your project directory:
Code: |
01A value
01B count
01C-025 codin
026 codout
027 yamaha.@SCRATCH
028 yamaha.@SCRATCH
029 yamaha.@SCRATCH
02A isr.@SCRATCH
|
Notice that 'codout' is only one byte long. If you write more than
one byte to it, you will destroy the yamaha scratch variables and
also the isr scratch variable. Your program will not run correctly.
That's why it's important to declare the size of the 'codout' array.
-------
Also, when you post code, make sure that you disable HTML.
Some of the lines in your code were garbled because HTML was enabled.
There is a tickbox below the posting window to disable it.
It looks like this:
Quote: | x Disable HTML in this post |
|
|
|
bernhard3
Joined: 17 Mar 2007 Posts: 2
|
|
Posted: Sat Mar 17, 2007 11:59 am |
|
|
@ PCM programmer
Thank's for your fast respond!
Is it correct that with [10] , ten fields, with a start value of 0, are created?
When i use "int" I have 256 digits?
Is 255 the maximum field number when using int?
greetings Bernhard |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 17, 2007 12:15 pm |
|
|
In CCS, 'int' mean an 8-bit unsigned integer.
If you use an 'int' as the array index, you can declare an array
of 256 elements. Example:
Code: |
int array[256];
void main()
{
int i; // Array index
int c;
c = array[i];
while(1);
} |
The value of 'i' can be from 0 to 255. |
|
|
buneri Guest
|
Problem in Timer Isr |
Posted: Sat Apr 07, 2007 1:52 am |
|
|
I m using two timers timero and timer1 in my project. My project is to creat pulses of width 500us with respect to the percentage value of ADC. For example for 5V i need 200 pulses and for 2.5V i need 100 pulses and the hundred pulses with 0s width.
Also i need 500us width pulse in start and at the end of 100ms delay i.e at the end of 200 pulses but this output is on anther pin.
I have connected an LED to both of the output pin, I seen the mistake in timing.
Here is my code if anyone find mistake plz tell me,
// PIN_D0 500us pulse after every 100ms delay
// PIN_D1 500us pulses wrt the ADC value
#include <16F877.h>
#device icd=true
#device adc=10
#fuses HS,NOLVP,NOWDT
#use delay(clock=20000000)
#define boundry PIN_D7
#define pulse PIN_D0
int pulses=0,NOP;
#int_RTCC
RTCC_isr()
{
pulses++;
if((pulses < (NOP+1)) && (pulses > 1))
output_toggle(pulse);
if(pulses >= (NOP+1))
output_bit(pulse,0);
set_rtcc(255-39);
}
#int_TIMER1
TIMER1_isr()
{
pulses=0;
set_timer1(65535-6250);
}
void main()
{
float value;
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DISABLED,0,1);
//enable_interrupts(INT_RTCC);
//disable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
set_rtcc(0);
output_bit(boundry,0);
output_bit(pulse,0);
set_adc_channel(1);
// TODO: USER CODE!!
while(1)
{
delay_us(10);
value=read_adc();
NOP = (value/1023)*2*100;
enable_interrupts(INT_RTCC);
//set_rtcc(0);
if(pulses==0)
output_bit(boundry,1);
if(pulses==1)
{
output_bit(boundry,0);
enable_interrupts(INT_TIMER1);
set_timer1(0);
}
}//while
}//main |
|
|
|
|
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
|