|
|
View previous topic :: View next topic |
Author |
Message |
Boyce
Joined: 07 Feb 2010 Posts: 39
|
#asm bsf PORTC, 5 #endasm does not work |
Posted: Thu Mar 04, 2010 9:50 pm |
|
|
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 _________________ [email protected] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 04, 2010 10:03 pm |
|
|
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
|
|
Posted: Thu Mar 04, 2010 10:06 pm |
|
|
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
|
|
Posted: Thu Mar 04, 2010 10:17 pm |
|
|
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 _________________ [email protected] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 04, 2010 11:03 pm |
|
|
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
|
|
Posted: Fri Mar 05, 2010 3:04 am |
|
|
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
|
|
Posted: Fri Mar 05, 2010 1:45 pm |
|
|
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 _________________ [email protected] |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Fri Mar 05, 2010 9:41 pm |
|
|
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 beBut 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.
Rohit |
|
|
Boyce
Joined: 07 Feb 2010 Posts: 39
|
|
Posted: Fri Mar 05, 2010 10:17 pm |
|
|
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 _________________ [email protected] |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Fri Mar 05, 2010 11:43 pm |
|
|
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
|
|
Posted: Sat Mar 06, 2010 9:43 pm |
|
|
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 _________________ [email protected] |
|
|
|
|
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
|