Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Questions about PIC Assembly Language Coding

Status
Not open for further replies.

smileguitar

Newbie level 4
Joined
Dec 18, 2007
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,341
assembly language retlw

Code:
		clrf	count	
Message		movf	count, w	
		call	Text	
		xorlw	0x00	
		btfsc	STATUS, Z
		goto	NextMessage
		call	LCD_Char
		call	Delay255
		incf	count, f
		goto	Message

From the coding above, why need to clear count, what it is use for? And why increase f? is it a timing?

How do I explain xorlw for understanding, while I've read the explaination; not really understand it.


Code:
LCD_Line1	movlw	0x80	;move to 1st row, first column
		call	LCD_Cmd
		retlw	0x00

LCD_Line2	movlw	0xc0		;move to 2nd row, first column
		call	LCD_Cmd
		retlw	0x00

LCD_Line1W	addlw	0x80	;move to 1st row, column W
		call	LCD_Cmd
		retlw	0x00

LCD_Line2W	addlw	0xc0	;move to 2nd row, column W
		call	LCD_Cmd
		retlw	0x00

I know that if display a message on line1 of LCD just set R/S to '1'. But what it's mean by the coding above, where move to 1st row, 1st column / move to 2nd row, 1st cloumn / move to 1st row, column W / move to 2nd row, column W ? The purpose of doing this is for?
 

assembler language, retlw

smileguitar said:
From the coding above, why need to clear count, what it is use for? And why increase f?
that is what the programmer intended to do.

The purpose of doing this is for?
for the pure joy of moving a cursor around...

don't you think that your questions are at least not-precise, if not totally stupid?

0x41 0x56 0x45!!
 

pic24 assembly language

Freddie Chopin said:
smileguitar said:
From the coding above, why need to clear count, what it is use for? And why increase f?
that is what the programmer intended to do.

The purpose of doing this is for?
for the pure joy of moving a cursor around...

don't you think that your questions are at least not-precise, if not totally stupid?

0x41 0x56 0x45!!

Well the questions are stupid!! I just really want to understand it because my coding is like showing as below, very simply.The coding showing above is quite different from what I know, and I'm not really understand why need to creat LCD_LINE1W and LCD_LINE2W. Just need someone else to explain it to improve my assembly language. I know you're smart and experienced, but cannot scorn at a student like me without any experience about this. :cry:

Code:
			CALL	DELAY1
			BCF	PORTB,2		; R/S SET TO '0'
			MOVLW	B'00110000'
			MOVWF	PORTD		; FUNCTION SET: 8 BIT INTERFACE
			CALL	CLOCK_E		; E CLOCK 
			MOVLW	B'00001101'			
			MOVWF	PORTD		; DISPALY & CURSOR: SET TO DISPLAY ON; CURSOR UNDERLINE OFF; CURSOR BLINK ON
			CALL	CLOCK_E		; E CLOCK 
			MOVLW	B'00111000'		
			MOVWF	PORTD		; FUNCTION SET: 8 BIT; 2 LINE MODE; 5X10 DOT FORMAT
			CALL	CLOCK_E		; E CLOCK 
			MOVLW	B'00000001'			
			MOVWF	PORTD		; CLEAR DISPLAY
			CALL	CLOCK_E		; E CLOCK 									
			MOVLW	B'00000110'
			MOVWF	PORTD		; CHARACTER ENTRY MODE: INCREMENT; DISPLAY SHIFT ON
			CALL	CLOCK_E		; E CLOCK 
;****************MESSAGES DISPLAY IN LINE 1 ************************

			BSF		PORTB,2		;R/S SET TO '1'
			MOVLW	H'59'	
			MOVWF	PORTD		;DISPLAY "YES"
			CALL	CLOCK_E
			MOVLW	H'45'
			MOVWF	PORTD
			CALL	CLOCK_E
			MOVLW	H'53'
			MOVWF	PORTD
			CALL	CLOCK_E
	
;****************SET LCD TO SECOND LINE*************************
			
			BCF		PORTB,2		; R/S SET TO '0'
			MOVLW	B'11000000'
			MOVWF	PORTD		; JUMP TO 2ND LINE
			CALL	CLOCK_E

;****************MESSAGES DISPLAY IN LINE 2**********************

			BSF		PORTB,2		;R/S SET TO '1'
			MOVLW	H'30'
			MOVWF	PORTD		;0
			CALL	CLOCK_E
			MOVLW	H'31'
			MOVWF	PORTD		;1
			CALL	CLOCK_E
			MOVLW	H'32'
			MOVWF	PORTD		;2
			CALL	CLOCK_E

The knownledge to get from the web is quite limited, also in my college; the only way for me is ask from forum if I'm not understand....
 

assembly movlw ‘m’

Clearing a RAM register before starting a loop is quite common if that register is going to be used inside it.

In the snippet you provide there is not enough to say why the programmer did it, but most probably to start with a zero value.

A simple counter increasing along, as the loop goes, is a good example. To get it started from a known value, what better than zero?
 

what is addlw in the assembly language

atferrari said:
Clearing a RAM register before starting a loop is quite common if that register is going to be used inside it.

In the snippet you provide there is not enough to say why the programmer did it, but most probably to start with a zero value.

A simple counter increasing along, as the loop goes, is a good example. To get it started from a known value, what better than zero?

