Building the Bar Graph Display
2 min
Lead in
The bar graph display takes the input from AD0 and converts the value to be displayed on 8-BITs of a bar graph display.
Code sample
Sample code for MikroC.
unsigned int16 adcRead;
char ledBar[9]={0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};
void SetUp(){
TRISA = 0x01;
TRISD = 0x00;
}
void main(void){
SetUp();
while(1){
adcRead=read_adc(0);
//Wait for completion
delay_ms(50);
adcRead=(adcRead*9)/256;
//Output the result to PORTD
output_D(ledBar[adcRead]);
delay_ms(50);
}
}
Lead Out
The code provided has been tested using a RADIX development board.