show hexadecimal value on 7_segment 8051 code

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
Visit site
Activity points
1,172
Hi,
I'm beginner with 8051 assembly code i want to write a program that read 4 input and show its hexadecimal value on 7 seg and the code should be in infinite loop.
thanks
 

It is very easy. Make a mask array of 16 elements and store the 7 Segment masks for displaying the hexadecimal digits in the array. No make a switch statement and based on the 4 bit input values display the required 7 segment digit.

mikroC PRO 8051 project attached. Also Proteus 8.2 SP2 format file attached.


Code C - [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
char mask[16] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x5F, 0x7C, 0x58, 0x5E, 0x7B, 0x71};
char prevVal = 20;
 
void main() {
 
     P0 = 0x00;
     P1 = 0x0F;
     P2 = 0x00;
     P3 = 0x00;
     
     while(1) {
     
           if((P1 & 0x0F) != prevVal) {
                  Delay_ms(50);
           
               switch(P1 & 0x0F) {
 
                    case 0:
                         P2 = mask[0];
                         break;
                    case 1:
                         P2 = mask[1];
                         break;
                    case 2:
                         P2 = mask[2];
                         break;
                    case 3:
                         P2 = mask[3];
                         break;
                    case 4:
                         P2 = mask[4];
                         break;
                    case 5:
                         P2 = mask[5];
                         break;
                    case 6:
                         P2 = mask[6];
                         break;
                    case 7:
                         P2 = mask[7];
                         break;
                    case 8:
                         P2 = mask[8];
                         break;
                    case 9:
                         P2 = mask[9];
                         break;
                    case 10:
                         P2 = mask[10];
                         break;
                    case 11:
                         P2 = mask[11];
                         break;
                    case 12:
                         P2 = mask[12];
                         break;
                    case 13:
                         P2 = mask[13];
                         break;
                    case 14:
                         P2 = mask[14];
                         break;
                    case 15:
                         P2 = mask[15];
                         break;
               };
 
               prevVal = P1 & 0x0F;
           }
     }
}



broken link removed
 

Attachments

  • Display Hex Values.rar
    24.8 KB · Views: 95
  • hex displayer.png
    26.4 KB · Views: 99
Last edited by a moderator:
Milam.rajik
What software is used to produce these figures please.
 


Shouldn't it be the simple:

Code C - [expand]
1
2
P2 = mask[P1 & 0xf];
        prevVal = P1 & 0xf;



or even shorter:


Code C - [expand]
1
P2 = mask[prevVal = (P1 & 0xf)];

 

Yes, it can be simple xenos but I prefer using two digits for hexadecimal representation. It is a habit. I have used that code for debouncing the 4 inputs.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…