#include<p18f1320.h>
char * data=00;// Initiazlizes it to zero so the array is saved on
// first location and one can retrieve it.
void main(void)
{
rom near char * pname;
static rom near char name[]="Hi";
pname=name;//pointer points to first element of name
*data++=*pname++;
*data ++=*pname++;
[B]data=data+20;;
pname=name;
*data++=*pname++;
*data ++=*pname++;
while(1);
}[/B]
//void main(void)
//{
////static rom near char name[]="Hi";
//*data++=name[];
//*data ++=pname[];
//while(1);
//}
#include<p18f1320.h>
char chrArray[40];
char * data=chrArray;
void main(void)
{
rom near char * pname;
static rom near char name[]="Hi";
pname=&name[0] ;//pointer points to first element of name
*data++=*pname++;
*data ++=*pname++;
data=data+20; //will point to chrArray+22 (20+2 increments)
pname=name;
*data++=*pname++;
*data ++=*pname++;
while(1);
}
Yes. Just add the .c source file to you project. Note that this does not move a copy of the file to your project director it just includes the file from where it is at.Wond3rboy said:1)Can we have multiple source codes(not included as functions in header files) in a C18 project.This will help if one is working on multiple devices and rather then going through the process of putting the code in to one file(a huge head ache) one can just add them and link them.If so then how?(sorry my C has just dried up...)
Yes. Just add the .c source file to you project. Note that this does not move a copy of the file to your project director it just includes the file from where it is at.
You can also link in compiled objects by adding .o files to the objects list.
3v0
Hi, i wanted a bit to be used for indication but found out that C18 doesnt support the bit data type.
Secondly, a question regarding multiple source files.Is there some way one can have variables that are accessible in both files?
extern int shareVar;
int shareVar;
make a function like:
int SetBit(int var, int bit){
var = var | (1<<bit);
return var;
}
int ClearBit(int var, int bit){
var = var & ~((1<<bit));
return var;
}
I want to avoid using .h files since...thats what i know( dont know whether its wrong or right)...when you call a function from a header file then it is replaced on every line the function is invoked..i-e a macro.I am already low on memory(i will have to use two pic micros if i use that technique).I want to differentiate between two ADC conversions(one for temperature and one for a SG) for which i wanted to use a bit.Secondly about the variable problem with two source files.. since i will store temp values in the internal EEPROM i want to use a variable as a counter till 100 and use that same variable as an address to store data.What i have done is that i have given up checking that variable in main and used it in the ADC routine only.
Thanks.
Which PIC...?
The method I provided for a variable shared between files will use no additional memory. The variable is allocated in the file shareStuff.c only.
3v0
#include <timers.h>
void OpenTimer0( unsigned char config0 ); // Configure and enable timer x.
void OpenTimer1( unsigned char config1 );
void OpenTimer2( unsigned char config2 );
void OpenTimer3( unsigned char config3 );
void WriteTimer0( unsigned int value16 ); // Write a value into timer x.
void WriteTimer1( unsigned int value16 );
void WriteTimer2( unsigned char value_8 );
void WriteTimer3( unsigned int value16 );
unsigned int ReadTimer0( void ); // Read the value of timer x.
unsigned int ReadTimer1( void );
unsigned char ReadTimer2( void );
unsigned int ReadTimer3( void );
void CloseTimer0( void ); // Disable timer x.
void CloseTimer1( void );
void CloseTimer2( void );
void CloseTimer3( void );
Timer register(s) for ReadTimerx and WriteTimerx functions:
· Timer0 (16 bit): TMR0L,TMR0H
· Timer1 (16 bit): TMR1L,TMR1H
· Timer2 (8 bit): TMR2
· Timer3 (16 bit): TMR3L,TMR3H
1.3.1 ReadTimer0
For TMR_V1, TMR_V2, TMR_V3, TMR_V4, TMR_V5 and TMR_V6
Function:
[B]Reads the value of the timer0.[/B]
Include:
timers.h
Prototype:
unsigned int ReadTimer0( void );
Remarks:
This function reads the value of the timer0 register.
Timer0: TMR0L,TMR0H
Note: When using a timer in 8-bit mode that may be configured in 16-bit mode (e.g., timer0), the upper byte is not ensured to be zero. The user may wish to cast the result to a char for correct results. For example:
// Example of reading a 16-bit result
// from a 16-bit timer operating in
// 8-bit mode:
unsigned int result;
[B] result = (unsigned char) ReadTimer0();[/B]
Return Value:
[B]The current value of the timer.
[/B]
File Name:
t0read.c
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?