Continue to Site

Welcome to EDAboard.com

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

[Moved] volt meter 7segment some coding problem

Status
Not open for further replies.

nirob121

Newbie level 1
Joined
Aug 9, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
25
this is volt meter with 7segment display...
I want when 2V show than LED on....

is not working, anyone help me this problem...


My code is hare...


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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
unsigned int adc_rd0,tlong;
unsigned short mask(int num)
{
 switch (num)
 {
   case 0 : return 0xC0;
   case 1 : return 0xF9;
   case 2 : return 0xA4;
   case 3 : return 0xB0;
   case 4 : return 0x99;
   case 5 : return 0x92;
   case 6 : return 0x82;
   case 7 : return 0xD8;
   case 8 : return 0x80;
   case 9 : return 0x90;
   case 10: return 0x40;
   case 11: return 0x79;
   case 12: return 0x24;
   case 13: return 0x30;
   case 14: return 0x19;
   case 15: return 0x12;
   case 16: return 0x02;
   case 17: return 0x78;
   case 18: return 0x00;
   case 19: return 0x10;
 }
}
 
unsigned short shifter, portb_index;
unsigned int digit, number;
unsigned short portb_array[4];
 
void interrupt()
{
  PORTC = 0;
  PORTB = portb_array[portb_index];
  PORTC = shifter;
 
 
  shifter <<= 1;
  if(shifter > 8u)
  shifter = 1;
 
 
  portb_index ++ ;
  if (portb_index > 3u)
  portb_index = 0;
  TMR0 = 0;
  INTCON = 0x20;
 }
 void display()
 {
   digit = number % 10u;
   portb_array[0] = mask(digit);
   digit = (number / 10u) % 10u;
   portb_array[1] = mask(digit);
   digit = (number / 100u) % 10u+10;
   portb_array[2] = mask(digit);
   digit = number / 1000u;
   portb_array[3] = mask(digit);
 }
 
void main()
{
  // port initialization...
  TRISB = 0x00; // Set PORTB direction to be output
  PORTB = 0xff;    // Turn OFF LEDs on PORTB
  TRISC= 0x00; // Set PORTB direction to be output
  PORTC = 0x00;
  TRISA = 0xFF; // all input
 
 digit = 0;
 portb_index = 0;
 shifter = 1;
 number = 0;                          //initial value;
 
 
 ADCON1 = 0x00;
 // tiemr0 settings...
 OPTION_REG = 0x80;                   // Set timer TMR0;
 TMR0 = 0;
 INTCON = 0xA0;                       // Disable interrupt PEIE,INTE,RBIE,T0IE
 
 
 
 while(1)
  {
    // Read Battery  voltage
    ADCON0 = 0b00000001;
    adc_rd0 = ADC_Read(0);        // A/D conversion. Pin RA2 is an input.
    tlong = (float)adc_rd0 *1.96078431372549; // Convert the result in millivolts
    number = tlong;
    display();
    
    
     if(number>2.00)
      {
        RC7_bit = 1;
        Delay_ms(500);
      }
      else
            {
        RC7_bit = 1;
        Delay_ms(500);
      }
    
    
    
    
  }//Endless loop;
}//End.

 
Last edited by a moderator:

Not sure of your schematic, are you trying to turn on an LED on PIN 7 of the C register ?
Does a 0 or a 1 turn the LED on ?
Do you have to do any conversion to "number'" to have it represent volts rather than millivolts before you test if it is greater than 2 on line 96?
The if statement starting at line 96 in your code, sets RC7_bit = 1 in both results of the test.
 
Last edited:

I think I would also consider an array to hold the data instead of a very long switch/case statement. It wuld depend upon the compiler used but it would probably produce far fewer instructions and run faster.

If my understanding of intended operation is correct, 'shifter' is to move the drive signal from one digit to the next in sequence (multiplexing the digits) so why not also use it to select the digit data to be displayed. I appears you are doing it twice with your 'index' variable when the values should be the same anyway.

Also, do you really want to set the value of INTCON while in your interrupt? I'm assuming you have the interrupt configured elsewhere. Normally you clear the interrupt flag and leave other bits alone.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top