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.

variables in assembly

Status
Not open for further replies.

megan

New Member
hi there..

im trying to save an ascii character into a register variable as follows:
Code:
CBLOCK 0X20		
		A1
		

ENDC

movlw      'A'
movwf      A1

however the content returned in variable A1 is 0x20 (which is its address)

i then tried

Code:
CBLOCK 0X20		
		A1
		

ENDC

movlw      0x41
movwf      A1

the same thing still happened..

is my syntax okay??

hopefully someone can help me on this
thanks guys :)
 
If that is what you have done then A1 contains 'A'. Do you have an example that demonstrates your problem?

Mike.
 
i sent out the value of A1 to my PC and my VB program receives a "space" which is 0x20
i then added A2 in the cblock as follows

CBLOCK 0X20
A1
A2

ENDC

movlw 'A'
movwf A2

this time round, i received the character '!' on my VB screen which is the ASCII character valued at 0x21 (address of A2)
 
i sent out the value of A1 to my PC and my VB program receives a "space" which is 0x20
i then added A2 in the cblock as follows



this time round, i received the character '!' on my VB screen which is the ASCII character valued at 0x21 (address of A2)

You're still not showing us the code you're using to read the variable, please show us that - as it seems likely your fault is there.
 
Post the code and we'll work out what's wrong. My best guess is that you're doing movlw A1 and then movwf TXREG.

Mike.
 
Nigel, I believe that the OP is having a issue with CBLOCK.


Megan, when you declare:

CBLOCK 0x20{
A1
}

It does not mean that A1 will be initializated with the value 0x20. It means that the "variable" A1 will be allocated at the Address 0x20 of the RAM.
 
yes you guys are right!!! wow....awesome...

i forgot to move the register A1 into the w register before i movwf TXREG...

im so sorry for taking your time.thank you all for your help!

i have another question..for the commands btfss and xorlw...does it only work for ports with full 8 bits (im using the 877A so that would be ports B,C and D.) ? or does it work equally well for ports A and E..thanks again!!
 
Last edited:
i see..well im having problems with that now...
im doing a routine to poll 3 ports to test whether PIN 0 of each respective PORT is HIGH or LOW. when it is a high, the string ON will be saved in predefined registers. when it is a low, the string OFF will be saved instead.
This is my code:

Code:
###########################TESTING port A###
[B]CHECKA	MOVF	PORTA,W
		XORLW	0X01
		BTFSS	STATUS,Z
		GOTO	LOW1
		GOTO	HIGH1[/B]

LOW1	MOVLW	0X4F
		MOVWF	A1
		MOVLW	0X46
		MOVWF	A2
		MOVLW	0X46
		MOVWF	A3
		GOTO	CHECKB

HIGH1	MOVLW	0X4F
		MOVWF	A1
		MOVLW	0X4E
		MOVWF	A2
		MOVLW	0X20
		MOVWF	A3
		GOTO	CHECKB
##########################TESTING port B##########
CHECKB	movf	PORTB,W
		XORLW	0X01
		btfss	STATUS,Z
		GOTO	LOW2
		GOTO	HIGH2

LOW2	MOVLW	0X4F
		MOVWF	B1
		MOVLW	0X46
		MOVWF	B2
		MOVLW	0X46
		MOVWF	B3
		GOTO	CHECKC


HIGH2	MOVLW	0X4F
		MOVWF	B1
		MOVLW	0X4E
		MOVWF	B2
		MOVLW	0X20
		MOVWF	B3
		GOTO	CHECKC

##################TESTING port D##########
CHECKC	MOVF	PORTD,W
		XORLW	0X01
		btfss	STATUS,Z
		GOTO	LOW3
		GOTO	HIGH3


LOW3	MOVLW	0X4F
		MOVWF	C1
		MOVLW	0X46
		MOVWF	C2
		MOVLW	0X46
		MOVWF	C3
		GOTO	SEND


HIGH3	MOVLW	0X4F
		MOVWF	C1
		MOVLW	0X4E
		MOVWF	C2
		MOVLW	0X20
		MOVWF	C3
		GOTO	SEND

everything seems to be working fine (Port B and PortD) except for PortA (in bold) which does not seem to be able to detect that a pin is HIGH (The routine always jumps to the label LOW1 regardless of the state of the pin.)

when i removed portA and changed it to PortB, it was able to detect the correct state of the pin..

Code:
CHECKA	MOVF	PORTB,W
		XORLW	0X01
		BTFSS	STATUS,Z
		GOTO	LOW1
		GOTO	HIGH1

i also tried by changing it to Port E and this time round it could not work...so my conclusion was only the 8 bit ports worked...and that was why the question in the earlier post...

hope you guys can help me on this...thank you all dearly =)
 
awesome! i read the datasheet again and i realized i did not clear the ADON bit of the ADCON0 register.

problem solved!

thank you Mr. Goodwin=)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top