ive been trying to program a simple speedometer for a bike. as of right now the hardware end is all finished. got a hall effect sensor as the input, and a 2digit 7-segment display. using a pic16f690 microcontroller.
so far ive written a short bit of code to test the 7-segment display. what i need help with is making the 7-segment display use the input from the hall effect sensor, whichll be a frequency.
can anyone point me in the right direction (or help me) to make the 7-segment display not run through 0-99, but rather display the frequency coming off the hall effect sensor?
thanks
Code:unsigned int advalue = 0; //variable to store potentiometer input unsigned char digit, digit1, digit2; //used to store BCD values for display int x,y; main() { ANSEL = 0; // No analog inputs yet. CM1CON0 = 0; // Initialize Comparator 1 off CM2CON0 = 0; // Initialize Comparator 2 off PORTA = 0; //Clear PortA TRISA = 0xFF; //All PortA I/O inputs ANSEL = 0b00000000; //Analog input AN0 (potentiometer) ADCON0 = 0b00000001; //AtoD on, Left justified, Channel AN0/RA0 selected initially ADCON1 = 0b00111000; //Internal RC clock for A/D conversion PORTC = 0x0F; //Initialize PortC port TRISC = 0x00; //All PortC I/O outputs while(1==1) //loop forever { for(x=0;x<=99;x++) { ADCON0 = 0b00000001; //AtoD on, Left justified, Channel AN0/RA0 selected initially pause(1); GODONE = 1; //Start A/D process; need to account for overhead of ADC. while (GODONE ==1) //wait for A/D to finish (average time?) { } advalue = ADRESH; for(y=0;y<=advalue;y++) { digit1=0; digit2=0; digit = x; while(digit >= 10) { digit2++; digit=digit-10; } digit1=digit; digit = digit1<<4; digit = (digit|0b00000111)&0b11111110; PORTC = digit; pause(1); digit = digit2<<4; digit = (digit|0b00000111)&0b11111101; PORTC = digit; pause(10); } } continue; } //End while } //end main



LinkBack URL
About LinkBacks



