Discussion in "General help Guidance and Discussion" started by    hemghosh04    Sep 19, 2013.
Fri Sep 20 2013, 10:59 pm
#11
yeh,experimentuk i want to use P3.3 as ir receiving port and P3.6 is unavailable for user.actual problem is

I wish, by pressing remote control button 1 & 2 port3 bit will shift one by one (for 1--it will go like P3.0,P3.1....... AND by pressing switch 2 it will reverse the fact).and when one bit is set others are clr.

Hope i am able to make u understand my problem.
Sat Sep 21 2013, 02:39 am
#12
This bit of code demonstrates one way to do it.
main: 
   mov Pattern,#1   ;//Pattern is a byte of memory
ShiftLoop:
   call delay                 ;// for demo purposes only
   mov A,Pattern
rollbit:   
   rl A  ;//Rotate Accumulator Left    also see Rotate Accumulator Right
   jb 0xe3,rollbit ;//test bit 3 of ACC, if set shift again
   jb 0xe6,rollbit ;//test bit 6 of ACC
   mov Pattern,A
   ADD A,#0x08  ;//keep input high
   mov P3,A
   jmp ShiftLoop
   
   
;**********************************************************

DELAY:
mov R3,#10
REP3:
MOV R1,#0
REP2:
MOV R2,#0
REP1: NOP
DJNZ R2,REP1
DJNZ R1,REP2
DJNZ R3,REP3
RET


[ Edited Sat Sep 21 2013, 09:31 am ]
Sun Sep 22 2013, 08:57 pm
#13
//It is not working,ExperimenterUK.

//This is the RC5 lib code....and i want do the said operation by pressing switch 1 & 2 (i.e I wish, by pressing remote control button 1 & 2 port3 bit will shift one by one (for 1--it will go like P3.0,P3.1....... AND by pressing switch 2 it will reverse the fact).and when one bit is set others are clr.)


VAR1	equ r7                  ;Temporary Variable
TEMP	equ 10H		        ;Temp variable
COUNT	equ 11H		        ;Count
ADDR	equ 12H		        ;Device address
CMD	equ 13H 		;Command
FLIP	bit 00H		        ;Flip bit
TOG	bit 01H 	        ;Temp bit for flip
IR	equ P3.3	        ;IR Receiver connected to this pin
	
	org 00H			;Start of prog
	mov sp,#50H		;Stack pointer initialization
	clr TOG			;Clear temp bit
	
main:
	jb IR,$			;Wait for first bit
	mov VAR1,#255           ;3.024mS delay
	djnz VAR1,$
	mov VAR1,#255
	djnz VAR1,$
	mov VAR1,#255
	djnz VAR1,$
	mov VAR1,#255
	djnz VAR1,$
	mov VAR1,#255
	djnz VAR1,$
	mov VAR1,#100
	djnz VAR1,$
	mov c,IR		;Read Flip bit
	mov FLIP,c
	clr A
	mov COUNT,#5	        ;Count for address
fadd:
	mov VAR1,#255	        ;1.728mS delay for each bit
	djnz VAR1,$
	mov VAR1,#255
	djnz VAR1,$
	mov VAR1,#255
	djnz VAR1,$
	mov VAR1,#4
	djnz VAR1,$
	mov c,IR
	rlc a
	djnz COUNT,fadd
	mov ADDR,A		;Save the address
	clr a
	mov COUNT,#6	        ;Count for Command
fcmd:
	mov VAR1,#255	        ;1.728mS Delay for each bit
	djnz VAR1,$
	mov VAR1,#255
	djnz VAR1,$
	mov VAR1,#255
	djnz VAR1,$
	mov VAR1,#4
	djnz VAR1,$
	mov c,IR
	rlc a
	djnz COUNT,fcmd
	mov TEMP,CMD        	;Save the old command
	mov CMD,a		;Save the new command
	mov a,ADDR		;Cheack for valid address
	cjne a,#00,nvalid
	mov a,TEMP
	cjne a,CMD,valid	;Check for valid command
nvalid:
	ljmp main
valid:				;Key press check
	clr a
	mov c,FLIP
	rlc a
	mov TEMP,a
	clr a
	mov c,TOG
	rlc a
	cjne a,TEMP,valid1
	sjmp nvalid
valid1:
	mov c,FLIP
	mov TOG,c
	mov a,CMD
	clr c

skip0:

cjne a,#1,skip1          ;Check for SW1


skip1:

cjne a,#2,exit          ;Check for SW2

exit:
ljmp main
END                          ; End of program


[ Edited Mon Sep 23 2013, 03:42 pm ]
Mon Sep 23 2013, 02:55 am
#14


//It is not working,ExperimenterUK.
//This is the RC5 lib code....

hemghosh04


Well my code works
I can't comment on yours.
Where is this RC5 lib code from ?
I don't think you should trust it.

My code is just an example of how to shift the bits, it does not deal with reading
the RC5 signal.


[ Edited Mon Sep 23 2013, 03:04 am ]
Mon Sep 23 2013, 09:11 am
#15
The code is taken from Site Owner Ajay Bhargav,and it is working,i.e it response the RC5 code and act accordingly,but when i put your code it is not working some how..
Mon Sep 23 2013, 03:45 pm
#16
I do not see any problem here, can you tell me what exactly are you putting in this area. post your exact code:
skip0:
cjne a,#1,skip1          ;Check for SW1
skip1:
cjne a,#2,exit          ;Check for SW2
exit:
ljmp main
Mon Sep 23 2013, 10:43 pm
#17
Pattern equ 52H

DELAY:
mov R3,#10
REP3:
MOV R1,#0
REP2:
MOV R2,#0
REP1: NOP
DJNZ R2,REP1
DJNZ R1,REP2
DJNZ R3,REP3
RET
skip0:
cjne a,#1,skip1 ;Check for SW1
mov Pattern,#1 ;//Pattern is a byte of memory
ShiftLoop:
call delay ;// for demo purposes only
mov A,Pattern
rollbit:
rl A ;//Rotate Accumulator Left
jb 0xe3,rollbit ;//test bit 3 of ACC, if set shift again
jb 0xe6,rollbit ;//test bit 6 of ACC
mov Pattern,A
ADD A,#0x08 ;//keep input high
mov P3,A
jmp ShiftLoop

skip1:
cjne a,#2,exit ;Check for SW2
mov Pattern,#1 ;//Pattern is a byte of memory
ShiftLoop:
call delay ;// for demo purposes only
mov A,Pattern
rollbit:
rr A ;//Rotate Accumulator right
jb 0xe3,rollbit ;//test bit 3 of ACC, if set shift again
jb 0xe6,rollbit ;//test bit 6 of ACC
mov Pattern,A
ADD A,#0x08 ;//keep input high
mov P3,A
jmp ShiftLoop

exit:
ljmp main
Tue Sep 24 2013, 12:54 am
#18
We need your *full* code as loaded into the micro.
RC5 code and port output code together.
Tue Sep 24 2013, 08:20 am
#19
// THIS IS THE FULL CODE,WHERE IR IS CONNECTED TO P3.3 AND I WANT TO OUT PUT FROM P3.0,P3.1,P3.2,P3.4,P3.5,P3.7

VAR1 equ r7 ;Temporary Variable
TEMP equ 10H ;Temp variable
COUNT equ 11H ;Count
ADDR equ 12H ;Device address
CMD equ 13H ;Command
FLIP bit 00H ;Flip bit
TOG bit 01H ;Temp bit for flip
IR equ P3.3 ;IR Receiver connected to this pin
Pattern equ 52H

org 00H ;Start of prog
mov sp,#50H ;Stack pointer initialization
clr TOG ;Clear temp bit

main:
jb IR,$ ;Wait for first bit
mov VAR1,#255 ;3.024mS delay
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#100
djnz VAR1,$
mov c,IR ;Read Flip bit
mov FLIP,c
clr A
mov COUNT,#5 ;Count for address
fadd:
mov VAR1,#255 ;1.728mS delay for each bit
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#4
djnz VAR1,$
mov c,IR
rlc a
djnz COUNT,fadd
mov ADDR,A ;Save the address
clr a
mov COUNT,#6 ;Count for Command
fcmd:
mov VAR1,#255 ;1.728mS Delay for each bit
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#255
djnz VAR1,$
mov VAR1,#4
djnz VAR1,$
mov c,IR
rlc a
djnz COUNT,fcmd
mov TEMP,CMD ;Save the old command
mov CMD,a ;Save the new command
mov a,ADDR ;Cheack for valid address
cjne a,#00,nvalid
mov a,TEMP
cjne a,CMD,valid ;Check for valid command
nvalid:
ljmp main
valid: ;Key press check
clr a
mov c,FLIP
rlc a
mov TEMP,a
clr a
mov c,TOG
rlc a
cjne a,TEMP,valid1
sjmp nvalid
valid1:
mov c,FLIP
mov TOG,c
mov a,CMD
clr c

DELAY:
mov R3,#10
REP3:
MOV R1,#0
REP2:
MOV R2,#0
REP1: NOP
DJNZ R2,REP1
DJNZ R1,REP2
DJNZ R3,REP3
RET
skip0:
cjne a,#1,skip1 ;Check for SW1
mov Pattern,#1 ;//Pattern is a byte of memory
ShiftLoop:
call delay ;// for demo purposes only
mov A,Pattern
rollbit:
rl A ;//Rotate Accumulator Left
jb 0xe3,rollbit ;//test bit 3 of ACC, if set shift again
jb 0xe6,rollbit ;//test bit 6 of ACC
mov Pattern,A
ADD A,#0x08 ;//keep input high
mov P3,A
jmp ShiftLoop

skip1:
cjne a,#2,exit ;Check for SW2
mov Pattern,#1 ;//Pattern is a byte of memory
ShiftLoop:
call delay ;// for demo purposes only
mov A,Pattern
rollbit:
rr A ;//Rotate Accumulator right
jb 0xe3,rollbit ;//test bit 3 of ACC, if set shift again
jb 0xe6,rollbit ;//test bit 6 of ACC
mov Pattern,A
ADD A,#0x08 ;//keep input high
mov P3,A
jmp ShiftLoop

exit:
ljmp main

END
Tue Sep 24 2013, 01:04 pm
#20
ok I would say.. blunder mistake. Always remember, assembly code runs sequentially i.e. controller will execute every statement as it is written... Now if you look closely at your code after
mov c,FLIP
mov TOG,c
mov a,CMD
clr c


there is a DELAY subroutine and end of routine there is "RET" so controller will read IR, execute delay and return. which is not what you want. Delay is a subroutine and should not be placed within the flow of program. subroutines should always be written after end of main execution. So move your delay routine after
exit:
ljmp main


try it and let us know.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am