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

Assembly Code for data saving from keypad in Registers(8051)

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 want assembly code that is get a two digit number from user(from matrix keypad) and then Save it in R7 and R6 registers.
I write below code but this is not work true for second digit.

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
ORG 0
        LJMP MAIN
        
        
        EX0ISR:       
                
                 CJNE R0,#0,Number_2
                 ACALL Scan
                 MOV A,R1
                 MOV R7,A
                 MOV R2,#1
                 RETI
                 Number_2: 
         CJNE R2,#1,Nothing              
                 ACALL Scan
                 MOV A,R1
                 MOV R6,A
                 MOV R0,#2
                 RETI
                 Nothing:
         
        RETI
        
        
        
        ORG 00100H
                
                MAIN:
        MOV A,#00000111B        
        MOV P2,A                
                MOV IE,#85H
                SETB IT0
                SETB IT1
                MOV A,R6
                MOV P1,A
                SJMP MAIN
                                
                        
                        Scan:
                        MOV A,#11111111B                
            MOV P2,A    
                        CLR P2.0        
                    JB P2.3,J1
                        MOV R1,#3
                        RET
                        J1:
                        JB P2.4,J2
                        MOV R1,#6
                        RET
                        J2:
                    JB P2.5,J3
                        MOV R1,#9
                        RET
                        J3:
                   JB P2.6,J4
                        MOV R1,#10
                        RET
                        J4:
                   SETB P2.0
                   CLR P2.1
                   JB P2.3,J5
                        MOV R1,#2
                        RET
                        J5:
                        JB P2.4,J6
                        MOV R1,#5
                        RET
                        J6:
                    JB P2.5,J7
                        MOV R1,#8
                        RET
                        J7:
                   JB P2.6,J8
                        MOV R1,#0
                        RET
                        J8:
                        SETB P2.1
                    CLR P2.2
                   JB P2.3,K1
                        MOV R1,#1
                        RET
                        K1:
                        JB P2.4,K2
                        MOV R1,#4
                        RET
                        K2:
                    JB P2.5,K3
                        MOV R1,#7
                        RET
                        K3:
                   JB P2.6,K4
                        MOV R1,#11
                        RET
                        K4:
                RET
                
                
                END

 
Last edited by a moderator:

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
Please don't make multiple threads for one problem. Check the below code and edit it as per your requirement. When you are asking a help please make your side clear and post necessary documents regarding the project.

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
ORG 00H
                SJMP MAIN
                ORG 30H                
MAIN:
        /* MOV A,#00000111B        
         MOV P2,A                
         MOV IE,#85H
         SETB IT0
         SETB IT1
         MOV A,R6
         MOV P1,A  */
                 ACALL SCAN
                 MOV R7,A
                 ACALL SCAN
                 MOV R6,A
         /*      TWO DIGITS ARE STORED IN R7,R6 RESPECTIVELY .PLEASE ENTER YOUR CODE FOR FREQUENCY GENERATION HERE
                  */
         SJMP MAIN                              
                        
SCAN:
          MOV A,#11111111B                
          MOV P2,A    
          CLR P2.0        
          JB P2.3,J1
                  JNB P2.3,$   ;KEY DEBOUNCE, DELETE THIS LINE TO CHECK THE EFFECT
          MOV A,#3
          RET
   J1:
          JB P2.4,J2
                  JNB P2.4,$
          MOV A,#6
          RET
   J2:
          JB P2.5,J3
                  JNB P2.5,$     ;
          MOV A,#9
          RET
   J3:
          JB P2.6,J4
                  JNB P2.6,$
          MOV A,#10
          RET
   J4:
          SETB P2.0
          CLR P2.1
          JB P2.3,J5
                  JNB P2.3,$
          MOV A,#2
          RET
   J5:
          JB P2.4,J6
                  JNB P2.4,$
          MOV A,#5
          RET
   J6:
          JB P2.5,J7
                  JNB P2.5,$
          MOV A,#8
          RET
   J7:
          JB P2.6,J8
                  JNB P2.6,$
          MOV A,#0
          RET
   J8:
          SETB P2.1
          CLR P2.2
          JB P2.3,K1
                  JNB P2.3,$
          MOV A,#1
          RET
   K1:
          JB P2.4,K2
                  JNB P2.4,$
          MOV A,#4
          RET
   K2:
          JB P2.5,K3
                  JNB P2.5,$
          MOV A,#7
          RET
   K3:
          JB P2.6,K4
                  JNB P2.6,$
          MOV A,#11
          RET
   K4:    AJMP SCAN
                  
          END

 
