nirob121
Newbie level 1
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...
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: