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.

Assembly - Help Please

Status
Not open for further replies.

Wilksey

Member
Hi Guys,

I am trying to get back into the assembly boat with PIC's after a long haul with C, I want to see if I can still remember what I used to know!

I have followed Nigel's PIC tutorial 7.7 regarding the Hardware UART,

I have the loop receiving and sending anything in the W register, anybody enlighten me how I can check the incomming data for a string, i.e. Check if the data received is "hello" etc.

I'm sure there was a "simple" way to do it, I just cannot think how.

Thanks

Wilksey
 
Hi Guys,

I am trying to get back into the assembly boat with PIC's after a long haul with C, I want to see if I can still remember what I used to know!

I have followed Nigel's PIC tutorial 7.7 regarding the Hardware UART,

I have the loop receiving and sending anything in the W register, anybody enlighten me how I can check the incomming data for a string, i.e. Check if the data received is "hello" etc.

I'm sure there was a "simple" way to do it, I just cannot think how.

Thanks

Wilksey

cp 0x(hello)

where (hello) is the hex value of hello...whatever the hex value of hello is in whatever character set you are using. This will compare the value and set the e flag if they are equal. the next logical instruction will be a branch to whatever you wanna do when hello is seen. hope that helps :)
 
Apologies...I was looking in my dspic30 datasheet. BAD assumption that they would be similar...well, since there is no compare instruction, I would subtract the value of hello using the subwf instruction then branch if zero.
 
hmm....no branching instructions either....this could be tricky. also, you probably want sublw not subwf and define the hello literal, unless you wanna load that literal into memory :) I coulda sworn the pic16f's had some kinda conditional branching instruction but I don't see one.
 
ok, ok how about this

function _lookforhello
(UART RECIEVE STUFF)
sublw 0x(hello)
btfss zeroflag
goto _lookforhello
goto _hellofound
 
In pseudo-code:
Code:
c = UART_get
if c != "h" return
c = UART_get
if c != "e" return
c = UART_get
if c != "l" return
c = UART_get
if c != "l" return
c = UART_get
if c != "o" return

At this point you have received "hello"
 
In pseudo-code:
Code:
c = UART_get
if c != "h" return
c = UART_get
if c != "e" return
c = UART_get
if c != "l" return
c = UART_get
if c != "l" return
c = UART_get
if c != "o" return

At this point you have received "hello"
Except hhello will not be recognized, because the second char fails the 'e' test and the new test for 'h' only applies to the NEXT char.
 
Thank you all for your responses!

Nigel, that is what I was looking for, thank you!

Your delay routines say for a 4MHz clock, how can I calculate the values for other OSC speeds, I must admit I dont understand the 0xE7 or the 0x04 for counta and countb, and goto $+2 I'm guessing that means current address + 2 locations?

Thanks

Wilksey
 
Hmm, one issue.

I have just realised 9.2 assumes you know what the 4 bytes of the RX register are, but wouldn't I need to look at each byte at a time?

Also, can I use a "function" like your "TEXT" for the LCD, where it just increments the F count to find where in the list it is checking?
 
Thank you all for your responses!

Nigel, that is what I was looking for, thank you!

Your delay routines say for a 4MHz clock, how can I calculate the values for other OSC speeds, I must admit I dont understand the 0xE7 or the 0x04 for counta and countb, and goto $+2 I'm guessing that means current address + 2 locations?

The delay routines were generated by the PICList delay code generator. And yes, that's what $+2 means.
 
Hmm, one issue.

I have just realised 9.2 assumes you know what the 4 bytes of the RX register are, but wouldn't I need to look at each byte at a time?

No, do like my routine does, read the bytes into a buffer, then compare the buffer.

Also, can I use a "function" like your "TEXT" for the LCD, where it just increments the F count to find where in the list it is checking?

Yes, of course you could.
 
Hi Nigel.

I haven't heard of the PICList delay code generator, is this freely available?

So I have 5 variables to store the data such as:
Code:
		byte1
		byte2
		byte3
		byte4
                byte5
and 5 variables that hold the value to check
Code:
                store1
                store2
                store3
                store4
                store5

The loop consists of:
Code:
Loop
	call Recv_RS232
	call Xmit_RS232
	goto Loop

I have added the following:
Code:
Command1
	addwf PCL, f
	retlw	'h'
	retlw	'e'
	retlw	'l'
	retlw	'l'
	retlw	'o'
	retlw	0x00

I have a variable called count like you and have used this:
Code:
clrf	count			;set counter register to zero
Message		movf	count, w		;put counter value in W
		call	Command1		;get a character from the text table
		xorlw	0x00			;is it a zero?
		btfsc	STATUS, Z
		goto Correct
		incf	count, f
		goto	Message
Correct
               bsf PORTD, 0

So if it compares correctly it will set RD0 to high.

But I'm a bit confused as to how to get more than one character from the UART before checking, and how to check multiple commands.

So for example, if I wanted to turn on / off 3 /4 channels I wanted to compare the UART against:

ch1on
ch1off
ch2on
ch2off
ch3on
ch3off
ch4on
ch4off

Or if I wanted to check mutliple lengths I guess I could use a terminating char such as 0x00 or 0x0A , 0x0D?

I have only really turned bits on and off based on inputs using ASM before, I have never used the UART in Assembler.
 
Last edited:
Hi Nigel.

I haven't heard of the PICList delay code generator, is this freely available?

It's online and free, the PICList is one of the biggest and oldest PIC code sites.

So I have 5 variables to store the data such as:
Code:
		byte1
		byte2
		byte3
		byte4
                byte5
and 5 variables that hold the value to check
Code:
                store1
                store2
                store3
                store4
                store5

The loop consists of:
Code:
Loop
	call Recv_RS232
	call Xmit_RS232
	goto Loop

I have added the following:
Code:
Command1
	addwf PCL, f
	retlw	'h'
	retlw	'e'
	retlw	'l'
	retlw	'l'
	retlw	'o'
	retlw	0x00

I have a variable called count like you and have used this:
Code:
clrf	count			;set counter register to zero
Message		movf	count, w		;put counter value in W
		call	Command1		;get a character from the text table
		xorlw	0x00			;is it a zero?
		btfsc	STATUS, Z
		goto Correct
		incf	count, f
		goto	Message
Correct
               bsf PORTD, 0

So if it compares correctly it will set RD0 to high.

But I'm a bit confused as to how to get more than one character from the UART before checking, and how to check multiple commands.

Look how my tutorial did it - four calls to Chk_Keys - crude but simple.

So for example, if I wanted to turn on / off 3 /4 channels I wanted to compare the UART against:

ch1on
ch1off
ch2on
ch2off
ch3on
ch3off
ch4on
ch4off

Or if I wanted to check mutliple lengths I guess I could use a terminating char such as 0x00 or 0x0A , 0x0D?

Yes you could, just as a PC normally does.
 
Hi Nigel,

Wouldn't that only allow for a fixed number of input characters if I call the "check_receive" (mock function) 4 times?

I dont suppose you can do dynamic variables like in C with Assembler can you?
 
Well the input characters in one transmission or reception that can be sent or read respectively is one, you treat information byte wise(going down to the ground level). C like you said does provide the transmission of a 'String' but in reality its just transmitting one byte a time. In assembler you have got to do every thing yourself. You could keep the "check_receive" program in a continuous loop and ask it to read continuously looking for a TC, if it doesnt get that than save it in file registers(you might have to use indirect addressing to keep it simple). When you get the TC then stop reading. Also run a counter every time a character is stored so that you can know how many numbers have come.
 
Last edited:
Hi Nigel,

Wouldn't that only allow for a fixed number of input characters if I call the "check_receive" (mock function) 4 times?

If you don't check for an end of string character yes, it's really down to deciding what you want, and how you want to do it.

I dont suppose you can do dynamic variables like in C with Assembler can you?

You can do anything you want, micro-controllers only run machine code, they don't run C.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top