Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem I face with Pic Basic Pro

Status
Not open for further replies.

Bumblebrain

New Member
Hi, does any one have an idea how to solve the following problem..

Problem is that I have a subroutine in my program..

A01:
Low PORTB.1 : High PORTB.0 : Low PORTB.0
Low PORTB.1 : High PORTB.0 : Low PORTB.0
Low PORTB.1 : High PORTB.0 : Low PORTB.0
Low PORTB.1 : High PORTB.0 : Low PORTB.0
Low PORTB.1 : High PORTB.0 : Low PORTB.0
Low PORTB.1 : High PORTB.0 : Low PORTB.0
Low PORTB.1 : High PORTB.0 : Low PORTB.0
High PORTB.1 : High PORTB.0 : Low PORTB.0
Return

I need to put variables instead of PORTB.1 and PORTB.0 like following

A01:
Low desk : GoSub Enabler
Low desk : GoSub Enabler
Low desk : GoSub Enabler
Low desk : GoSub Enabler
Low desk : GoSub Enabler
Low desk : GoSub Enabler
Low desk : GoSub Enabler
High desk : GoSub Enabler
Return

Also I need to change the variables desk and Enabler. Because sometimes I am using PORTB.1 some times PORTB.4 or PORTB.7.

When I write the following code in the beginning I can not change the varibles again

desk var PORTB.1 <- This is Ok and works well

but when I need to switch to PORTB.4 that is, desk must represent PORTB.4 there is problem..

I could not find a solution.

Basically I need a variable that can be changed any time and represents a specific port in order to use it in my subroutine.
 
You probably aren't going to make the one variable represent more than one port. Have you though of using an array?

Or... You could use a couple if-then statements to define one variable as equalling the port you want to use..

if... then desk = porta.1
if... then desk = portb.2
etc.
 
The
if... then desk = porta.1
if... then desk = portb.2
is a good idea and should work well. I have a question; Why do you repeat the same comand over and over?
 
Thanks for the replies..
I have solved the problem but not in that manner.. I have change the the way a send data to ports. Instead of making desk variable I keep it as PORTB.1 or what ever it is and use a variable in different place like..

PORTB.1 = Sdigit[Sd] : High PORTB.0 :Low PORTB.0
PORTB.1 = Sdigit[Sd+1] : High PORTB.0 : Low PORTB.0
PORTB.1 = Sdigit[Sd+2]: High PORTB.0 :Low PORTB.0
PORTB.1 = Sdigit[Sd+3]: High PORTB.0 :Low PORTB.0
PORTB.1 = Fdigit[Fd]: High PORTB.0 :Low PORTB.0
PORTB.1 = Fdigit[Fd+1]: High PORTB.0 :Low PORTB.0
PORTB.1 = Fdigit[Fd+2]: High PORTB.0 :Low PORTB.0
PORTB.1 = Fdigit[Fd+3]: High PORTB.0 :Low PORTB.0

I am sending datas bit by bit because I use a shift register, so first I am making PORTB.1 high and by changing states of PORTB.0 one bit data transfers to shift register.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top