Last edited:

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 but i have one question where is the subroutine of interrupt in your program?
and your code frequent altered the INT pin.
keypad.png
 
Last edited:

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
move the following lines to ISR

Code ASM - [expand]
1
2
3
4
5
6
ORG 30H
  ACALL SCAN
  MOV R7,A
  ACALL SCAN
  MOV R6,A
  RETI

 

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
When i do it it's not run true.
 

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,but not working true.
 

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 have one another question how to generate signal in range of 100 to 990 HZ with timer interrupt suppose frequency and duty cycle in R7 and R6.
 

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 will answer you. but first tell me what you got wrong about the code?. i have double checked and it seems ok.
 

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
well,first check the values of r6 and r7. after two key press you have the values in the corresponding registers. where did you add the lines to output it to P1?. i didn't wrote that in my code.

sim.JPG
 

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 Entered for show registers in here:
PHP:
MAIN:            
         MOV IE,#81H
         MOV A,R7
         MOV P1,A 
		 MOV P2,#11111000B
	 /*	 TWO DIGITS ARE STORED IN R7,R6 RESPECTIVELY .PLEASE ENTER YOUR CODE FOR FREQUENCY GENERATION HERE
		  */
         SJMP $
But after enter two keypad nothing show on P1
 

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
you should enter that in the ISR


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
isr:              ACALL SCAN
                  MOV R7,A
                  MOV P1,A
                  ACALL SCAN
                  MOV R6,A
                  MOV P3,A
                  JNB P2.3,$
                  JNB P2.4,$
                  JNB P2.5,$
                  JNB P2.5,$              
                  RET

 
Last edited:

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,why you use JNB in isr?

- - - Updated - - -

and when we enter R6 and R7 program goes to MAIN?
 

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
when the program exits from isr last scanning status retained ,to avoid that JNB instructions are used. remove that lines and run your program to check the effect. I have stopped the main program using 'sjmp $'. you can remove that and enter your program loop there. then you have to use some status bits to know keypad status. when the keypad is active make the status bit 1 and always check the status bit in your main loop.
 

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 have one another question how to generate signal in range of 100 to 990 HZ with timer interrupt suppose frequency and duty cycle in R7 and R6.

- - - Updated - - -

i added to code this:
PHP:
isr:	  

                 ACALL SCAN
                 MOV R7,A
                 ACALL SCAN
                 MOV R6,A
				 MOV B,R7
				 MOV A,#10
				 MUL AB
				 ADD A,R6
				 MOV R7,A      //R7 0.1 Frequency
				 ACALL SCAN
                 ACALL SCAN
                 MOV R5,A
				 ACALL SCAN
                 MOV R4,A
				 MOV B,R5
				 MOV A,#10
				 MUL AB
				 ADD A,R4
				 MOV R6,A
                 ACALL SCAN
				
          
		  JNB P2.3,$
		  JNB P2.4,$
		  JNB P2.5,$
		  JNB P2.5,$	
               	MOV R2,#2		  
		  RET
and add to main:
PHP:
MAIN:            
         MOV IE,#81H
         MOV A,R6
         MOV P1,A 
		 MOV P2,#11111000B
	 /*	 TWO DIGITS ARE STORED IN R7,R6 RESPECTIVELY .PLEASE ENTER YOUR CODE FOR FREQUENCY GENERATION HERE
		  */
         CJNE R2,#2,MAIN
		    MOV P1,#0FFH
         	SJMP MAIN
but when i enter digits P1 not change.what's the problem?

- - - Updated - - -

where program goes after entering digits?
 

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 have one another question how to generate signal in range of 100 to 990 HZ with timer interrupt suppose frequency and duty cycle in R7 and R6.when i write internal interrupt routine program didn't go in it.can you put an example for me?
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top