View previous topic :: View next topic |
Author |
Message |
behrouz2007
Joined: 27 Sep 2008 Posts: 3
|
Reading port latch in ccs |
Posted: Sun Sep 28, 2008 4:37 pm |
|
|
I previously used MicroC, but because of no command line (no possiblity for use it with MPLAB and ISIS) I decided to use CCS, so I am a beginner in using CCS. Please help me how I can write herein ideas in CCS:
1- The program reads PORTB latch and then toggle its register value. I do it very easy in microc like this (PORTB=~PORTB).
Comment: All pins of PORTB configured as output.
2- Portb value is equal to PR2 register value. I do it in MicroC like this (PORTB=PR2). |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
behrouz2007
Joined: 27 Sep 2008 Posts: 3
|
|
Posted: Mon Sep 29, 2008 3:17 am |
|
|
Thank you for your help
I do mentioned jobs in CCS. I define PORTB as a Byte like this:
#Byte TRISB=86
#Byte PORTB=6
TRISB=0;
PORTB=0X78;
But when i allocate a value to PORTB ,the value did not change because of current bank value. So i must change STATUS bits to adjust the current bank on PORTB. All of this process is very similar to assembly.
My question is :How i can force the compiler for automatic-adjusting the bank value ,when i allocate a value to registers?? |
|
![](templates/subSilver/images/spacer.gif) |
RLScott
Joined: 10 Jul 2007 Posts: 465
|
|
Posted: Mon Sep 29, 2008 5:58 am |
|
|
behrouz2007 wrote: | ...I define PORTB as a Byte like this:
#Byte TRISB=86
#Byte PORTB=6
TRISB=0;
PORTB=0X78;
But when i allocate a value to PORTB ,the value did not change because of current bank value. So i must change STATUS bits to adjust the current bank on PORTB. All of this process is very similar to assembly.
My question is :How i can force the compiler for automatic-adjusting the bank value ,when i allocate a value to registers?? |
First, I hope you just miscopied TRISB=86, because it should be TRISB=0x86. Secondly, the compiler does automatically change to the correct bank. But if you were still using 86 instead of 0x86, then the compiler would think that TRISB and PORTB were in the same bank, and the TRISB would never get written, so PORTB would remain as all inputs. _________________ Robert Scott
Real-Time Specialties
Embedded Systems Consulting |
|
![](templates/subSilver/images/spacer.gif) |
behrouz2007
Joined: 27 Sep 2008 Posts: 3
|
|
Posted: Mon Sep 29, 2008 12:55 pm |
|
|
RLScott wrote: | behrouz2007 wrote: | ...I define PORTB as a Byte like this:
#Byte TRISB=86
#Byte PORTB=6
TRISB=0;
PORTB=0X78;
But when i allocate a value to PORTB ,the value did not change because of current bank value. So i must change STATUS bits to adjust the current bank on PORTB. All of this process is very similar to assembly.
My question is :How i can force the compiler for automatic-adjusting the bank value ,when i allocate a value to registers?? |
First, I hope you just miscopied TRISB=86, because it should be TRISB=0x86. Secondly, the compiler does automatically change to the correct bank. But if you were still using 86 instead of 0x86, then the compiler would think that TRISB and PORTB were in the same bank, and the TRISB would never get written, so PORTB would remain as all inputs. |
Thanks - |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Mon Sep 29, 2008 4:17 pm |
|
|
I try to evaluate "portb=(portb & 0b11110000) | ui[i];" with herein code:
Code: |
int ui[]={1,2,4,8};
void main()
{
int i=0;
setup_timer_0(RTCC_DIV_16|RTCC_INTERNAL);
trisb=0;
portb=0b11010000;
//output_b(0x78);
for(i=0;i<5;i++)
portb=(portb & 0b11110000) | ui[i];
while (1){};
}
|
but the compiler error 51 "A numeric expression must appear here
" occurred.
So first i transfered the value of portb to a intermediate variable and then transfered the result of expression to portb like this:
Code: |
int ui[]={1,2,4,8},jk;
void main()
{
int i=0;
setup_timer_0(RTCC_DIV_16|RTCC_INTERNAL);
trisb=0;
portb=0b11010000;
//output_b(0x78);
for(i=0;i<5;i++){
jk=portb;
portb=(jk & 0b11110000) | ui[i];}
while (1){};
}
|
So my question is: Is it possible to use portb value directly in expressions like above or i should use intermediate variable? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 29, 2008 4:40 pm |
|
|
Post a complete test program that shows the declarations for 'portb'
and 'trisb'. Post the #include, #fuses, and #use delay() statements.
The program should compile without errors.
Also post your compiler version. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Sep 30, 2008 10:07 am |
|
|
PCM programmer wrote: | Post a complete test program that shows the declarations for 'portb'
and 'trisb'. Post the #include, #fuses, and #use delay() statements.
The program should compile without errors.
Also post your compiler version. |
main code:
Code: |
#include "C:\PIC Project\PROJECTS\C Exercices\Prac1\main.h"
#include "C:\PIC Project\PROJECTS\C Exercices\Prac1\PIC.h"
#byte portb=0x6
#byte trisb=0x86
#int_TIMER0
void TIMER0_isr(void)
{
output_b(0x45);
}
void main()
{
int ui[]={1,2,4,8},jk,i=0;
setup_timer_0(RTCC_DIV_16|RTCC_INTERNAL);
trisb=0;
portb=0x78;
for (i=0;i<5;i++){
portb = (0b11110000 & portb) | (0b00001111 & ui[i]);
}
while (1);
} |
PIC.h
Code: | #byte portc = 0x7
#byte portd = 0x8
#byte porte = 0x9
#byte trisa = 0x85
#byte trisb = 0x86
#byte trisc = 0x87
#byte trisd = 0x88
#byte trise = 0x89
#byte intcon = 0xb
struct {
short int ra0 : 1;
short int ra1 : 1;
short int ra2 : 1;
short int ra3 : 1;
short int ra4 : 1;
} porta;
#byte porta = 0x5
struct {
short int rb0 : 1;
short int rb1 : 1;
short int rb2 : 1;
short int rb3 : 1;
short int rb4 : 1;
short int rb5 : 1;
short int rb6 : 1;
short int rb7 : 1;
} portb;
#byte portb = 0x6
|
main.h
Code: | #include <16F877A.h>
#device adc=8
#FUSES NOWDT, XT, PUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=4000000) |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Sep 30, 2008 11:13 am |
|
|
Compiler : CCS V 4.069 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 30, 2008 11:15 am |
|
|
Post your compiler version. It's a 4-digit number in this format: x.xxx |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Sep 30, 2008 2:00 pm |
|
|
PCWHD 4.069
I program a 16F877A |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 30, 2008 2:16 pm |
|
|
Your original complaint was that the code below does not compile with
PCM vs. 4.069. You said it gave you this error message:
Error 51 "A numeric expression must appear here".
I installed vs. 4.069 and this code compiled with no errors:
Quote: | 0 Errors, 0 Warnings.
Loaded C:\Program Files\PICC\Projects\PCM_Test\pcm_test.cof.
BUILD SUCCEEDED: Tue Sep 30 13:05:37 2008 |
Code: | #include <16F877A.h>
#device adc=8
#FUSES NOWDT, XT, PUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=4000000)
#byte portb = 0x6
#byte trisb=0x86
#int_TIMER0
void TIMER0_isr(void)
{
output_b(0x45);
}
void main()
{
int ui[]={1,2,4,8};
int i=0;
setup_timer_0(RTCC_DIV_16|RTCC_INTERNAL);
trisb=0;
portb=0b11010000;
//output_b(0x78);
for(i=0;i<5;i++)
portb=(portb & 0b11110000) | ui[i];
while (1){};
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Sep 30, 2008 2:53 pm |
|
|
As yo can see in PIC.h ,I declared portb as a byte structure.
Code: | #byte portc = 0x7
#byte portd = 0x8
#byte porte = 0x9
#byte trisa = 0x85
#byte trisb = 0x86
#byte trisc = 0x87
#byte trisd = 0x88
#byte trise = 0x89
#byte intcon = 0xb
struct {
short int ra0 : 1;
short int ra1 : 1;
short int ra2 : 1;
short int ra3 : 1;
short int ra4 : 1;
} porta;
#byte porta = 0x5
struct {
short int rb0 : 1;
short int rb1 : 1;
short int rb2 : 1;
short int rb3 : 1;
short int rb4 : 1;
short int rb5 : 1;
short int rb6 : 1;
short int rb7 : 1;
} portb;
#byte portb = 0x6 |
but you declare it as a byte.
When i changed the definition to byte,The error solved. |
|
![](templates/subSilver/images/spacer.gif) |
|