Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Code reusablity for two DHT11 sensors in PIC1f877a

Status
Not open for further replies.

7ezhil7

Junior Member level 2
Joined
Mar 31, 2016
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
214
I am doing a project in PIC16f877a with 2 DHT11 sensors.The sensors where placed at different places.But the code for both of the sensors were same.I would like to reuse the code.I dont know how to do that...
Code:
#define dht11pin locpin;
#define dht11dir locdir;
........
........
void main()
{
locpin=PORTAbits.RA0;
locdir =TRISAbits.TRISCA0;
}


I tried above code but i shoots an error as 'undefined locpin'.
Please suggest me a way to reuse my code.
 

I haven't used any library..i have programed using dht11 datasheet.
 

Is there any way to reuse code in PIC?
By any choice can I pass a pin as argument to another function?
 

pin as argument is a most popular and basic way. Sure, it is a best choice for your purpose.

- - - Updated - - -

Just an example:
Code:
typedef struct
{
  unsigned char I2C_Address;
  unsigned char (* I2C_SeqRead) (I2C_SW_InitStructTypeDef * I2C_Struct);
  unsigned char (* I2C_SeqWrite)(I2C_SW_InitStructTypeDef * I2C_Struct);
  I2C_SW_InitStructTypeDef * I2C_SW_InitStruct;
}BME280_InitStructTypeDef;
I2c driver for BMP280 sensor. Works with s/w and h/w i2c.
 
Thank you very much for your reply Sir,It helped me alot...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top