Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC PortB code problem

Status
Not open for further replies.

richard.c

New Member
lHi All,

Would appreciate some help on a bit of coding for a Pic portB
I originally used the lcd routine written by Ron Kreymborg, but am now wanting to slightly change it, but I just cannot work out one line of the code, as shown in bold type. Radix is set to hex.

Its the ‘ 1 << lcd_RW ’ part of the movlw statement - 1, left shift, lcd-rw ?

The point of the exercise is that I am trying to fully detach the unused PortB,0 from the routine.

many thanks

Richard



; Ron Kreymborg
;******************************************************************
; Flags -
lcd_Bflg equ 0
lcd_RSflg equ 1

; I/O portB -
lcd_BUSY equ 7 ; input - LCD is busy (0x80)
lcd_R_W equ 3 ; output - LCD Read/Write (0x08)
lcd_RS equ 2 ; output - Register Select (0x04)
lcd_E equ 1 ; output - LCD Enable (0x02)


; Check whether the LCD is busy. Loop until it isn't. When
; it's free, output the byte passed in W, MS nibble first.

lcd_d bsf lcd_flags,lcd_RSflg ; set RS flag for data
goto lcd_o1
lcd_c bcf lcd_flags,lcd_RSflg ; clear RS flag for commands
lcd_o1 movwf lcd_temp ; save control word
dotris b'11110000',PORTB ; RB7-4 as inputs for busy
movlw 1 << lcd_R_W
movwf PORTB ; set up for read
 
The instruction will load W with 2^(lcd_R_W). To understand this, think in binary. 1 shifted left zero places becomes B'00000001' (unchanged), shifted 3 places becomes B'0001000' etc.

In the case above it is the same as movlw b'00001000'

HTH

Mike
 
Thanks for that - I though the code may have been as you said, but it wasn't clear to me in the way he had coded it using the arithmetic operators, particularly as all his other codes are in the movlw b' ' format.

One point it does make me wonder, as someone using MpAsm, the use of the Directive Language and such Arithmetic Operators.
Although a certain few are always used eg ORG and END, generally most code does not use many different directives.
I have tended not to use them, for some reason, probably mistaken, I've associated them as part of a higher language.

Can you say how I should view and be using these Directives ?
eg:-
as code that is part of an old system and should be avoided -
use as any other code -
use as much as possible, the way to go-
use if you want to move towards higher level languages

thanks

Richard
 
I use this all the time.
Here are some lines copied out of a recent project to show how I use it.
Code:
		movlw	(0<<NOT_RBPU|0<<INTEDG|0<<T0CS|0<<T0SE|0<<PSA|B'000'<<PS0)
		movwf	OPTION_REG

		movlw	(b'00'<<T1CKPS0|1<<T1OSCEN|1<<NOT_T1SYNC|1<<TMR1CS|1<<TMR1ON)
		movwf	T1CON

		movlw	(0<<CCP1X|0<<CCP1Y|b'1011'<<CCP1M0)
		movwf	CCP1CON;	

		movlw	(0<<CSRC|0<<TX9|1<<TXEN|0<SYNC|1<<BRGH|0<<TRMT|0<<TX9D)
		movwf	TXSTA

		movlw	(1<<SPEN|0<<RX9|0<<SREN|1<<CREN|0<<ADDEN|0<<FERR|0<<OERR|0<<RX9D)
		movwf	RCSTA

		movlw	(1<<GIE|1<<PEIE|[COLOR="Blue"]0<<TMR0IE[/COLOR]|0<<INTE|0<<RBIE|0<<TMR0IF|0<<INTF|0<<RBIF)
		movwf	INTCON

I find it easier to use as I can just set the values and not have to worry which bit is which. It may look confusing at first but makes it much easier to change things. For example, if I wish to enable timer0 interrupts then I change 0<<TMR0IE to 1<<TMR0IE - no need to look at the data sheet.

I think it's just a personal choice and you should just do what you are comfortable with.

Mike.
 
Hi Mike,
Yes I see what you mean, its a good way to use them.
Will have to open the blinkers !

thanks again
Richard
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top