the programme as below:
Code:
		cblock	0x20			
			count			
			count1			
			counta			
			countb			
			tmp1			
			tmp2
			templcd			
			templcd2	
		endc

LCD_PORT	Equ	PORTA
LCD_TRIS	Equ	TRISA
LCD_RS		Equ	0x04			 
LCD_RW		Equ	0x06
LCD_E		Equ	0x07

		org	0x0000

Initialise	clrf	count
		clrf	PORTA
		clrf	PORTB



SetPorts	bsf 	STATUS,		RP0
		movlw	0x00			
		movwf	LCD_TRIS
		bcf 	STATUS,		RP0

		call	Delay100	


		call	LCD_Init


		clrf	count			
Message		movf	count, w		
		call	Text			 
		xorlw	0x00			
		btfsc	STATUS, Z
		goto	NextMessage
		call	LCD_Char
		call	Delay255
		incf	count, f
		goto	Message

NextMessage	call	LCD_Line2		

		clrf	count			
Message2	movf	count, w		
		call	Text2			
		xorlw	0x00			
		btfsc	STATUS, Z
		goto	EndMessage
		call	LCD_Char
		incf	count, f
		goto	Message2

EndMessage	
		
Stop		goto	Stop			

;Subroutines and text tables

;LCD routines

;Initialise LCD
LCD_Init	movlw	0x20			
		call	LCD_Cmd

		movlw	0x28			
		call	LCD_Cmd

		movlw	0x06			
		call	LCD_Cmd

		movlw	0x0d			
		call	LCD_Cmd

		call	LCD_Clr	

		retlw	0x00

; command set routine
LCD_Cmd		movwf	templcd
		swapf	templcd,	w	
		andlw	0x0f		
		movwf	LCD_PORT
		bcf	LCD_PORT, LCD_RS	
		call	Pulse_e		

		movf	templcd,	w	
		andlw	0x0f		
		movwf	LCD_PORT
		bcf	LCD_PORT, LCD_RS	
		call	Pulse_e			 
		call 	Delay5
		retlw	0x00

LCD_CharD	addlw	0x30
LCD_Char	movwf	templcd
		swapf	templcd,	w	
		andlw	0x0f			 
		movwf	LCD_PORT
		bsf	LCD_PORT, LCD_RS	;RS line to 1
		call	Pulse_e			

		movf	templcd,	w	
		andlw	0x0f			
		movwf	LCD_PORT
		bsf	LCD_PORT, LCD_RS	;RS line to 1
		call	Pulse_e			
		call 	Delay5
		retlw	0x00

LCD_Line1	movlw	0x80			
		call	LCD_Cmd
		retlw	0x00

LCD_Line2	movlw	0xc0			
		call	LCD_Cmd
		retlw	0x00

LCD_Line1W	addlw	0x80			
		call	LCD_Cmd
		retlw	0x00

LCD_Line2W	addlw	0xc0			
		call	LCD_Cmd
		retlw	0x00

LCD_CurOn	movlw	0x0d			
		call	LCD_Cmd
		retlw	0x00

LCD_CurOff	movlw	0x0c			
		call	LCD_Cmd
		retlw	0x00

LCD_Clr		movlw	0x01			
		call	LCD_Cmd
		retlw	0x00

LCD_HEX		movwf	tmp1
		swapf	tmp1,	w
		andlw	0x0f
		call	HEX_Table
		call	LCD_Char
		movf	tmp1, w
		andlw	0x0f
		call	HEX_Table
		call	LCD_Char
		retlw	0x00

Delay255	movlw	0xff		;delay 255 mS
		goto	d0
Delay100	movlw	d'100'		;delay 100mS
		goto	d0
Delay50		movlw	d'50'	;delay 50mS
		goto	d0
Delay20		movlw	d'20'	;delay 20mS
		goto	d0
Delay5		movlw	0x05	;delay 5.000 ms (4 MHz clock)
d0		movwf	count1
d1		movlw	0xC7	;delay 1mS
		movwf	counta
		movlw	0x01
		movwf	countb
Delay_0
		decfsz	counta, f
		goto	$+2
		decfsz	countb, f
		goto	Delay_0

		decfsz	count1	,f
		goto	d1
		retlw	0x00

Pulse_e		bsf	LCD_PORT, LCD_E
		nop
		bcf	LCD_PORT, LCD_E
		retlw	0x00

;end of LCD routines

HEX_Table  	ADDWF   PCL       , f
            	RETLW   0x30
            	RETLW   0x31
            	RETLW   0x32
            	RETLW   0x33
            	RETLW   0x34
            	RETLW   0x35
            	RETLW   0x36
            	RETLW   0x37
            	RETLW   0x38
            	RETLW   0x39
            	RETLW   0x41
            	RETLW   0x42
            	RETLW   0x43
            	RETLW   0x44
            	RETLW   0x45
            	RETLW   0x46


Text		addwf	PCL, f
		retlw	'H'
		retlw	'e'
		retlw	'l'
		retlw	'l'
		retlw	'o'
		retlw	0x00

Text2		ADDWF   PCL, f
            	RETLW   'R'
            	RETLW   'e'
            	RETLW   'a'
            	RETLW   'd'
            	RETLW   'y'
            	RETLW   '.'
            	RETLW   '.'
            	RETLW   '.'
            	RETLW   0x00


		end


Thanks in advanced!!
 

use of movlw assembly language

The count variable is is being used as index to array at Test2. It is initialiazed to 0 to point to first char.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top