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

PIC16F1934 TRIS

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



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PIC16F1934 TRIS
PostPosted: Thu May 20, 2010 12:22 am     Reply with quote

Hello,

I am using a PIC16F1934 to interface a custom made lcd.

I cannot get the tris registers to work. The "set_tris" function does not work.

I tried this:

Code:


#byte   TRISA = 0x8C
#byte   TRISB = 0x8D
#byte   TRISC = 0x8E
#byte   TRISD = 0x8F
#byte   TRISE = 0x90


TRISA=0b00001100;
TRISB=0b00000110;
TRISC=0b00011000;




The above should work but the disassembly listing says:
Code:


      TRISA=0b00001100;
      MOVLW 0xc
      MOVWF 0xc

      TRISB=0b00000110;
      MOVLW 0x6
      MOVWF 0xd

      TRISC=0b00011000;
      MOVLW 0x18
      MOVWF 0xe



for some reason it writes to the PORT register and not the tris register.

And the strangest thing, I tried this in assembly:

Code:

   #asm
   CLRF   0x8C

   MOVLW   0x6
   MOVWF   0x8d

   MOVLW   0x18
   MOVWF   0x8e

   CLRF   0x8f 
       #endasm 


The result is again:

Code:


#asm
CLRF   0x8C
CLRF 0xc
               
MOVLW   0x6
 MOVLW     0x6
MOVWF   0x8d
 MOVWF     0xd
               
MOVLW   0x18
 MOVLW     0x18
MOVWF   0x8e
 MOVWF     0xe
             
CLRF   0x8f 
 CLRF 0xf
#endasm 


It does not write to the register that I want. It write to the port register.

Any help appreciated.

George.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 20, 2010 12:34 am     Reply with quote

This type of PIC was recently added to the compiler. What's your
compiler version ?
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Thu May 20, 2010 3:25 am     Reply with quote

4.093
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Thu May 20, 2010 4:25 am     Reply with quote

And another question,

where is the EEPROM located? org 0x2100 does not work.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Thu May 20, 2010 4:52 am     Reply with quote

Look a few lines _above_ the assembler you show. The compiler will not switch banks, if it is already using the right page. Writing to address 0c, would be 'right', if the BSR is already pointing to the required page...

On the EEPROM, details of this are always found in the 'programming' data sheet for the chip. 0x1E000 for your chip.

Best Wishes
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Thu May 20, 2010 5:01 am     Reply with quote

Ok, I agree with the bank Nr as far as it goes for assembly but in C it should work with the method below without caring about the banks. right?
Code:

#byte   TRISA = 0x8C
#byte   TRISB = 0x8D
#byte   TRISC = 0x8E
#byte   TRISD = 0x8F
#byte   TRISE = 0x90


TRISA=0b00001100;
TRISB=0b00000110;
TRISC=0b00011000;


I have already tried 0x1E000, it does not work.

#rom 0x1E000= {0,1,32,45,66,75}

Any ideas?

Thanks for the reply!
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Thu May 20, 2010 5:11 am     Reply with quote

I found a post by PCM programmer, he says:

http://www.ccsinfo.com/forum/viewtopic.php?t=42386&highlight=0x2100

Quote:


To get the physical address in the PIC, divide the Hex file address by 2.
This means the data eeprom starts at 0xF000.



I tried this and it works.

One problem solved!


Now, I am searching for the tris problem.

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 20, 2010 3:26 pm     Reply with quote

I installed vs. 4.093 and compiled the following test program:
Code:

#include <16F1934.h>
#fuses INTRC_IO, NOWDT, PUT, NOLVP
#use delay(clock=4000000)

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

set_tris_a(0x55);
set_tris_b(0xAA);
set_tris_c(0x22);

while(1);
}


Here is part of the .LST file, with my comments added.
It shows that the correct TRIS register addresses are being used.
The TRIS registers are in Bank 1, and that's the currently selected
bank in the code below:
Code:

0016:  MOVLB  01    // Bank 1
0017:  CLRF   17    // WDTCON = 0
0018:  MOVLW  07
0019:  MOVWF  1C    // ADRESH = 0  ***Bug: not needed
.................... 
.................... set_tris_a(0x55);
001A:  MOVLW  55
001B:  MOVWF  0C    // TRISA = 0x55
.................... set_tris_b(0xAA);
001C:  MOVLW  AA
001D:  MOVWF  0D    // TRISB = 0xAA
.................... set_tris_c(0x22);
001E:  MOVLW  22
001F:  MOVWF  0E    // TRISC = 0x22
.................... 
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Thu May 20, 2010 11:06 pm     Reply with quote

Yes, but TRISA = 0x8C and not 0xC.

Am I missing something here?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 20, 2010 11:33 pm     Reply with quote

It's all about bank selection. Look at this table in the PIC data sheet:
Quote:
TABLE 3-3: PIC16F1933/1934 MEMORY MAP, BANKS 0-7

Find the row for 00Ch on the left. Then find the column for Bank 1.
Now find the intersection of the row and the column. It says "TRISA".
That's because it's at offset 0x0C and it's in Bank 1. Look just to the
left of "TRISA", and you'll see the address, which is 0x8C.
Sica001



Joined: 14 Dec 2011
Posts: 1

View user's profile Send private message

PostPosted: Wed Dec 14, 2011 2:51 am     Reply with quote

I try yesterday with 4.129 version and problem is not solved. In my program output is ok but input not work(even input_state). Somebody know how to solve this problem ?

Regards
Marius
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Dec 14, 2011 7:50 am     Reply with quote

Marius,

Please don't ask your new and unrelated question in a thread that was solved and closed 1.5 years ago.

We have no clue what you are talking about.
Start a new thread. Post a short but complete example program of maximum 20 lines. If the question is related to inputs and outputs then describe in short the hardware connected to these pins, even better, post a schematic.
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