sairfan1
Full Member level 1
- Joined
- Jun 12, 2010
- Messages
- 97
- Helped
- 4
- Reputation
- 8
- Reaction score
- 7
- Trophy points
- 1,288
- Location
- Regina, Canada
- Activity points
- 2,384
Hi,
I'm having problem while working in MikroC, i want to break my code into library, see how can i make following code workable.
I'm having problem while working in MikroC, i want to break my code into library, see how can i make following code workable.
Code:
//--------------
//file test.h
//--------------
#ifndef _TEST_H_
#define _TEST_H_
#define __TEST_DEF 1
unsigned char __chr = 'D';
void set_char(unsigned char c);
unsigned get_char(void);
unsigned do_access();
#endif
//--------------
// file test.c
//--------------
#include "test.h"
#include "access.h"
void set_char(unsigned char c){
if (__chr == __TEST_DEF)
__chr = 'T';
else
__chr = c;
}
unsigned get_char(void){
return __chr;
}
unsigned do_access(){
return acc;
}
//--------------
//file access.h
//--------------
#ifndef _ACCESS_H_
#define __ACCESS_H_
unsigned char acc = 'S';
void setchar(unsigned char c);
unsigned getchar(void);
unsigned char do_test();
#endif
//--------------
// file access.c
//--------------
// accessing sourcing of other header and c files
// variables, functions and #define macros
#include "test.h"
#include "access.h"
void setchar(unsigned char c){
if (__chr == __TEST_DEF)
__chr = 'T';
else
__chr = c;
}
unsigned getchar(void){
return __chr;
}
unsigned char do_test(){
returne get_char();
}
//--------------
// file main.c
//--------------
#include "test.h"
#include "access.h"
void main(void){
TRISB = 0;
PORTB = 0;
setchar('B');
PORTB = get_char();
Delay_ms(1500);
set_char('A');
PORTB = getchar();
Delay_ms(1500);
PORTB = do_test();
Delay_ms(1500);
PORTB = do_access();
Delay_ms(1500);
while(1);
}