Bernard Tyers wrote: > > Hi, > Beginner mode :) > > Could someone explain the use for the TRIS (TRISTATE) register in a C54? > > In particular: > > MOVLW 0x0F ; load the working register 'W' with the control code for > ; the data direction register, in this case the HEX > ; number 0F to set the port as inputs > TRIS 5 ; set the data control register for register 5 which is > ; port A by moving the data in W to the data control > ; register for the port > > In the PIC16C54 datasheet I find the TRIS operand means: > > Description: TRIS register 'f' (f=5,6 or 7) is loaded with the contents of > the W register. > > is the TRIS register PORT A? i understand moving the data (MOVLW 0x0F) The TRIS instruction takes a value from the W register and places it into the register that controls whether the PORT pins are set as inputs or outputs. This is the method that this chip uses to set port pins as inputs or outputs. Any bits that are set to 1 set the corresponding pin to an input, and any bits that are set to 0 set the corresponding bits to an output. PORTA is located at address 0x05, and PORTB at 0x06. To set PORTA as all inputs and PORTB as all outputs you could do this... movlw 0x0F TRIS PORTA ; porta = all inputs movlw 0x00 TRIS PORTB ; portb = all outputs You can set inputs and outputs in the same port like this... movlw b'11110000' TRIS PORTB ; PB7-4 = inputs, PB3-0 = outputs I use binary representation here because it is easier to see what pins are inputs and what pins are outputs. This assumes that somewhere in your code you have PORTA defined as 0x05 and PORTB defined as 0x06. This can come from using the 16c5x include file by having this written at the start of your ASM code. list P=16C54 #include "p16c5x.inc" You can open the p16c5x.inc file with a text editor and see that it defines all the registers inside the 16C5x range of chips. Alternately, you can do this, albeit a bit messier... PORTA equ 0x05 PORTB equ 0x06 > if it set the data control register for register 6, would that be PORT B? Yes, as explained above. -- Best regards Tony mICros http://www.bubblesoftonline.com mailto:sales@bubblesoftonline.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu