Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[Moved] Why this 8051 code not functioning as expected?

Status
Not open for further replies.

panda1234

Full Member level 2
Joined
Jan 22, 2015
Messages
125
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Activity points
1,172
Hi,
I write sample code for using interrupt but when i simulate it into Proteus P1.1 is 0 from start and without pressing interrupt button


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
ORG 0
    LJMP MAIN
    EX0ISR:   
            CLR P1.1
    RETI
    ORG 0030H
        MAIN:
        MOV A,#00000111B    
        MOV P2,A        
        MOV IE,#85H
        SETB IT0
        SETB IT1
            SJMP MAIN
                END




In this code for 8051 i want to read data from matrix keyboard and save it in register R1 but this code just work one time why?


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
ORG 0
        LJMP MAIN
        EX0ISR:   
                MOV A,#11111111B        
        MOV P2,A                
                CLR P2.0        
                JB P2.3,J1
                        MOV R1,#3
                        J1:
                        JB P2.4,J2
                        MOV R1,#6
                        J2:
                    JB P2.5,J3
                        MOV R1,#9
                        J3:
                   JB P2.6,J4
                        MOV R1,#10
                        J4:
                SETB P2.0
                CLR P2.1
                JB P2.3,J5
                        MOV R1,#2
                        J5:
                        JB P2.4,J6
                        MOV R1,#5
                        J6:
                    JB P2.5,J7
                        MOV R1,#8
                        J7:
                   JB P2.6,J8
                        MOV R1,#0
                        J8:
                        SETB P2.1
                    CLR P2.2
                   JB P2.3,K1
                        MOV R1,#1
                        K1:
                        JB P2.4,K2
                        MOV R1,#4
                        K2:
                    JB P2.5,K3
                        MOV R1,#7
                        K3:
                   JB P2.6,K4
                        MOV R1,#11
                        K4:
                        
        RETI
        ORG 0030H
                MAIN:
        MOV A,#00000111B        
        MOV P2,A                
                MOV IE,#85H
                SETB IT0
                SETB IT1
                MOV P1,R1
                        SJMP MAIN
                                END

 
Last edited by a moderator:

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
18,006
Helped
4,038
Reputation
8,076
Reaction score
3,952
Trophy points
113
Activity points
118,901
Hi,

P1.1 is 0 from start and without pressing interrupt button
What else do you expect? And why?

Klaus
 

panda1234

Full Member level 2
Joined
Jan 22, 2015
Messages
125
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Activity points
1,172
Thanks,So what should i do?
 

S.P.S

Member level 5
Joined
Oct 30, 2011
Messages
89
Helped
19
Reputation
38
Reaction score
19
Trophy points
1,298
Location
Thodupuzha, India, India
Activity points
1,742
i must ask, what are you trying to do?. why are you using the interrupt pin??. i have edited the keyboard scanning program. Please note the changes and edit as per your requirement.
Code:
						ORG 0
        				LJMP MAIN
  						ORG 03H
						ACALL SCAN                 
				        RETI
				        ORG 0030H
  MAIN:
				        MOV A,#00000111B        
				        MOV P2,A                
		                MOV IE,#85H
		                SETB IT0
		                SETB IT1
		                MOV P1,R1
                        SJMP $

 SCAN:   				MOV A,#11111111B        
        				MOV P2,A                
                		CLR P2.0        
                		JB P2.3,J1
                        MOV R1,#3
            J1:
                        JB P2.4,J2
                        MOV R1,#6
            J2:
                    	JB P2.5,J3
                        MOV R1,#9
            J3:
	                    JB P2.6,J4
	                    MOV R1,#10
            J4:
		                SETB P2.0
		                CLR P2.1
		                JB P2.3,J5
                        MOV R1,#2
            J5:
                        JB P2.4,J6
                        MOV R1,#5
            J6:
                    	JB P2.5,J7
                        MOV R1,#8
            J7:
                   		JB P2.6,J8
                        MOV R1,#0
            J8:
                        SETB P2.1
                    	CLR P2.2
                   		JB P2.3,K1
                        MOV R1,#1
            K1:
                        JB P2.4,K2
                        MOV R1,#4
            K2:
                   	    JB P2.5,K3
                        MOV R1,#7
            K3:
                   		JB P2.6,K4
                        MOV R1,#11
            K4:	 		MOV P1,R1
						AJMP SCAN


                        END
in the above program the interrupts triggers keyboard scanning and exits only on reset.
 

panda1234

Full Member level 2
Joined
Jan 22, 2015
Messages
125
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Activity points
1,172
I'm Trying to make a pulse generator in that user first enter one number that show frequency and then get duty cycle and then generate it but in this code i cut that section.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top