CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

#asm bsf PORTC, 5 #endasm does not work

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Boyce



Joined: 07 Feb 2010
Posts: 39

View user's profile Send private message

#asm bsf PORTC, 5 #endasm does not work
PostPosted: Thu Mar 04, 2010 9:50 pm     Reply with quote

Simple question, I hope. PCW 4.104 16F690

How do I get assembly language to turn on and off
PORTC, pin 5 in the middle of a CCS program?

I have tried a lot of different stuff and it will not compile.

The statement:

#byte PORTC = 0x07

is located above main()

For the statement:

#asm bsf PORTC, 5 #endasm

The compiler returns:

//Error 12 Line 76(11,16): Undefined identifier PORTC

PEBKC
Thanks,
Boyce
_________________
boyceg1@gmail.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 10:03 pm     Reply with quote

The test program shown below compiles with no errors.
Quote:

CCS PCM C Compiler, Version 4.104, xxxxx 04-Mar-10 20:04

Filename: C:\Program Files\PICC\Projects\16F690\16F690_Test.lst

ROM used: 34 words (1%)
Largest free fragment is 2048
RAM used: 5 (2%) at main() level
5 (2%) worst case
Stack: 0 locations

Executing: "C:\Program Files\PICC\Ccsc.exe" "16F690_Test.c" +FM +DF +LY +T -A +M -Z +Y=9 +EA -EW
Memory usage: ROM=1% RAM=2% - 2%
0 Errors, 0 Warnings.
Loaded C:\Program Files\PICC\Projects\16F690\16F690_Test.cof.
BUILD SUCCEEDED: Thu Mar 04 20:04:27 2010

Code:

#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOMCLR
#use delay(clock=8000000)

#byte PORTC = 0x07

//======================================
void main()
{

#asm bsf PORTC, 5 #endasm

while(1);
}
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Thu Mar 04, 2010 10:06 pm     Reply with quote

It compiles fine for me. However you may still run into some other problems. All ports are configured as inputs by default. You need to change the tristate register for the port so that the pin is an output.

Try using this:
Code:
#byte PORTC = 0x07

#asm
      bsf 0x03,0x05      //status register; changing banks
      bcf 0x87,5         //trisC register; setting pin as OP
      bcf 0x03,0x05      //status register; changing banks
      bsf PORTC, 5   
#endasm


Rohit
Boyce



Joined: 07 Feb 2010
Posts: 39

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 10:17 pm     Reply with quote

Put this in my program and it compiled.

Code:
#byte PORTC = 0x07

#asm
      bsf 0x03,0x05      //status register; changing banks
      bcf 0x87,5         //trisC register; setting pin as OP
      bcf 0x03,0x05      //status register; changing banks
      bsf PORTC, 5   
#endasm


Thanks for the education, fellows. I am trying to kill a PWM bug...
Boyce
_________________
boyceg1@gmail.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 04, 2010 11:03 pm     Reply with quote

But why do you have to use ASM ? You can set Pin C5 low or high
with these two lines:
Code:

output_low(PIN_C5);

and
Code:

output_high(PIN_C5);

And they set the correct TRIS too.

CCS has got a function to do almost anything you want to do.
Ttelmah
Guest







PostPosted: Fri Mar 05, 2010 3:04 am     Reply with quote

and (of course), if you don't want the TRIS overload, just make a #bit definition.
So:
Code:


#byte PORTC = 0x07
#bit PORTC5 = PORTC.5

PORTC5=1; //Turn it on

PORTC5=0; //Turn it off....


Best Wishes
Boyce



Joined: 07 Feb 2010
Posts: 39

View user's profile Send private message

PostPosted: Fri Mar 05, 2010 1:45 pm     Reply with quote

Quote:
#byte PORTC = 0x07

#asm
bsf 0x03,0x05 //status register; changing banks
bcf 0x87,5 //trisC register; setting pin as OP
bcf 0x03,0x05 //status register; changing banks
bsf PORTC, 5
#endasm


I have some questions about the code:

"bsf 0x03,0x05 //status register; changing banks"

The 16F690 data sheet shows 03h as the address of STATUS for
Bank 0. I understand that.

I don't understand the "0X05" part of the statement. Seems
like it is the same as:

bsf 0x03,5 //to change to bank 1.

True?

Please respond.
Thanks,
Boyce
_________________
boyceg1@gmail.com
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 05, 2010 9:41 pm     Reply with quote

If you look at pg-29 of the datasheet for the '690, you'll find the memory organization tabulated.

You will notice that the PORTC register is in bank0 while the TRISC register is in bank1. You need to switch to bank1 by setting the RP0 bit (ie. STATUS.5). Then modify the TRIS register. After this you need to switch back to bank0 (by clearing RP0, ie. bit 5 of STATUS), and then modify the PORTC register.

Since the STATUS register is 'mirrored', it's contents will be the same throughout the banks. This means that the STATUS register for bank0,1,2,3 are for all practical purposes, the same memory location. If you modify the STATUS register while you're in bank3, this change will be reflected in bank0,1,2 as well. The whole purpose of providing a mirrored STATUS register is so that key information about the processor is readily available regardless of the memory bank you're currently accessing.

If you look closely at my code you'll notice an error:
Quote:
#byte PORTC = 0x07

#asm

bsf 0x03,0x05
bcf 0x87,5
bcf 0x03,0x05
bsf PORTC, 5

#endasm
It should actually be
Code:
bcf 0x83,0x05
But on compilation the code works fine because of the way memory addressing is handled by the PIC. The PIC can address upto 128 location per bank (0 through 127). The appropriate bank is selected using RP0 and RP1 bits. So the actual memory address is concatenated like so - RP1:RP0:7-bits. So whether I write bcf 0x03,5 or bcf 0x83,5 it doesn't matter, since the MSBit of 0x83 is 'ignored' anyway. However you should be technically fastidious and write bcf 0x83,5. Razz

Rohit
Boyce



Joined: 07 Feb 2010
Posts: 39

View user's profile Send private message

PostPosted: Fri Mar 05, 2010 10:17 pm     Reply with quote

Rohit de Sa wrote:
...So whether I write bcf 0x03,5 or bcf 0x83,5 it doesn't matter, since the MSBit of 0x83 is 'ignored' anyway. However you should be technically fastidious and write bcf 0x83,5. :razz:
Rohit


Ok, but my question was about the "0x05" part of code like:

bcf 0x03,0x05

From what you have said, the "0x05" can be replaced with plain ol' "5".

Is the above statement true?
Thanks,
Boyce
_________________
boyceg1@gmail.com
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 05, 2010 11:43 pm     Reply with quote

Boyce wrote:
From what you have said, the "0x05" can be replaced with plain ol' "5".
Yes, 0x05 is the hexadecimal representation of 5. You could even replace it with 0b00000101 (binary). Note that leading zeros can be lopped off. So,
0x05==0x5
0b00000101==0b101

The '0x05' says that the sixth bit (ie bit 5) must be set/cleared.

Rohit
Boyce



Joined: 07 Feb 2010
Posts: 39

View user's profile Send private message

PostPosted: Sat Mar 06, 2010 9:43 pm     Reply with quote

Rohit de Sa wrote:
Boyce wrote:
From what you have said, the "0x05" can be replaced with plain ol' "5".
Yes, 0x05 is the hexadecimal representation of 5. You could even replace it with 0b00000101 (binary). Note that leading zeros can be lopped off. So,
0x05==0x5
0b00000101==0b101

The '0x05' says that the sixth bit (ie bit 5) must be set/cleared.

Rohit


Got it. Thanks.
Boyce
_________________
boyceg1@gmail.com
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group