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.

#define replace by function().

Status
Not open for further replies.

jit_singh_tara

Full Member level 6
Joined
Dec 22, 2006
Messages
325
Helped
9
Reputation
18
Reaction score
4
Trophy points
1,298
Location
Delhi , India
Activity points
4,293
hi , as we know that to use a particular pin of a port we use :

#define rs portd.f2 (in mikroc compiler )

i want to know that wether it is possible to use a function to have same functionality ,
i want to make a function in which , any port and any pin can be configured by user)i.e

something like this :
lcd(&portc, 2 , 3, 4) in which i can use any pins for rs , rw , en.

both the port and pins should be configurable.

is there some way of doing it because the in built libraries provided with mikroc compiler has this function , please tell me the details regarding this .

thanks.
 

Not familiar with that compiler but some micro controllers have their port bits memory mapped. Your function can then take a port and bit value and calculate the memory mapped port bit. Another way is something like this:

function(port_bit)// eg bit 18 will be in port 3
{
char portnum;
portnum = port_bit / 8; // work out which port
port_bit = port_bit % 8; // get bit number
switch(portnum)
{
case 0:
Port0 = Port0 & ~ port_bit;
Port0 = Port0 | port_bit;
....... do a case statement for each port. replace Port0 with actual port address
 
  • Like
Reactions: taroot

    taroot

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top