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

Reading port latch in ccs

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



Joined: 27 Sep 2008
Posts: 3

View user's profile Send private message

Reading port latch in ccs
PostPosted: Sun Sep 28, 2008 4:37 pm     Reply with quote

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).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 28, 2008 4:57 pm     Reply with quote

This thread shows how to read a latch register.
http://www.ccsinfo.com/forum/viewtopic.php?t=36161

This thread has pre-made header files with register addresses:
http://www.ccsinfo.com/forum/viewtopic.php?p=14779
behrouz2007



Joined: 27 Sep 2008
Posts: 3

View user's profile Send private message

PostPosted: Mon Sep 29, 2008 3:17 am     Reply with quote

PCM programmer wrote:
This thread shows how to read a latch register.
http://www.ccsinfo.com/forum/viewtopic.php?t=36161

This thread has pre-made header files with register addresses:
http://www.ccsinfo.com/forum/viewtopic.php?p=14779


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??
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Mon Sep 29, 2008 5:58 am     Reply with quote

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
behrouz2007



Joined: 27 Sep 2008
Posts: 3

View user's profile Send private message

PostPosted: Mon Sep 29, 2008 12:55 pm     Reply with quote

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 -
Guest








PostPosted: Mon Sep 29, 2008 4:17 pm     Reply with quote

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?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 29, 2008 4:40 pm     Reply with quote

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.
Guest








PostPosted: Tue Sep 30, 2008 10:07 am     Reply with quote

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)
Guest








PostPosted: Tue Sep 30, 2008 11:13 am     Reply with quote

Compiler : CCS V 4.069
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 11:15 am     Reply with quote

Post your compiler version. It's a 4-digit number in this format: x.xxx
Guest








PostPosted: Tue Sep 30, 2008 2:00 pm     Reply with quote

PCWHD 4.069
I program a 16F877A
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 2:16 pm     Reply with quote

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){};

}         
Guest








PostPosted: Tue Sep 30, 2008 2:53 pm     Reply with quote

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.
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