Jump to content

Recommended Posts

use this:

 

// in your header file, define variables for each pin on each port, like this:

volatile bit    bPin0    @ PORTA.0
volatile bit    bPin1    @ PORTA.1
volatile bit    bPin2    @ PORTA.2
volatile bit    bPin3    @ PORTA.3
volatile bit    bPin4    @ PORTA.4
volatile bit    bPin5    @ PORTA.5


:
:
:

bPin1 = 1;    // turn on pin 1

bPin4 = 0;    // turn off pin 4

if( bPin5 )
{
   // pin 5 is high
}

if( ! bPin0 )
{
   // pin 0 is low
}

 

You will also need to define the TRIS directions for the port(s) you will be using.

 

 

 

 

HTH

 

 

Joe

Link to post
Share on other sites

Hello!

 

I have got one similar question.

I want to write in register some Bin number.For example:

I need 11111100 in register PORTB.I think that is not right(PORTB=11111100)

 

Please tell me how can I do this?

 

Thanks for the answers!

Link to post
Share on other sites

I tried to do that,but it doesn't work.I wrote simple program,counter from 0 to 1.

Something in the program is not right.I am going to put 7segment LED display on

PORTB.

Please tell me where is the mistake.

There is my simple program.

 

 

#include <system.h>

 

void main()

{

trisa= 0; //output

trisb= 0; //output

 

loop:

PORTB= 11111100b; //value of PORTB.

delay_s( 1 );

PORTB= 01100000b; //value of PORTB.

delay_s( 1 );

goto loop;

}

Link to post
Share on other sites

Maister,

 

tried to do that,but it doesn't work.

 

It wasn't meant to work, just compile.

you would need to add trisb = 0; to the code to set port b to output.

 

The code below works for the PIC16F84A

 

#include <system.h>

void main()
{
   trisb= 0; //output

   loop:
   portb= 11111100b; //value of PORTB.
   delay_s( 1 ); 
   portb= 01100000b; //value of PORTB.
   delay_s( 1 ); 
   goto loop;
}

 

Regards

Dave

Link to post
Share on other sites

Dave,Idon't understand you perfectly.I wrote trisb = 0; in my programe.

Now I tried this code for PIC16F84a.The compiler gave me next messages:

 

BoostC Optimizing C Compiler Version 2.0.1 Beta (for PIC16 architecture)

http://www.picant.com/c2c/c.html

Copyright© 2004-2005 Pavel Baranov

Copyright© 2004-2005 David Hobday

 

 

7segmentni_C.pp(1): error: failure

failure

Exit code was 1.

Removing target: 7segmentni_C.obj

Failed to locate output file '7segmentni_C.obj'

Done

 

Failed

 

Please,tell me what i did wrong.

Thanks for the answers! :(

Link to post
Share on other sites

Another question about the port definitions:

 

I cannot get the compiler to accept port definitions declared extern in a header file, or declared regularly in the header file or any other way, other than directly in the source file. I need to be able to have this declared globally in the header file because there are multiple source files that use this header, but it won't work.

I've tried numerous things, including:

 

.c file:

volatile bit NC_0 @ PORTB, 0;

 

.h file

volatile bit NC_0 @ PORTB, 0;

or

extern ' '

 

or just declaring them in the header file, and whatever else I could think of.

error just states " general error"

Any reason for this?

Dan

Link to post
Share on other sites

Maister,

 

Don't you have to use lower case (portb) instead of PORTB in this example.

PORTB is the fixed address of B?

 

???

 

Mike :(

 

 

 

 

I tried to do that,but it doesn't work.I wrote simple program,counter from 0 to 1.

Something in the program is not right.I am going to put 7segment LED display on

PORTB.

Please tell me where is the mistake.

There is my simple program.

 

 

#include <system.h>

 

void main()

{

trisa= 0; //output

trisb= 0; //output

 

loop:

PORTB= 11111100b;  //value of PORTB.

delay_s( 1 ); 

PORTB= 01100000b;  //value of PORTB.

delay_s( 1 ); 

goto loop;

}

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...