I'm used to make a c file for things i use a lot in my code like a c file for timer0 , adc etc
Now to the main subject
when trying to make a c file to deal with the 8 bit shift register 74HC595 (I'm using two linked together ) i had some problems
here is my main code (most of it) :
#define F_CPU 8000000UL #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> #include "AVR_Hc595.c" // note : ds , sh , st are pins from the hc595 ic // 595 Micros !!!!!!!!!!!!!!!! #define Ds_Port PORTB #define sh_Port PORTB #define st_Port PORTB #define Ds_pin PB2 #define sh_pin PB3 #define st_pin PB4 int main(void) { //Basic IO init stuff here Shift595(0,255); Latch; _delay_ms(100); }
my "AVR_Hc595.c" :
#define Ds_pin_H Ds_Port|= (1<<Ds_pin); #define Ds_pin_L Ds_Port&=~ (1<<Ds_pin);// I'm using the macros that i defined in main.c #define sh_pin_H sh_Port|= (1<<sh_pin); #define sh_pin_L sh_Port&=~ (1<<sh_pin); #define st_pin_H st_Port|= (1<<st_pin); #define st_pin_L st_Port&=~ (1<<st_pin); #define Latch st_pin_H;st_pin_L; void Shift595(unsigned char _shift_High_Byte,unsigned char _shift_Low_Byte) { char i=8; while(i!=0) { if((_shift_High_Byte&128))Ds_pin_H else Ds_pin_L; sh_pin_H; sh_pin_L; _shift_High_Byte=_shift_High_Byte<<1; i--; } i=8; while(i!=0) { if((_shift_Low_Byte&128))Ds_pin_H else Ds_pin_L; sh_pin_H; sh_pin_L; _shift_Low_Byte=_shift_Low_Byte<<1; i--; } }
i want the pins and ports definition macros(from main.c) to be passed (shared) to the other c file but without adding other files if possible (like header files and such)
any idea ?
Thanks a lot for your time